Martin's Videostore

This example is picked from Martin Fowler's "Refactoring" book, chapter 1, "Refactoring, a First Example".

Pricing Models

The charge for renting a movie depends on both the type of movie and how long the movie is rented. Customers can also earn frequent renter points, depending on whether the film is a new release.

videostore.Pricing
movieCategory daysRented charge() frequentRenterPoints()
videostore.RegularPrice 1 2.00 1
videostore.RegularPrice 2 2.00 1
videostore.RegularPrice 3 3.50 1
videostore.RegularPrice 4 5.00 1
videostore.RegularPrice 5 6.50 1
videostore.NewReleasePrice 1 3.00 1
videostore.NewReleasePrice 2 6.00 2
videostore.NewReleasePrice 3 9.00 2
videostore.ChildrensMoviePrice 1 1.50 1
videostore.ChildrensMoviePrice 2 1.50 1
videostore.ChildrensMoviePrice 3 1.50 1
videostore.ChildrensMoviePrice 4 3.00 1
videostore.ChildrensMoviePrice 5 4.50 1
videostore.ChildrensMoviePrice 6 6.00 1

Customer Statement

Here, we're testing a function which obviously was not designed to be tested in small grains. One drawback is that we have to inject some state into the system, before we get interested in any test results. The intermediary steps could be tested as well, but our customers are only interested in the correct statement. The dontCarecolumn is really only a flag to make that distinction explicit.

Note: I'm not sure whether I'd expect to unformat the String value here (being the reason why the test fails).

fit.ActionFixture
start videostore.CustomerStatement
enter rental The Jungle Book,videostore.ChildrensMoviePrice,2
enter rental Brazil,videostore.RegularPrice,4
enter rental Crouching Tiger Hidden Dragon,videostore.NewReleasePrice,1
check statement Rental Record for Quentin Tarantino\n\tThe Jungle Book\t1.5\n\tBrazil\t5.0\n\tCrouching Tiger Hidden Dragon\t3.0\nAmount owed is 9.5\nYou earned 3.0 frequent renter points expected
Rental Record for Quentin Tarantino The Jungle Book 1.5 Brazil 5.0 Crouching Tiger Hidden Dragon 3.0 Amount owed is 9.5 You earned 3.0 frequent renter points actual

Lack of Precision

Here is an interesting case: The check of frequentRenterPoints() claims to be both 1 and 2, but only if defined of type integer.

videostore.Pricing
movieCategory daysRented charge() frequentRenterPoints()
videostore.ChildrensMoviePrice 2 1.50 2
videostore.ChildrensMoviePrice 2 1.50 1
videostore.ChildrensMoviePrice 2 1.50 2.0 expected
1.0 actual
videostore.ChildrensMoviePrice 2 1.50 1.0