source: josm/trunk/test/unit/org/openstreetmap/josm/actions/upload/FixDataHookTest.java

Last change on this file was 18870, checked in by taylor.smock, 6 months ago

See #16567: Update to JUnit 5

This converts most tests to use @Annotations. There are also some performance
improvements as it relates to tests.

  • Property svn:eol-style set to native
File size: 4.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions.upload;
3
4import static org.junit.jupiter.api.Assertions.assertEquals;
5import static org.junit.jupiter.api.Assertions.assertFalse;
6import static org.junit.jupiter.api.Assertions.assertNotEquals;
7import static org.junit.jupiter.api.Assertions.assertNotNull;
8import static org.junit.jupiter.api.Assertions.assertTrue;
9
10import java.util.Arrays;
11import java.util.Collection;
12
13import org.junit.jupiter.api.Test;
14import org.openstreetmap.josm.command.PseudoCommand;
15import org.openstreetmap.josm.command.SequenceCommand;
16import org.openstreetmap.josm.data.APIDataSet;
17import org.openstreetmap.josm.data.UndoRedoHandler;
18import org.openstreetmap.josm.data.osm.DataSet;
19import org.openstreetmap.josm.data.osm.OsmPrimitive;
20import org.openstreetmap.josm.data.osm.Relation;
21import org.openstreetmap.josm.data.osm.Way;
22import org.openstreetmap.josm.testutils.annotations.Main;
23
24/**
25 * Unit tests for class {@link FixDataHook}.
26 */
27@Main
28class FixDataHookTest {
29 /**
30 * Test of {@link FixDataHook#checkUpload} method.
31 */
32 @Test
33 void testCheckUpload() {
34 // Empty data set
35 UndoRedoHandler.getInstance().clean();
36 new FixDataHook().checkUpload(new APIDataSet());
37 assertTrue(UndoRedoHandler.getInstance().getUndoCommands().isEmpty());
38
39 // Complete data set (except empty node which cannot be tested anymore)
40 Way emptyWay = new Way();
41 Relation emptyRelation = new Relation();
42 Way w1 = new Way();
43 w1.put("color", "test");
44 Way w2 = new Way();
45 w2.put("highway", "ford");
46 Way w3 = new Way();
47 w3.put("oneway", "false");
48 Way w4 = new Way();
49 w4.put("oneway", "0");
50 Way w5 = new Way();
51 w5.put("oneway", "true");
52 Way w6 = new Way();
53 w6.put("oneway", "1");
54 Way w7 = new Way();
55 w7.put("highway", "stile");
56 Relation r1 = new Relation();
57 r1.put("type", "multipolygon");
58 r1.put("boundary", "administrative");
59 Relation r2 = new Relation();
60 r2.put("foo", "space_end ");
61 r2.put("bar", " space_begin ");
62 r2.put("baz", " space_both ");
63 r2.put(" space_begin", "test");
64 r2.put("space_end ", "test");
65 r2.put(" space_both ", "test");
66 APIDataSet ads = new APIDataSet();
67 ads.init(new DataSet(emptyWay, emptyRelation, w1, w2, w3, w4, w5, w6, w7, r1, r2));
68
69 assertEquals(0, UndoRedoHandler.getInstance().getUndoCommands().size());
70 new FixDataHook().checkUpload(ads);
71 assertEquals(1, UndoRedoHandler.getInstance().getUndoCommands().size());
72
73 SequenceCommand seq = (SequenceCommand) UndoRedoHandler.getInstance().getUndoCommands().iterator().next();
74 Collection<? extends OsmPrimitive> prims = seq.getParticipatingPrimitives();
75 assertNotNull(prims);
76 assertEquals(9, prims.size());
77 for (OsmPrimitive o : Arrays.asList(w1, w2, w3, w4, w5, w6, w7, r1, r2)) {
78 assertTrue(prims.contains(o), o.toString());
79 }
80 Collection<PseudoCommand> cmds = seq.getChildren();
81 assertNotNull(cmds);
82 assertEquals(9, cmds.size());
83
84 assertTrue(seq.executeCommand());
85
86 assertFalse(w1.hasKey("color"));
87 assertTrue(w1.hasKey("colour"));
88
89 assertFalse(w2.hasKey("highway"));
90 assertTrue(w2.hasKey("ford"));
91
92 assertNotEquals("false", w3.get("oneway"));
93 assertEquals("no", w3.get("oneway"));
94
95 assertNotEquals("0", w4.get("oneway"));
96 assertEquals("no", w4.get("oneway"));
97
98 assertNotEquals("true", w5.get("oneway"));
99 assertEquals("yes", w5.get("oneway"));
100
101 assertNotEquals("1", w6.get("oneway"));
102 assertEquals("yes", w6.get("oneway"));
103
104 assertFalse(w7.hasKey("highway"));
105 assertTrue(w7.hasKey("barrier"));
106
107 assertNotEquals("multipolygon", r1.get("type"));
108 assertEquals("boundary", r1.get("type"));
109
110 assertEquals("space_end", r2.get("foo"));
111 assertEquals("space_begin", r2.get("bar"));
112 assertEquals("space_both", r2.get("baz"));
113 assertFalse(r2.hasKey(" space_begin"));
114 assertFalse(r2.hasKey("space_end "));
115 assertFalse(r2.hasKey(" space_both "));
116 assertTrue(r2.hasKey("space_begin"));
117 assertTrue(r2.hasKey("space_end"));
118 assertTrue(r2.hasKey("space_both"));
119 }
120}
Note: See TracBrowser for help on using the repository browser.