source: src/test/java/negotiator/parties/EnterBidDialog2Test.java@ 127

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

Initial import : Genius 9.0.0

File size: 5.0 KB
Line 
1package negotiator.parties;
2
3import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertTrue;
5import static org.mockito.Mockito.mock;
6import static org.mockito.Mockito.when;
7
8import javax.swing.JFrame;
9
10import org.junit.Before;
11import org.junit.Test;
12
13import genius.core.AgentID;
14import genius.core.Bid;
15import genius.core.Domain;
16import genius.core.actions.Accept;
17import genius.core.actions.Action;
18import genius.core.actions.EndNegotiation;
19import genius.core.actions.Offer;
20import genius.core.parties.NegotiationParty;
21import genius.core.utility.AdditiveUtilitySpace;
22
23public class EnterBidDialog2Test {
24
25 private static final AgentID AGENTID = new AgentID("test");
26 private NegotiationParty party;
27 private JFrame frame;
28 private AdditiveUtilitySpace utilspace;
29 private Bid lastOppBid;
30
31 @Before
32 public void before() {
33 party = mock(NegotiationParty.class);
34 frame = new JFrame();// mock(Frame.class);
35 utilspace = mock(AdditiveUtilitySpace.class);
36 Domain domain = mock(Domain.class);
37 when(utilspace.getDomain()).thenReturn(domain);
38 lastOppBid = mock(Bid.class);
39
40 }
41
42 @Test
43 public void testInit() throws Exception {
44 // smoke test.
45 new EnterBidDialog2(party, AGENTID, frame, true, utilspace, lastOppBid);
46 }
47
48 @Test
49 public void testEndNego() throws Exception {
50
51 // use non-modal dialog so that we can interact here with it
52 EnterBidDialog2 dialog = new EnterBidDialog2(party, AGENTID, frame, true, utilspace, lastOppBid);
53 final ControllableComponent control = new ControllableComponent(dialog);
54
55 Action opponentAction = new Offer(AGENTID, new Bid(mock(Domain.class)));
56 Bid myPreviousBid = new Bid(mock(Domain.class));
57
58 control.delayedClickOnButton(EnterBidDialog2.END_NEGOTIATION);
59 Action action = dialog.askUserForAction(opponentAction, myPreviousBid);
60 assertTrue("end nego click did not result in EndNegotiation", action instanceof EndNegotiation);
61 }
62
63 @Test
64 public void testEndNegoNullOpponentAction() throws Exception {
65
66 // use non-modal dialog so that we can interact here with it
67 EnterBidDialog2 dialog = new EnterBidDialog2(party, AGENTID, frame, true, utilspace, lastOppBid);
68 final ControllableComponent control = new ControllableComponent(dialog);
69
70 Bid myPreviousBid = new Bid(mock(Domain.class));
71
72 control.delayedClickOnButton(EnterBidDialog2.END_NEGOTIATION);
73 Action action = dialog.askUserForAction(null, myPreviousBid);
74 assertTrue("end nego click did not result in EndNegotiation", action instanceof EndNegotiation);
75 }
76
77 @Test
78 public void testEndNegoWithEndNegoOpponentAction() throws Exception {
79
80 // use non-modal dialog so that we can interact here with it
81 EnterBidDialog2 dialog = new EnterBidDialog2(party, AGENTID, frame, true, utilspace, lastOppBid);
82 final ControllableComponent control = new ControllableComponent(dialog);
83
84 Action opponentAction = new EndNegotiation(AGENTID);
85 Bid myPreviousBid = new Bid(mock(Domain.class));
86
87 control.delayedClickOnButton(EnterBidDialog2.END_NEGOTIATION);
88 Action action = dialog.askUserForAction(opponentAction, myPreviousBid);
89 assertTrue("end nego click did not result in EndNegotiation", action instanceof EndNegotiation);
90 }
91
92 @Test
93 public void testEndNegoWithAcceptOpponentAction() throws Exception {
94
95 // use non-modal dialog so that we can interact here with it
96 EnterBidDialog2 dialog = new EnterBidDialog2(party, AGENTID, frame, true, utilspace, lastOppBid);
97 final ControllableComponent control = new ControllableComponent(dialog);
98
99 Action opponentAction = new Accept(AGENTID, lastOppBid);
100 Bid myPreviousBid = new Bid(mock(Domain.class));
101
102 control.delayedClickOnButton(EnterBidDialog2.END_NEGOTIATION);
103 Action action = dialog.askUserForAction(opponentAction, myPreviousBid);
104 assertTrue("end nego click did not result in EndNegotiation", action instanceof EndNegotiation);
105 }
106
107 @Test
108 public void testAccept() throws Exception {
109
110 // use non-modal dialog so that we can interact here with it
111 EnterBidDialog2 dialog = new EnterBidDialog2(party, AGENTID, frame, true, utilspace, lastOppBid);
112 final ControllableComponent control = new ControllableComponent(dialog);
113
114 Action opponentAction = mock(Action.class);
115 Bid myPreviousBid = new Bid(mock(Domain.class));
116
117 control.delayedClickOnButton(EnterBidDialog2.ACCEPT);
118 Action action = dialog.askUserForAction(opponentAction, myPreviousBid);
119 assertTrue("end nego click did not result in accept", action instanceof Accept);
120 }
121
122 @Test
123 public void testDoBid() throws Exception {
124
125 // use non-modal dialog so that we can interact here with it
126 EnterBidDialog2 dialog = new EnterBidDialog2(party, AGENTID, frame, true, utilspace, lastOppBid);
127 final ControllableComponent control = new ControllableComponent(dialog);
128
129 Action opponentAction = mock(Action.class);
130 Bid myPreviousBid = new Bid(mock(Domain.class));
131
132 control.delayedClickOnButton(EnterBidDialog2.DO_BID);
133 Action action = dialog.askUserForAction(opponentAction, myPreviousBid);
134 assertTrue("end nego click did not result in offer", action instanceof Offer);
135 assertEquals("the placed bid is not equal to the previous bid", myPreviousBid, ((Offer) action).getBid());
136 }
137}
Note: See TracBrowser for help on using the repository browser.