Section 28.8. CalculateFixture Tables


28.8. CalculateFixture Tables

The third table in Figure 28.6 makes use of a CalculateFixture table, CalculateDiscounts2, which is returned by the method calculateWithFutureValue() in Listing 28.8. The fixture class CalculateDiscounts2 is shown in Listing 28.10. In a similar way to SetUpFixture, the labels in the second row of the table are combined to form a method name. Here, the method name discountOwingPurchase() is made up from the expected column label, followed by the given column labels.

For each of the following rows of the table, the method is called with two arguments from the two given columns. The result of the method call is checked against the calculated column for that row, and that cell is colored appropriately.

Listing 28.10. CalculateDiscounts2.java
 public class CalculateDiscounts2 extends CalculateFixture {    private DiscountApplication app;    private String futureValue;    public CalculateDiscounts2(DiscountApplication app, String futureValue) {       this.app = app;       this.futureValue = futureValue;    }    public double discountOwingPurchase(double owing, double purchase) {       return app.discount(futureValue,owing,purchase);    } } 

In general:

  • There may be several calculated columns. Each calculated column has a separate method made up of the calculated column label, followed by all the given column labels. For each row, the calculated columns are processed from left to right, calling the appropriate method.

  • CalculateFixture may take a reference to an application object, just like with DoFixture. If the fixture doesn't declare a required method, the method in that object will be called instead.

  • A CalculateFixture object may define a specific String for use in a given cell to mean to repeat the previous value in the column in the table. This is defined by calling the method setRepeatString() of the object, which takes the repeat String as an argument.

    By default, there is no repeat string. Compare this to ColumnFixture, in which an empty cell is used to repeat column values.

  • A CalculateFixture object may also define a specific String for use in a result cell of the table where an exception is expected instead of a result value. This is defined by calling the method setExceptionString() of the object, which takes the repeat String as an argument.

    By default, there is no exception string. Compare this to ColumnFixture, in which a result cell value of error is used to signify that an exception is expected.



    Fit for Developing Software. Framework for Integrated Tests
    Fit for Developing Software: Framework for Integrated Tests
    ISBN: 0321269349
    EAN: 2147483647
    Year: 2005
    Pages: 331

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net