Section 28.2. DoFixtures as Adapters


28.2. DoFixtures as Adapters

Note that many of the methods in ChatStart in Listing 28.1 simply call a method of the same name and with the same arguments in the system under test. With DoFixture, such adapter methods can be removed.

In the revised class ChatStart, as shown in Listing 28.4, we have eliminated many of the methods.[2] The constructor calls the superclass method setSystemUnderTest(), passing a reference to the system under test. When the picture has no method that corresponds to an action in a table, the fixture calls the corresponding method in the specified system under test directly.

[2] The changed method usersInRoom() is discussed in the next section.

For example, the action in the second table of Figure 28.1 is mapped to the method connectUser(). As this method is not defined in the ChatStart flow fixture object, the method connectUser() in the system under test is called instead. On the other hand the fixture method occupantCount() for the action in the last table is still needed, as it calls a method of a different name in the system under test.

Listing 28.4. ChatStart.java (version 2)
 public class ChatStart extends DoFixture {    private ChatRoom chat = new ChatRoom();    public ChatStart() {       setSystemUnderTest(chat);    }    public int occupantCount(String roomName) {       return chat.occupants(roomName);    }    public SetFixture usersInRoom(String roomName) {       return new SetFixture(chat.usersInRoom(roomName));    } } 



    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