dimanche 22 mai 2016

Java test adding values from an Enum to an arrayList

The arrayList politicCard of the class Player contains values from the enum Color, to test it i added three different values but it returns an error, isn't player.getPoliticCards().get(0) supposed to return the color value in position 0 that i added before?

public enum Color {
    BLUE, BLACK, JOKER
}
public class Player {
    private int id;
    private ArrayList<Color> politicCards;
    public Player(int id){
        this.setId(id);
    }
    public ArrayList<Color> getPoliticCards() {
        return politicCards;
    }
    public void setPoliticCards(ArrayList<Color> politicCards) {
        this.politicCards = politicCards;
    }   

}
public class PlayerTest {
    @Test
    public void PoliticCardsTest(){
        Player player = new Player(1);
        player.getPoliticCards().add(Color.BLACK);
        player.getPoliticCards().add(Color.BLUE);
        player.getPoliticCards().add(Color.JOKER);
        assertEquals(Color.BLACK,player.getPoliticCards().get(0));
    }

}

Aucun commentaire:

Enregistrer un commentaire