1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.dialogs.relation;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertNotNull;
|
---|
5 | import static org.junit.Assert.assertNull;
|
---|
6 |
|
---|
7 | import java.util.Collections;
|
---|
8 |
|
---|
9 | import javax.swing.JPanel;
|
---|
10 |
|
---|
11 | import org.junit.Rule;
|
---|
12 | import org.junit.Test;
|
---|
13 | import org.openstreetmap.josm.TestUtils;
|
---|
14 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
15 | import org.openstreetmap.josm.data.osm.Node;
|
---|
16 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
17 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
18 | import org.openstreetmap.josm.data.osm.Way;
|
---|
19 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
20 | import org.openstreetmap.josm.gui.tagging.TagEditorPanel;
|
---|
21 | import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;
|
---|
22 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
23 |
|
---|
24 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Unit tests of {@link GenericRelationEditor} class.
|
---|
28 | */
|
---|
29 | public class GenericRelationEditorTest {
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Setup test.
|
---|
33 | */
|
---|
34 | @Rule
|
---|
35 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
36 | public JOSMTestRules test = new JOSMTestRules().preferences().platform().main();
|
---|
37 |
|
---|
38 | /**
|
---|
39 | * Returns a new relation editor for unit tests.
|
---|
40 | * @param orig relation
|
---|
41 | * @param layer data layer
|
---|
42 | * @return new relation editor for unit tests
|
---|
43 | */
|
---|
44 | public static IRelationEditor newRelationEditor(final Relation orig, final OsmDataLayer layer) {
|
---|
45 | return new IRelationEditor() {
|
---|
46 | private Relation r = orig;
|
---|
47 |
|
---|
48 | @Override
|
---|
49 | public void setRelation(Relation relation) {
|
---|
50 | r = relation;
|
---|
51 | }
|
---|
52 |
|
---|
53 | @Override
|
---|
54 | public boolean isDirtyRelation() {
|
---|
55 | return false;
|
---|
56 | }
|
---|
57 |
|
---|
58 | @Override
|
---|
59 | public Relation getRelationSnapshot() {
|
---|
60 | return r;
|
---|
61 | }
|
---|
62 |
|
---|
63 | @Override
|
---|
64 | public Relation getRelation() {
|
---|
65 | return r;
|
---|
66 | }
|
---|
67 |
|
---|
68 | @Override
|
---|
69 | public void reloadDataFromRelation() {
|
---|
70 | // Do nothing
|
---|
71 | }
|
---|
72 |
|
---|
73 | @Override
|
---|
74 | public OsmDataLayer getLayer() {
|
---|
75 | return layer;
|
---|
76 | }
|
---|
77 | };
|
---|
78 | }
|
---|
79 |
|
---|
80 | /**
|
---|
81 | * Unit test of {@link GenericRelationEditor#addPrimitivesToRelation}.
|
---|
82 | */
|
---|
83 | @Test
|
---|
84 | public void testAddPrimitivesToRelation() {
|
---|
85 | Relation r = TestUtils.addFakeDataSet(new Relation(1));
|
---|
86 | assertNull(GenericRelationEditor.addPrimitivesToRelation(r, Collections.<OsmPrimitive>emptyList()));
|
---|
87 | assertNull(GenericRelationEditor.addPrimitivesToRelation(r, Collections.singleton(new Relation(1))));
|
---|
88 |
|
---|
89 | assertNotNull(GenericRelationEditor.addPrimitivesToRelation(r, Collections.singleton(new Node(1))));
|
---|
90 | assertNotNull(GenericRelationEditor.addPrimitivesToRelation(r, Collections.singleton(new Way(1))));
|
---|
91 | assertNotNull(GenericRelationEditor.addPrimitivesToRelation(r, Collections.singleton(new Relation(2))));
|
---|
92 | }
|
---|
93 |
|
---|
94 | /**
|
---|
95 | * Unit test of {@code GenericRelationEditor#build*} methods.
|
---|
96 | */
|
---|
97 | @Test
|
---|
98 | public void testBuild() {
|
---|
99 | DataSet ds = new DataSet();
|
---|
100 | Relation relation = new Relation(1);
|
---|
101 | ds.addPrimitive(relation);
|
---|
102 | OsmDataLayer layer = new OsmDataLayer(ds, "test", null);
|
---|
103 | IRelationEditor re = newRelationEditor(relation, layer);
|
---|
104 |
|
---|
105 | AutoCompletingTextField tfRole = GenericRelationEditor.buildRoleTextField(re);
|
---|
106 | assertNotNull(tfRole);
|
---|
107 |
|
---|
108 | TagEditorPanel tagEditorPanel = new TagEditorPanel(relation, null);
|
---|
109 |
|
---|
110 | JPanel top = GenericRelationEditor.buildTagEditorPanel(tagEditorPanel);
|
---|
111 | assertNotNull(top);
|
---|
112 | assertNotNull(tagEditorPanel.getModel());
|
---|
113 | }
|
---|
114 | }
|
---|