Section 23.3. Testing a List with Parameters


23.3. Testing a List with Parameters

Let's now return to the example from Section 5.1 on p. 31 of testing the occupants of a specific chat room, as shown again in Figure 23.5. This is a RowFixture table, with the parameter lotr provided in the first row.

Figure 23.5. Table for Testing the Occupants of a Selected Room

OccupantListInRoom

lotr

user

anna

luke


The fixture code for this is shown in Listing 23.5. The parameters provided in the first row of any table, after the fixture name, are accessed in the fixture code through the instance variable args, which is a String[]. The crucial difference from the code shown in Listing 23.1 is that here, the query() method uses args[0] to select a single room by name. Note that we use the Occupancy, from Listing 23.2, again in Listing 23.5, even though the room is irrelevant here.

Listing 23.5. OccupantListInRoom.java
 public class OccupantListInRoom extends fit.RowFixture {    private ChatServer chat = new ChatServer();    public Object[] query() throws Exception {       List occupancies = new ArrayList();       collectOccupants(occupancies,chat.room(args[0]));       return occupancies.toArray();    }    public Class getTargetClass() {       return Occupancy.class;    }    private void collectOccupants(List occupancies, Room room) {       for (Iterator it = room.users(); it.hasNext(); ) {          User user = (User)it.next();          Occupancy occupant = new Occupancy(room.getName(),                                          user.getName());          occupancies.add(occupant);       }    } } 



    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