1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.conflict.tags;
|
---|
3 |
|
---|
4 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
---|
5 | import static org.junit.jupiter.api.Assertions.assertNotNull;
|
---|
6 |
|
---|
7 | import java.util.Arrays;
|
---|
8 | import java.util.Collections;
|
---|
9 |
|
---|
10 | import javax.swing.JTable;
|
---|
11 |
|
---|
12 | import org.junit.jupiter.api.extension.RegisterExtension;
|
---|
13 | import org.junit.jupiter.api.Test;
|
---|
14 | import org.openstreetmap.josm.data.osm.Tag;
|
---|
15 | import org.openstreetmap.josm.data.osm.TagCollection;
|
---|
16 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
17 |
|
---|
18 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Unit tests of {@link MultiValueCellRenderer} class.
|
---|
22 | */
|
---|
23 | class MultiValueCellRendererTest {
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Setup test.
|
---|
27 | */
|
---|
28 | @RegisterExtension
|
---|
29 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
30 | public JOSMTestRules test = new JOSMTestRules().preferences();
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * Unit test of {@link MultiValueCellRenderer#MultiValueCellRenderer}.
|
---|
34 | */
|
---|
35 | @Test
|
---|
36 | void testMultiValueCellRenderer() {
|
---|
37 | TagConflictResolverModel model = new TagConflictResolverModel();
|
---|
38 | TagCollection tags = new TagCollection(Arrays.asList(new Tag("oneway", "yes"), new Tag("oneway", "no")));
|
---|
39 | model.populate(tags, Collections.singleton("oneway"));
|
---|
40 | JTable table = new JTable(model);
|
---|
41 | MultiValueResolutionDecision decision = new MultiValueResolutionDecision(tags);
|
---|
42 | MultiValueCellRenderer r = new MultiValueCellRenderer();
|
---|
43 | test(table, decision, r);
|
---|
44 | decision.keepAll();
|
---|
45 | test(table, decision, r);
|
---|
46 | decision.keepNone();
|
---|
47 | test(table, decision, r);
|
---|
48 | decision.keepOne("yes");
|
---|
49 | test(table, decision, r);
|
---|
50 | decision.sumAllNumeric();
|
---|
51 | test(table, decision, r);
|
---|
52 | decision.undecide();
|
---|
53 | test(table, decision, r);
|
---|
54 | }
|
---|
55 |
|
---|
56 | private void test(JTable table, MultiValueResolutionDecision value, MultiValueCellRenderer r) {
|
---|
57 | assertEquals(r, r.getTableCellRendererComponent(table, value, false, false, 0, 0));
|
---|
58 | assertEquals(r, r.getTableCellRendererComponent(table, value, false, false, 0, 1));
|
---|
59 | assertNotNull(r.getTableCellRendererComponent(table, value, false, false, 0, 2));
|
---|
60 | assertEquals(r, r.getTableCellRendererComponent(table, value, true, false, 0, 0));
|
---|
61 | assertEquals(r, r.getTableCellRendererComponent(table, value, true, false, 0, 1));
|
---|
62 | assertNotNull(r.getTableCellRendererComponent(table, value, true, false, 0, 2));
|
---|
63 | }
|
---|
64 | }
|
---|