Saturday, November 21, 2009

Section 32.3.  The Fixtures









32.3. The Fixtures


The fixture DoRentEze that Emily wrote for Figure 32.1 is shown in Listing 32.1. This fixture runs the GUI by constructing an AdminFrame, which is the Java Swing JFrame for the simple mockup. This GUI is passed to a RentEzeUiAdapter; this adapter [GHJV95] is responsible for carrying out the operations on the GUI.


DoRentEze defines two methods, corresponding to the actions in the first rows of the second and third tables in Figure 32.1. The setUp() method returns a SetUpFixture fixture object[2] to set up the rental item data. The rentalItems() method returns a SetFixture with the actual collection of rental items from the system under test.

[2] See Section 28.3 on p. 232 for an introduction to writing SetUpFixture classes.



Listing 32.1. DoRentEze.java



public class DoRentEze extends DoFixture {
private RentEzeUiAdapter adapter =
new RentEzeUiAdapter(new AdminFrame());

public Fixture setUp() {
return new RentalItemSetUp();
}
public Fixture rentalItems() throws Throwable {
return new SetFixture(adapter.getRentalItems());
}
public class RentalItemSetUp extends SetUpFixture {
public void rentalItemCountDollarSlashHour(String name,
int count, double hourlyRate) throws Throwable {
adapter.addRentalItem(name,count,hourlyRate);
}
}
}











    No comments: