[1] | 1 | package negotiator.parties;
|
---|
| 2 |
|
---|
| 3 | import static org.junit.Assert.assertNotNull;
|
---|
| 4 | import static org.mockito.Matchers.anyInt;
|
---|
| 5 | import static org.mockito.Mockito.mock;
|
---|
| 6 | import static org.mockito.Mockito.when;
|
---|
| 7 |
|
---|
| 8 | import java.util.ArrayList;
|
---|
| 9 | import java.util.List;
|
---|
| 10 |
|
---|
| 11 | import javax.swing.table.AbstractTableModel;
|
---|
| 12 |
|
---|
| 13 | import org.junit.Before;
|
---|
| 14 | import org.junit.Test;
|
---|
| 15 |
|
---|
| 16 | import genius.core.Bid;
|
---|
| 17 | import genius.core.Domain;
|
---|
| 18 | import genius.core.issue.Issue;
|
---|
| 19 | import genius.core.issue.IssueDiscrete;
|
---|
| 20 | import genius.core.issue.Objective;
|
---|
| 21 | import genius.core.issue.ValueDiscrete;
|
---|
| 22 | import genius.core.utility.AdditiveUtilitySpace;
|
---|
| 23 | import genius.core.utility.EvaluatorDiscrete;
|
---|
| 24 |
|
---|
| 25 | public 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 | }
|
---|