source: src/test/java/negotiator/session/SessionTest.java@ 50

Last change on this file since 50 was 1, checked in by Wouter Pasman, 6 years ago

Initial import : Genius 9.0.0

File size: 2.8 KB
RevLine 
[1]1package negotiator.session;
2
3import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertFalse;
5import static org.junit.Assert.assertNull;
6import static org.junit.Assert.assertTrue;
7import static org.mockito.Mockito.mock;
8import static org.mockito.Mockito.when;
9
10import org.junit.Before;
11import org.junit.Test;
12
13import genius.core.Deadline;
14import genius.core.DeadlineType;
15import genius.core.session.Round;
16import genius.core.session.Session;
17
18/**
19 * Tests the {@link Session} object. FIXME we currently ignore time related
20 * calls as that part of the code needs to be cleaned up first.
21 *
22 * @author W.Pasman
23 *
24 */
25public class SessionTest {
26 private Session session;
27 private Deadline deadline = mock(Deadline.class);
28
29 @Before
30 public void before() {
31 when(deadline.getType()).thenReturn(DeadlineType.ROUND);
32 session = new Session(deadline, null);
33 }
34
35 @Test
36 public void testGetDeadline() {
37 assertEquals(deadline, session.getDeadlines());
38 }
39
40 @Test
41 public void testGetLastRoundInitially() {
42 assertNull(session.getMostRecentRound());
43 }
44
45 @Test
46 public void testGetRoundNumberInitially() {
47 assertEquals(0, session.getRoundNumber());
48 }
49
50 @Test
51 public void testIsFirstRoundInitially() {
52 assertFalse(session.isFirstRound());
53 }
54
55 @Test
56 public void testGetRoundsInitially() {
57 assertTrue(session.getRounds().isEmpty());
58 }
59
60 @Test
61 public void testGetTurnNumberInitially() {
62 assertEquals(0, session.getTurnNumber());
63 }
64
65 @Test
66 public void testMostRecentActionInitially() {
67 assertNull(session.getMostRecentAction());
68 }
69
70 @Test
71 public void testIsDeadlineReachedInitially() {
72 when(deadline.getValue()).thenReturn(10);
73 assertFalse(session.isDeadlineReached());
74 }
75
76 @Test
77 public void testGetRuntimeNanoInitially() {
78 assertEquals(0, session.getRuntimeInNanoSeconds());
79 }
80
81 @Test
82 public void testGetRuntimeInitially() {
83 assertEquals(0, session.getRuntimeInSeconds(), 0.000000001);
84 }
85
86 @Test
87 public void testGetLastRoundAfter1Round() {
88 Round firstRound = mock(Round.class);
89 session.startNewRound(firstRound);
90 assertEquals(firstRound, session.getMostRecentRound());
91 }
92
93 @Test
94 public void testIsDeadlineReachedAfter1Round() {
95 Round firstRound = mock(Round.class);
96 session.startNewRound(firstRound);
97 when(deadline.getValue()).thenReturn(0);
98 assertTrue(session.isDeadlineReached());
99 }
100
101 @Test
102 public void testIsDeadlineReachedAfter1RoundB() {
103 Round firstRound = mock(Round.class);
104 session.startNewRound(firstRound);
105 when(deadline.getValue()).thenReturn(10);
106 assertFalse(session.isDeadlineReached());
107 }
108
109 @Test(expected = UnsupportedOperationException.class)
110 public void testIsGetRoundNonmodifyable() {
111 Round firstRound = mock(Round.class);
112 session.startNewRound(firstRound);
113 // this SHOULD throw unsipportedoperation
114 session.getRounds().add(mock(Round.class));
115 }
116
117}
Note: See TracBrowser for help on using the repository browser.