source: protocol/src/test/java/geniusweb/protocol/session/ConnectionWithPartiesTest.java@ 43

Last change on this file since 43 was 43, checked in by bart, 3 years ago

Added python timedependent parties (conceder, hardliner, etc)

File size: 3.4 KB
Line 
1package geniusweb.protocol.session;
2
3import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertFalse;
5import static org.junit.Assert.assertTrue;
6import static org.mockito.Mockito.mock;
7import static org.mockito.Mockito.when;
8
9import java.util.Arrays;
10import java.util.List;
11
12import org.junit.Before;
13import org.junit.Test;
14
15import geniusweb.actions.PartyId;
16import geniusweb.protocol.partyconnection.ProtocolToPartyConnections;
17import geniusweb.protocol.partyconnection.ProtocolToPartyConn;
18import tudelft.utilities.junit.GeneralTests;
19
20public class ConnectionWithPartiesTest
21 extends GeneralTests<ProtocolToPartyConnections> {
22 PartyId party1 = new PartyId("party1");
23 PartyId party2 = new PartyId("party2");
24 PartyId party3 = new PartyId("party3");
25
26 private ProtocolToPartyConn con1 = mock(ProtocolToPartyConn.class);
27 private ProtocolToPartyConn con2 = mock(ProtocolToPartyConn.class);
28 private ProtocolToPartyConn con3 = mock(ProtocolToPartyConn.class);
29
30 private ProtocolToPartyConnections conns1 = new ProtocolToPartyConnections(
31 Arrays.asList(con1, con2));
32 private ProtocolToPartyConnections conns1a = new ProtocolToPartyConnections(
33 Arrays.asList(con1, con2));
34 private ProtocolToPartyConnections conns2 = new ProtocolToPartyConnections(
35 Arrays.asList(con1, con3));
36 private ProtocolToPartyConnections conns3 = new ProtocolToPartyConnections(
37 Arrays.asList(con2, con1));
38 private ProtocolToPartyConnections conns4 = new ProtocolToPartyConnections(
39 Arrays.asList(con2, con1, con3));
40 private ProtocolToPartyConnections conns5 = new ProtocolToPartyConnections(
41 Arrays.asList(con2, con1, con3, con1));
42
43 @Before
44 public void before() {
45 when(con1.toString()).thenReturn("con1");
46 when(con2.toString()).thenReturn("con2");
47 when(con3.toString()).thenReturn("con3");
48
49 when(con1.getParty()).thenReturn(party1);
50 when(con2.getParty()).thenReturn(party2);
51 when(con3.getParty()).thenReturn(party3);
52
53 }
54
55 @Override
56 public List<List<ProtocolToPartyConnections>> getGeneralTestData() {
57 return Arrays.asList(Arrays.asList(conns1, conns1a),
58 Arrays.asList(conns2), Arrays.asList(conns3),
59 Arrays.asList(conns4));
60 }
61
62 @Override
63 public List<String> getGeneralTestStrings() {
64 return Arrays.asList("ConnectionWithParties\\[con1, con2\\]",
65 "ConnectionWithParties\\[con1, con3\\]",
66 "ConnectionWithParties\\[con2, con1\\]",
67 "ConnectionWithParties\\[con2, con1, con3\\]");
68 }
69
70 @Test
71 public void getTest() {
72 assertEquals(con1, conns1.get(0));
73 assertEquals(con3, conns4.get(2));
74 }
75
76 @Test
77 public void getPartyTest() {
78 assertEquals(con1, conns1.get(party1));
79 assertEquals(con1, conns4.get(party1));
80 assertEquals(con2, conns1.get(party2));
81 assertEquals(con2, conns3.get(party2));
82 assertEquals(con2, conns4.get(party2));
83 }
84
85 @Test
86 public void getUnknownPartyTest() {
87 assertEquals(null, conns2.get(party2));
88 }
89
90 @Test
91 public void sizeTest() {
92 assertEquals(2, conns1.size());
93 assertEquals(2, conns2.size());
94 assertEquals(2, conns3.size());
95 assertEquals(3, conns4.size());
96 }
97
98 @Test
99 public void withPartyTest() {
100 ProtocolToPartyConnections conns = conns3.with(con3);
101 assertEquals(2, conns3.size());
102 assertEquals(3, conns.size());
103 assertEquals(conns4, conns);
104 }
105
106 @Test
107 public void withExistingPartyTest() {
108 conns4.with(con1);
109 // no throw, default this is ok, it should be the protocol testing this.
110 }
111
112 @Test
113 public void allUniqueTest() {
114 assertTrue(conns4.allunique());
115 assertFalse(conns5.allunique());
116 }
117
118}
Note: See TracBrowser for help on using the repository browser.