1 | package negotiator.session;
|
---|
2 |
|
---|
3 | import static org.junit.Assert.assertEquals;
|
---|
4 | import static org.junit.Assert.assertNull;
|
---|
5 | import static org.junit.Assert.assertTrue;
|
---|
6 | import static org.mockito.Mockito.mock;
|
---|
7 | import static org.mockito.Mockito.when;
|
---|
8 |
|
---|
9 | import org.junit.Before;
|
---|
10 | import org.junit.Test;
|
---|
11 |
|
---|
12 | import genius.core.actions.Action;
|
---|
13 | import genius.core.session.Round;
|
---|
14 | import genius.core.session.Turn;
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * Junit test for {@link Round}
|
---|
18 | *
|
---|
19 | * @author W.Pasman
|
---|
20 | *
|
---|
21 | */
|
---|
22 | public class RoundTest {
|
---|
23 | private Round round;
|
---|
24 |
|
---|
25 | @Before
|
---|
26 | public void before() {
|
---|
27 | round = new Round();
|
---|
28 | }
|
---|
29 |
|
---|
30 | @Test
|
---|
31 | public void testConstructor() {
|
---|
32 | assertTrue("new round contains turns", round.getTurns().isEmpty());
|
---|
33 | assertTrue("new round contains actions", round.getActions().isEmpty());
|
---|
34 | }
|
---|
35 |
|
---|
36 | @Test
|
---|
37 | public void testMostRecentActionWhenEmpty() {
|
---|
38 | assertNull(round.getMostRecentAction());
|
---|
39 | }
|
---|
40 |
|
---|
41 | @Test
|
---|
42 | public void testAddTurn() {
|
---|
43 | Turn turn = mock(Turn.class);
|
---|
44 | Action action1 = mock(Action.class);
|
---|
45 | when(turn.getAction()).thenReturn(action1);
|
---|
46 | round.addTurn(turn);
|
---|
47 | assertEquals(1, round.getTurns().size());
|
---|
48 | assertEquals(1, round.getActions().size());
|
---|
49 | assertEquals(action1, round.getActions().get(0));
|
---|
50 | }
|
---|
51 |
|
---|
52 | @Test
|
---|
53 | public void testgetAction() {
|
---|
54 | Turn turn = mock(Turn.class);
|
---|
55 | Action action1 = mock(Action.class);
|
---|
56 | when(turn.getAction()).thenReturn(action1);
|
---|
57 | round.addTurn(turn);
|
---|
58 | assertEquals(1, round.getTurns().size());
|
---|
59 | assertEquals(1, round.getActions().size());
|
---|
60 | assertEquals(action1, round.getActions().get(0));
|
---|
61 | }
|
---|
62 |
|
---|
63 | @Test
|
---|
64 | public void testIterateOverRoundsWhileUpdating() {
|
---|
65 | Turn turn = mock(Turn.class);
|
---|
66 | Action action1 = mock(Action.class);
|
---|
67 | when(turn.getAction()).thenReturn(action1);
|
---|
68 | round.addTurn(turn);
|
---|
69 |
|
---|
70 | for (Turn t : round.getTurns()) {
|
---|
71 | round.addTurn(mock(Turn.class));
|
---|
72 | }
|
---|
73 |
|
---|
74 | }
|
---|
75 |
|
---|
76 | @Test
|
---|
77 | public void testgetActionWithNull() {
|
---|
78 | Turn turn = mock(Turn.class);
|
---|
79 | when(turn.getAction()).thenReturn(null);
|
---|
80 | round.addTurn(turn);
|
---|
81 | assertEquals(1, round.getTurns().size());
|
---|
82 | assertEquals(0, round.getActions().size());
|
---|
83 | }
|
---|
84 |
|
---|
85 | @Test
|
---|
86 | public void testGetLastAction() {
|
---|
87 | Turn turn = mock(Turn.class);
|
---|
88 | Action action1 = mock(Action.class);
|
---|
89 | when(turn.getAction()).thenReturn(action1);
|
---|
90 | round.addTurn(turn);
|
---|
91 | Action lastAction = round.getMostRecentAction();
|
---|
92 | assertEquals(action1, lastAction);
|
---|
93 | }
|
---|
94 |
|
---|
95 | }
|
---|