[1] | 1 | package negotiator.protocol;
|
---|
| 2 |
|
---|
| 3 | import static org.junit.Assert.assertEquals;
|
---|
| 4 | import static org.junit.Assert.assertFalse;
|
---|
| 5 | import static org.junit.Assert.assertTrue;
|
---|
| 6 | import static org.mockito.Mockito.mock;
|
---|
| 7 |
|
---|
| 8 | import java.util.ArrayList;
|
---|
| 9 | import java.util.Collection;
|
---|
| 10 | import java.util.List;
|
---|
| 11 |
|
---|
| 12 | import org.junit.Before;
|
---|
| 13 | import org.junit.Test;
|
---|
| 14 | import org.mockito.Mockito;
|
---|
| 15 |
|
---|
| 16 | import genius.core.parties.NegotiationParty;
|
---|
| 17 | import genius.core.protocol.DefaultMultilateralProtocol;
|
---|
| 18 | import genius.core.session.Session;
|
---|
| 19 |
|
---|
| 20 | public 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 | }
|
---|