When I use the method "execute(p)" there is a list when I must chose an item :
@Override
public void execute(Player p) {
// listchoser with items available
ListChoser lc = new ListChoser();
Object itemChosen;
itemChosen = lc.chose("Which item?", p.getCurrentRoom().getItems());
System.out.println("You chose " + itemChosen.toString());
// put item effect on player
((Item) itemChosen).effect(p);
// remove item from current room
p.getCurrentRoom().removeItem(itemChosen);
}
I must do some Unit Tests on it so here how I proceed :
Player c;
Action useAction;
@Before
public void initiliaze() {
c = new Player("Test", 100, 100,100);
c.setCurrentRoom(new Room("Debug Room", false));
useAction = new UseAction();
}
@Test
public void testUseAction(){
List<? super Item> l = c.getCurrentRoom().getItems();
int nbItems = l.size();
useAction.execute(c);
assertEquals(nbItems-1, c.getCurrentRoom().getItems().size());
}
I have some trouble to deal with such tests when I launch them : I'm asked for an input when I should only use a default one (like the 0 one)