source: src/test/java/negotiator/protocol/MultiLateralProtocolAdapterTest.java

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

Initial import : Genius 9.0.0

File size: 2.8 KB
Line 
1package negotiator.protocol;
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;
7
8import java.util.ArrayList;
9import java.util.Collection;
10import java.util.List;
11
12import org.junit.Before;
13import org.junit.Test;
14import org.mockito.Mockito;
15
16import genius.core.parties.NegotiationParty;
17import genius.core.protocol.DefaultMultilateralProtocol;
18import genius.core.session.Session;
19
20public class MultiLateralProtocolAdapterTest {
21
22 private DefaultMultilateralProtocol protocol;
23
24 Session session = mock(Session.class);
25
26 @Before
27 public void init() {
28
29 protocol = mock(DefaultMultilateralProtocol.class,
30 Mockito.CALLS_REAL_METHODS);
31 }
32
33 @Test
34 public void testEndNego() {
35 protocol.endNegotiation();
36 assertTrue(protocol.isFinished(session, null));
37 }
38
39 @Test
40 public void testFilterEmptyList() {
41 List<NegotiationParty> negotiationParties = new ArrayList<NegotiationParty>();
42 Collection<NegotiationParty> filtered = protocol.includeOnly(
43 negotiationParties, NegotiationParty.class);
44 assertTrue("filter result not empty", filtered.isEmpty());
45 }
46
47 @Test
48 public void testFilterOneParty() {
49 List<NegotiationParty> negotiationParties = new ArrayList<NegotiationParty>();
50 NegotiationParty oneParty = mock(NegotiationParty.class);
51 negotiationParties.add(oneParty);
52
53 Collection<NegotiationParty> filtered = protocol.includeOnly(
54 negotiationParties, oneParty.getClass());
55 assertFalse("filter result is empty", filtered.isEmpty());
56 }
57
58 /**
59 * Filter two parties, only first one should remain.
60 */
61 @Test
62 public void testFilterTwoParties() {
63 List<NegotiationParty> negotiationParties = new ArrayList<NegotiationParty>();
64 NegotiationParty party1 = mock(NegoParty1.class);
65 NegotiationParty party2 = mock(NegoParty2.class);
66
67 negotiationParties.add(party1);
68 negotiationParties.add(party2);
69
70 Collection<NegotiationParty> filtered = protocol.includeOnly(
71 negotiationParties, party1.getClass());
72 assertEquals(1, filtered.size());
73 assertEquals(party1, filtered.iterator().next());
74 }
75
76 /**
77 * Filter two parties, only first one should remain.
78 */
79 @Test
80 public void testFilterTwoPartiesExclude() {
81 List<NegotiationParty> negotiationParties = new ArrayList<NegotiationParty>();
82 NegotiationParty party1 = mock(NegoParty1.class);
83 NegotiationParty party2 = mock(NegoParty2.class);
84
85 negotiationParties.add(party1);
86 negotiationParties.add(party2);
87
88 Collection<NegotiationParty> filtered = protocol.exclude(
89 negotiationParties, party1.getClass());
90 assertEquals(1, filtered.size());
91 assertEquals(party2, filtered.iterator().next());
92 }
93
94 interface NegoParty1 extends NegotiationParty {
95 }
96
97 interface NegoParty2 extends NegotiationParty {
98
99 }
100
101}
Note: See TracBrowser for help on using the repository browser.