35.1. Testing DirectlyAs we saw in Chapter 31, one approach to implementing fixtures for calculation tests is to call a specific method within the application that does only that calculation for a business rule. For example, consider the fair charge table from Chapter 16 shown again in Figure 35.1. Figure 35.1. Testing a Part of the Application  The DoFixture class CalculateFairCharge that Neo and Emily developed is shown in Listing 35.1.[1] 
 This method simply returns a CalculateFixture object of class FairCharge, as shown in Listing 35.2. Class FairCharge uses a Duration, which encodes the hours, days, and weeks of a rental. Duration values in this and the following Fit tables are handled automatically by the FitLibrary fixtures because a static parse() method exists in class Duration. This method translates a String into a Duration. Listing 35.1. CalculateFairCharge.java public class CalculateFairCharge extends DoFixture {    public Fixture ratesDollarPerHourPerDayPerWeek(Money perHour,           Money perDay, Money perWeek) {       return new FairCharge(new Rates(perHour,perDay,perWeek));    } } Listing 35.2. FairCharge.java public class FairCharge extends CalculateFixture {    private Rates rates;    public FairCharge(Rates rates) {       this.rates = rates;    }    public Duration fairDuration(Duration duration) {       return rates.fairDuration(duration);    } } The Rates object encodes the business rule. This object is used in FairCharge to calculate the fair duration, based on the actual charge rates.  |