1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.dialogs.properties;
|
---|
3 |
|
---|
4 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
---|
5 |
|
---|
6 | import java.util.ArrayList;
|
---|
7 | import java.util.List;
|
---|
8 |
|
---|
9 | import org.junit.jupiter.api.extension.RegisterExtension;
|
---|
10 | import org.junit.jupiter.api.Test;
|
---|
11 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
12 | import org.openstreetmap.josm.data.osm.Node;
|
---|
13 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
14 | import org.openstreetmap.josm.data.osm.Way;
|
---|
15 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
16 |
|
---|
17 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Unit tests of {@link PropertiesDialog} class.
|
---|
21 | */
|
---|
22 | class PropertiesDialogTest {
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * Setup tests
|
---|
26 | */
|
---|
27 | @RegisterExtension
|
---|
28 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
29 | public JOSMTestRules test = new JOSMTestRules();
|
---|
30 |
|
---|
31 | private static String createSearchSetting(List<OsmPrimitive> sel, boolean sameType) {
|
---|
32 | return PropertiesDialog.createSearchSetting("foo", sel, sameType).text;
|
---|
33 | }
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Non-regression test for ticket <a href="https://josm.openstreetmap.de/ticket/12504">#12504</a>.
|
---|
37 | */
|
---|
38 | @Test
|
---|
39 | void testTicket12504() {
|
---|
40 | List<OsmPrimitive> sel = new ArrayList<>();
|
---|
41 | // 160 objects with foo=bar, 400 objects without foo
|
---|
42 | for (int i = 0; i < 160+400; i++) {
|
---|
43 | Node n = new Node(LatLon.ZERO);
|
---|
44 | if (i < 160) {
|
---|
45 | n.put("foo", "bar");
|
---|
46 | }
|
---|
47 | sel.add(n);
|
---|
48 | }
|
---|
49 | assertEquals("(\"foo\"=\"bar\")", createSearchSetting(sel, false));
|
---|
50 |
|
---|
51 | Node n = new Node(LatLon.ZERO);
|
---|
52 | n.put("foo", "baz");
|
---|
53 | sel.add(0, n);
|
---|
54 |
|
---|
55 | assertEquals("(\"foo\"=\"baz\") OR (\"foo\"=\"bar\")", createSearchSetting(sel, false));
|
---|
56 |
|
---|
57 | sel.remove(0);
|
---|
58 |
|
---|
59 | Way w = new Way();
|
---|
60 | w.put("foo", "bar");
|
---|
61 | sel.add(0, w);
|
---|
62 |
|
---|
63 | assertEquals("(type:way \"foo\"=\"bar\") OR (type:node \"foo\"=\"bar\")", createSearchSetting(sel, true));
|
---|
64 | }
|
---|
65 | }
|
---|