21.2. Extending CreditThe credit tests from Section 3.3 on p. 16 are shown again in Figure 21.3. Our fixture class is CalculateCredit, a ColumnFixture, as shown in Listing 21.2.
There are three given columns, so the class has three corresponding instance variables, which are declared on lines 2-4 in Listing 21.2. The two calculated columns, allow credit() and credit limit(), correspond to the two methods allowCredit() and creditLimit() on lines 7 and 10 in Listing 21.2. The simple translation here is defined by camel casing; see the Note below. The two methods each make use of the values in the instance variables to call methods in the system under test, of class Credit. Listing 21.2. CalculateCredit.java1 public class CalculateCredit extends fit.ColumnFixture { 2 public int months; 3 public boolean reliable; 4 public double balance; 5 private Credit credit = new Credit(); 6 7 public boolean allowCredit() { 8 return credit.allowsCredit(months,reliable,balance); 9 } 10 public double creditLimit() { 11 return credit.limit(months,reliable,balance); 12 } 13 } Note Camel casing handles spaces separating words in a ColumnFixture or RowFixture table label, as well as in the names of fields in enter, press, and check actions in ActionFixture tables. These spaces have to be removed to get a valid Java identifier. A sequence of space-separated words in the header is translated so that spaces are removed and the first letter of all words but the first is capitalized. For example, "allow credit" is translated into "allowCredit." An extended form, extended camel casing, handles arbitrary characters in labels and actions in FitLibrary fixture tables, as discussed in Chapter 28. The operation is much the same as in the previous example, except that
Questions & Answers
|