source: src/test/java/negotiator/parties/NegoInfoTest.java@ 37

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

Initial import : Genius 9.0.0

File size: 2.6 KB
Line 
1package negotiator.parties;
2
3import static org.junit.Assert.assertNotNull;
4import static org.mockito.Matchers.anyInt;
5import static org.mockito.Mockito.mock;
6import static org.mockito.Mockito.when;
7
8import java.util.ArrayList;
9import java.util.List;
10
11import javax.swing.table.AbstractTableModel;
12
13import org.junit.Before;
14import org.junit.Test;
15
16import genius.core.Bid;
17import genius.core.Domain;
18import genius.core.issue.Issue;
19import genius.core.issue.IssueDiscrete;
20import genius.core.issue.Objective;
21import genius.core.issue.ValueDiscrete;
22import genius.core.utility.AdditiveUtilitySpace;
23import genius.core.utility.EvaluatorDiscrete;
24
25public class NegoInfoTest {
26
27 private AdditiveUtilitySpace utilspace;
28 private Domain domain;
29 private List<Issue> issues = new ArrayList<Issue>();
30
31 @Before
32 public void before() {
33 // the absolute minimum mocks
34 utilspace = mock(AdditiveUtilitySpace.class);
35 domain = mock(Domain.class);
36 when(utilspace.getDomain()).thenReturn(domain);
37 }
38
39 @Test
40 public void testConstructorNoIssues() throws Exception {
41 // smoke test with minimal config.
42 NegoInfo model = new NegoInfo(new Bid(domain), new Bid(domain),
43 utilspace);
44 checkConsistency(model);
45 }
46
47 @Test
48 public void testConstructor2Issues() throws Exception {
49 addTwoIssues();
50 NegoInfo model = new NegoInfo(new Bid(domain), new Bid(domain),
51 utilspace);
52 checkConsistency(model);
53 }
54
55 /****************** support ***********************/
56 private void addTwoIssues() {
57 when(utilspace.getEvaluator(anyInt())).thenReturn(
58 mock(EvaluatorDiscrete.class));
59
60 issues.add(issue());
61 issues.add(issue());
62
63 Objective objectivesRoot = mock(Objective.class);
64 Objective objective = mock(Objective.class);
65
66 when(domain.getObjectivesRoot()).thenReturn(objectivesRoot);
67 when(objectivesRoot.getObjective(anyInt())).thenReturn(objective);
68
69 when(domain.getIssues()).thenReturn(issues);
70
71 }
72
73 private static int nr = 1;
74
75 Issue issue() {
76 IssueDiscrete issue = mock(IssueDiscrete.class);
77 when(issue.getNumber()).thenReturn(nr++);
78 when(issue.getValues()).thenReturn(value());
79 return issue;
80 }
81
82 private List<ValueDiscrete> value() {
83 ArrayList<ValueDiscrete> values = new ArrayList<ValueDiscrete>();
84 for (int n = 0; n < 3; n++) {
85 ValueDiscrete value = mock(ValueDiscrete.class);
86 values.add(value);
87 }
88 return values;
89 }
90
91 private void checkConsistency(AbstractTableModel model) {
92 for (int col = 0; col < model.getColumnCount(); col++) {
93 assertNotNull(model.getColumnName(col));
94 for (int row = 0; row < model.getRowCount(); row++) {
95 assertNotNull("model value in row " + row + ", column " + col
96 + " is not set", model.getValueAt(row, col));
97 }
98 }
99 }
100}
Note: See TracBrowser for help on using the repository browser.