Changeset 10663 in josm for trunk/test/unit/org/openstreetmap
- Timestamp:
- 2016-07-28T01:24:39+02:00 (8 years ago)
- Location:
- trunk/test/unit/org/openstreetmap/josm/command
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/command/AddCommandTest.java
r9943 r10663 2 2 package org.openstreetmap.josm.command; 3 3 4 import org.junit.BeforeClass; 4 import static org.junit.Assert.assertArrayEquals; 5 import static org.junit.Assert.assertTrue; 6 7 import java.util.ArrayList; 8 9 import org.junit.Rule; 5 10 import org.junit.Test; 6 import org.openstreetmap.josm.JOSMFixture; 11 import org.openstreetmap.josm.Main; 12 import org.openstreetmap.josm.data.coor.LatLon; 7 13 import org.openstreetmap.josm.data.osm.DataSet; 8 14 import org.openstreetmap.josm.data.osm.Node; 9 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; 16 import org.openstreetmap.josm.data.osm.Relation; 10 17 import org.openstreetmap.josm.data.osm.User; 18 import org.openstreetmap.josm.data.osm.Way; 11 19 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 20 import org.openstreetmap.josm.testutils.JOSMTestRules; 12 21 22 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 13 23 import nl.jqno.equalsverifier.EqualsVerifier; 14 24 import nl.jqno.equalsverifier.Warning; … … 20 30 21 31 /** 22 * Setup test.32 * We need prefs for nodes. 23 33 */ 24 @BeforeClass 25 public static void setUpBeforeClass() { 26 JOSMFixture.createUnitTestFixture().init(false); 34 @Rule 35 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 36 public JOSMTestRules test = new JOSMTestRules().preferences().i18n(); 37 38 /** 39 * Test if the add command is executed correctly and sets the modified flag. 40 */ 41 @Test 42 public void testAdd() { 43 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 44 Main.getLayerManager().addLayer(layer1); 45 assertArrayEquals(new Object[0], layer1.data.allPrimitives().toArray()); 46 47 Node osm = new Node(LatLon.ZERO); 48 assertTrue(new AddCommand(osm).executeCommand()); 49 50 assertArrayEquals(new Object[] {osm}, layer1.data.allPrimitives().toArray()); 51 assertArrayEquals(new Object[] {osm}, layer1.data.allModifiedPrimitives().toArray()); 52 assertTrue(osm.isModified()); 53 } 54 55 /** 56 * Tests if the add command respects the layer. 57 */ 58 @Test 59 public void testAddToLayer() { 60 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 61 OsmDataLayer layer2 = new OsmDataLayer(new DataSet(), "l1", null); 62 63 Main.getLayerManager().addLayer(layer1); 64 Main.getLayerManager().addLayer(layer2); 65 66 Node osm = new Node(LatLon.ZERO); 67 assertTrue(new AddCommand(layer2, osm).executeCommand()); 68 69 assertArrayEquals(new Object[0], layer1.data.allPrimitives().toArray()); 70 assertArrayEquals(new Object[] {osm}, layer2.data.allPrimitives().toArray()); 71 } 72 73 /** 74 * Test {@link AddCommand#undoCommand()} 75 */ 76 @Test 77 public void testUndo() { 78 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 79 Main.getLayerManager().addLayer(layer1); 80 Node osm = new Node(LatLon.ZERO); 81 layer1.data.addPrimitive(osm); 82 83 AddCommand command = new AddCommand(new Node(LatLon.ZERO)); 84 command.executeCommand(); 85 86 command.undoCommand(); 87 assertArrayEquals(new Object[] {osm}, layer1.data.allPrimitives().toArray()); 88 } 89 90 /** 91 * Test {@link AddCommand#getParticipatingPrimitives()} 92 */ 93 @Test 94 public void testParticipatingPrimitives() { 95 Node osm = new Node(LatLon.ZERO); 96 97 assertArrayEquals(new Object[] {osm}, new AddCommand(osm).getParticipatingPrimitives().toArray()); 98 } 99 100 /** 101 * Tests {@link AddCommand#fillModifiedData(java.util.Collection, java.util.Collection, java.util.Collection)} 102 */ 103 @Test 104 public void testFillModifiedData() { 105 Node osm = new Node(LatLon.ZERO); 106 107 ArrayList<OsmPrimitive> modified = new ArrayList<>(); 108 ArrayList<OsmPrimitive> deleted = new ArrayList<>(); 109 ArrayList<OsmPrimitive> added = new ArrayList<>(); 110 new AddCommand(osm).fillModifiedData(modified, deleted, added); 111 assertArrayEquals(new Object[] {}, modified.toArray()); 112 assertArrayEquals(new Object[] {}, deleted.toArray()); 113 assertArrayEquals(new Object[] {osm}, added.toArray()); 114 } 115 116 /** 117 * Test {@link AddCommand#getDescriptionText()} 118 */ 119 @Test 120 public void testDescription() { 121 Node node = new Node(LatLon.ZERO); 122 node.put("name", "xy"); 123 Way way = new Way(); 124 way.addNode(node); 125 way.put("name", "xy"); 126 Relation relation = new Relation(); 127 relation.put("name", "xy"); 128 129 assertTrue(new AddCommand(node).getDescriptionText().matches("Add node.*xy.*")); 130 assertTrue(new AddCommand(way).getDescriptionText().matches("Add way.*xy.*")); 131 assertTrue(new AddCommand(relation).getDescriptionText().matches("Add relation.*xy.*")); 27 132 } 28 133 -
trunk/test/unit/org/openstreetmap/josm/command/AddPrimitivesCommandTest.java
r9943 r10663 2 2 package org.openstreetmap.josm.command; 3 3 4 import org.junit.BeforeClass; 4 import static org.junit.Assert.assertArrayEquals; 5 import static org.junit.Assert.assertEquals; 6 import static org.junit.Assert.assertFalse; 7 import static org.junit.Assert.assertSame; 8 import static org.junit.Assert.assertTrue; 9 10 import java.util.ArrayList; 11 import java.util.Arrays; 12 import java.util.HashSet; 13 import java.util.List; 14 15 import org.junit.Rule; 5 16 import org.junit.Test; 6 import org.openstreetmap.josm.JOSMFixture; 17 import org.openstreetmap.josm.Main; 18 import org.openstreetmap.josm.data.coor.LatLon; 7 19 import org.openstreetmap.josm.data.osm.DataSet; 20 import org.openstreetmap.josm.data.osm.Node; 21 import org.openstreetmap.josm.data.osm.NodeData; 22 import org.openstreetmap.josm.data.osm.OsmPrimitive; 23 import org.openstreetmap.josm.data.osm.PrimitiveData; 8 24 import org.openstreetmap.josm.data.osm.User; 25 import org.openstreetmap.josm.data.osm.Way; 26 import org.openstreetmap.josm.data.osm.WayData; 9 27 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 10 28 import org.openstreetmap.josm.testutils.JOSMTestRules; 29 30 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 11 31 import nl.jqno.equalsverifier.EqualsVerifier; 12 32 import nl.jqno.equalsverifier.Warning; … … 18 38 19 39 /** 20 * Setup test. 21 */ 22 @BeforeClass 23 public static void setUpBeforeClass() { 24 JOSMFixture.createUnitTestFixture().init(false); 40 * We need prefs for nodes. 41 */ 42 @Rule 43 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 44 public JOSMTestRules test = new JOSMTestRules().preferences().i18n(); 45 46 /** 47 * Test if the add command is executed correctly and does not set the modified flag. 48 */ 49 @Test 50 public void testAdd() { 51 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 52 Main.getLayerManager().addLayer(layer1); 53 54 List<PrimitiveData> testData = createTestData(); 55 assertTrue(new AddPrimitivesCommand(testData).executeCommand()); 56 57 testContainsTestData(layer1); 58 assertEquals(3, layer1.data.getAllSelected().size()); 59 } 60 61 /** 62 * Test if the add command sets the selection. 63 */ 64 @Test 65 public void testAddSetSelection() { 66 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 67 Main.getLayerManager().addLayer(layer1); 68 69 List<PrimitiveData> testData = createTestData(); 70 assertTrue(new AddPrimitivesCommand(testData, testData.subList(2, 3)).executeCommand()); 71 72 testContainsTestData(layer1); 73 74 assertEquals(1, layer1.data.getAllSelected().size()); 75 assertEquals(1, layer1.data.getSelectedWays().size()); 76 } 77 78 /** 79 * Tests if the add command respects the layer. 80 */ 81 @Test 82 public void testAddToLayer() { 83 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 84 OsmDataLayer layer2 = new OsmDataLayer(new DataSet(), "l1", null); 85 86 Main.getLayerManager().addLayer(layer1); 87 Main.getLayerManager().addLayer(layer2); 88 89 List<PrimitiveData> testData = createTestData(); 90 assertTrue(new AddPrimitivesCommand(testData, testData.subList(2, 3), layer1).executeCommand()); 91 92 testContainsTestData(layer1); 93 assertTrue(layer2.data.allPrimitives().isEmpty()); 94 95 assertEquals(1, layer1.data.getAllSelected().size()); 96 assertEquals(1, layer1.data.getSelectedWays().size()); 97 } 98 99 /** 100 * Tests if the add command ignores existing data 101 */ 102 @Test 103 public void testAddIgnoresExisting() { 104 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 105 Main.getLayerManager().addLayer(layer1); 106 107 List<PrimitiveData> testData = createTestData(); 108 assertTrue(new AddPrimitivesCommand(testData).executeCommand()); 109 assertEquals(2, layer1.data.getNodes().size()); 110 assertEquals(1, layer1.data.getWays().size()); 111 112 testData.set(2, createTestNode(7)); 113 assertTrue(new AddPrimitivesCommand(testData).executeCommand()); 114 115 assertEquals(3, layer1.data.getNodes().size()); 116 assertEquals(1, layer1.data.getWays().size()); 117 } 118 119 /** 120 * Test {@link AddPrimitivesCommand#getDescriptionText()} 121 */ 122 @Test 123 public void testDescription() { 124 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 125 Main.getLayerManager().addLayer(layer1); 126 127 List<PrimitiveData> testData = createTestData(); 128 NodeData data2 = createTestNode(7); 129 130 AddPrimitivesCommand command1 = new AddPrimitivesCommand(testData); 131 AddPrimitivesCommand command2 = new AddPrimitivesCommand(Arrays.<PrimitiveData>asList(data2)); 132 133 assertEquals("Added 3 objects", command1.getDescriptionText()); 134 assertEquals("Added 1 object", command2.getDescriptionText()); 135 136 // Name must be the same after execution. 137 assertTrue(command1.executeCommand()); 138 assertTrue(command2.executeCommand()); 139 140 assertEquals("Added 3 objects", command1.getDescriptionText()); 141 assertEquals("Added 1 object", command2.getDescriptionText()); 142 } 143 144 /** 145 * Test {@link AddPrimitivesCommand#undoCommand()} 146 */ 147 @Test 148 public void testUndo() { 149 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 150 Main.getLayerManager().addLayer(layer1); 151 152 List<PrimitiveData> testData = createTestData(); 153 154 AddPrimitivesCommand command = new AddPrimitivesCommand(testData); 155 156 assertTrue(command.executeCommand()); 157 158 assertEquals(3, layer1.data.allPrimitives().size()); 159 assertEquals(1, layer1.data.getWays().size()); 160 Way way = layer1.data.getWays().iterator().next(); 161 162 for (int i = 0; i < 2; i++) { 163 // Needs to work multiple times. 164 command.undoCommand(); 165 166 assertEquals(0, layer1.data.allPrimitives().size()); 167 assertEquals(0, layer1.data.getWays().size()); 168 169 // redo 170 assertTrue(command.executeCommand()); 171 172 assertEquals(3, layer1.data.allPrimitives().size()); 173 assertEquals(1, layer1.data.getWays().size()); 174 assertSame(way, layer1.data.getWays().iterator().next()); 175 } 176 } 177 178 /** 179 * Test {@link AddCommand#getParticipatingPrimitives()} 180 */ 181 @Test 182 public void testParticipatingPrimitives() { 183 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 184 Main.getLayerManager().addLayer(layer1); 185 186 List<PrimitiveData> testData = createTestData(); 187 AddPrimitivesCommand command = new AddPrimitivesCommand(testData); 188 assertTrue(command.executeCommand()); 189 190 assertEquals(3, command.getParticipatingPrimitives().size()); 191 HashSet<OsmPrimitive> should = new HashSet<>(layer1.data.allPrimitives()); 192 assertEquals(should, new HashSet<>(command.getParticipatingPrimitives())); 193 194 // needs to be the same after undo 195 command.undoCommand(); 196 assertEquals(should, new HashSet<>(command.getParticipatingPrimitives())); 197 } 198 199 /** 200 * Tests {@link AddPrimitivesCommand#fillModifiedData(java.util.Collection, java.util.Collection, java.util.Collection)} 201 */ 202 @Test 203 public void testFillModifiedData() { 204 ArrayList<OsmPrimitive> modified = new ArrayList<>(); 205 ArrayList<OsmPrimitive> deleted = new ArrayList<>(); 206 ArrayList<OsmPrimitive> added = new ArrayList<>(); 207 208 List<PrimitiveData> testData = createTestData(); 209 new AddPrimitivesCommand(testData).fillModifiedData(modified, deleted, added); 210 211 assertArrayEquals(new Object[] {}, modified.toArray()); 212 assertArrayEquals(new Object[] {}, deleted.toArray()); 213 assertArrayEquals(new Object[] {}, added.toArray()); 214 } 215 216 private void testContainsTestData(OsmDataLayer layer1) { 217 assertEquals(3, layer1.data.allPrimitives().size()); 218 assertEquals(2, layer1.data.getNodes().size()); 219 assertEquals(1, layer1.data.getWays().size()); 220 assertEquals(0, layer1.data.allModifiedPrimitives().size()); 221 for (OsmPrimitive n : layer1.data.allPrimitives()) { 222 assertEquals("test", n.get("test")); 223 assertFalse(n.isModified()); 224 } 225 226 for (Node n : layer1.data.getNodes()) { 227 assertEquals(LatLon.ZERO, n.getCoor()); 228 } 229 230 for (Way w : layer1.data.getWays()) { 231 assertEquals(2, w.getNodes().size()); 232 assertEquals(5, w.getNode(0).getId()); 233 assertEquals(6, w.getNode(1).getId()); 234 } 235 } 236 237 private List<PrimitiveData> createTestData() { 238 NodeData node1 = createTestNode(5); 239 NodeData node2 = createTestNode(6); 240 WayData way = new WayData(); 241 way.put("test", "test"); 242 way.setNodes(Arrays.asList(node1.getId(), node2.getId())); 243 List<PrimitiveData> testData = Arrays.<PrimitiveData>asList(node1, node2, way); 244 return testData; 245 } 246 247 private NodeData createTestNode(int id) { 248 NodeData node1 = new NodeData(); 249 node1.setCoor(LatLon.ZERO); 250 node1.put("test", "test"); 251 node1.setId(id); 252 return node1; 25 253 } 26 254 -
trunk/test/unit/org/openstreetmap/josm/command/ChangeCommandTest.java
r9943 r10663 2 2 package org.openstreetmap.josm.command; 3 3 4 import org.junit.BeforeClass; 4 import static org.junit.Assert.assertArrayEquals; 5 import static org.junit.Assert.assertEquals; 6 import static org.junit.Assert.assertNull; 7 import static org.junit.Assert.assertTrue; 8 9 import java.util.ArrayList; 10 import java.util.Collections; 11 import java.util.List; 12 13 import org.junit.Before; 14 import org.junit.Rule; 5 15 import org.junit.Test; 6 import org.openstreetmap.josm.JOSMFixture; 16 import org.openstreetmap.josm.command.CommandTest.CommandTestData; 17 import org.openstreetmap.josm.data.coor.LatLon; 18 import org.openstreetmap.josm.data.osm.DataIntegrityProblemException; 7 19 import org.openstreetmap.josm.data.osm.DataSet; 8 20 import org.openstreetmap.josm.data.osm.Node; 9 21 import org.openstreetmap.josm.data.osm.OsmPrimitive; 22 import org.openstreetmap.josm.data.osm.Relation; 10 23 import org.openstreetmap.josm.data.osm.User; 24 import org.openstreetmap.josm.data.osm.Way; 11 25 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 26 import org.openstreetmap.josm.testutils.JOSMTestRules; 12 27 28 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 13 29 import nl.jqno.equalsverifier.EqualsVerifier; 14 30 import nl.jqno.equalsverifier.Warning; … … 20 36 21 37 /** 22 * Setup test.38 * We need prefs for nodes. 23 39 */ 24 @BeforeClass 25 public static void setUpBeforeClass() { 26 JOSMFixture.createUnitTestFixture().init(false); 40 @Rule 41 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 42 public JOSMTestRules test = new JOSMTestRules().preferences().i18n(); 43 private CommandTestData testData; 44 45 /** 46 * Set up the test data. 47 */ 48 @Before 49 public void createTestData() { 50 testData = new CommandTestData(); 51 } 52 53 /** 54 * Test that empty ways are prevented. 55 */ 56 @Test(expected = IllegalArgumentException.class) 57 public void testPreventEmptyWays() { 58 Way emptyWay = new Way(); 59 new ChangeCommand(testData.existingWay, emptyWay); 60 } 61 62 /** 63 * Test {@link ChangeCommand#executeCommand()} 64 */ 65 @Test 66 public void testChange() { 67 Node newNode = new Node(5); 68 newNode.setCoor(LatLon.NORTH_POLE); 69 newNode.put("new", "new"); 70 71 new ChangeCommand(testData.existingNode, newNode).executeCommand(); 72 73 assertEquals("new", testData.existingNode.get("new")); 74 assertEquals(null, testData.existingNode.get("existing")); 75 assertEquals(LatLon.NORTH_POLE, testData.existingNode.getCoor()); 76 77 Way newWay = new Way(10); 78 List<Node> newNodes = testData.existingWay.getNodes(); 79 Collections.reverse(newNodes); 80 newWay.setNodes(newNodes); 81 82 new ChangeCommand(testData.existingWay, newWay).executeCommand(); 83 assertArrayEquals(newNodes.toArray(), testData.existingWay.getNodes().toArray()); 84 } 85 86 /** 87 * Test {@link ChangeCommand#executeCommand()} fails if ID is changed 88 */ 89 @Test(expected = DataIntegrityProblemException.class) 90 public void testChangeIdChange() { 91 Node newNode = new Node(1); 92 newNode.setCoor(LatLon.NORTH_POLE); 93 94 new ChangeCommand(testData.existingNode, newNode).executeCommand(); 95 } 96 97 /** 98 * Test {@link ChangeCommand#undoCommand()} 99 */ 100 @Test 101 public void testUndo() { 102 Node newNode = new Node(5); 103 newNode.setCoor(LatLon.NORTH_POLE); 104 newNode.put("new", "new"); 105 106 ChangeCommand command = new ChangeCommand(testData.existingNode, newNode); 107 command.executeCommand(); 108 109 assertEquals("new", testData.existingNode.get("new")); 110 assertEquals(LatLon.NORTH_POLE, testData.existingNode.getCoor()); 111 112 command.undoCommand(); 113 assertNull(testData.existingNode.get("new")); 114 assertEquals("existing", testData.existingNode.get("existing")); 115 assertEquals(LatLon.ZERO, testData.existingNode.getCoor()); 116 } 117 118 /** 119 * Tests {@link ChangeCommand#fillModifiedData(java.util.Collection, java.util.Collection, java.util.Collection)} 120 */ 121 @Test 122 public void testFillModifiedData() { 123 ArrayList<OsmPrimitive> modified = new ArrayList<>(); 124 ArrayList<OsmPrimitive> deleted = new ArrayList<>(); 125 ArrayList<OsmPrimitive> added = new ArrayList<>(); 126 new ChangeCommand(testData.existingNode, testData.existingNode).fillModifiedData(modified, deleted, added); 127 assertArrayEquals(new Object[] {testData.existingNode}, modified.toArray()); 128 assertArrayEquals(new Object[] {}, deleted.toArray()); 129 assertArrayEquals(new Object[] {}, added.toArray()); 130 } 131 132 /** 133 * Test {@link ChangeCommand#getDescriptionText()} 134 */ 135 @Test 136 public void testDescription() { 137 Node node = new Node(LatLon.ZERO); 138 node.put("name", "xy"); 139 Way way = new Way(); 140 way.addNode(node); 141 way.put("name", "xy"); 142 Relation relation = new Relation(); 143 relation.put("name", "xy"); 144 145 assertTrue(new ChangeCommand(node, node).getDescriptionText().matches("Change node.*xy.*")); 146 assertTrue(new ChangeCommand(way, way).getDescriptionText().matches("Change way.*xy.*")); 147 assertTrue(new ChangeCommand(relation, relation).getDescriptionText().matches("Change relation.*xy.*")); 27 148 } 28 149 -
trunk/test/unit/org/openstreetmap/josm/command/ChangeNodesCommandTest.java
r9943 r10663 2 2 package org.openstreetmap.josm.command; 3 3 4 import org.junit.BeforeClass; 4 import static org.junit.Assert.assertArrayEquals; 5 import static org.junit.Assert.assertEquals; 6 import static org.junit.Assert.assertFalse; 7 import static org.junit.Assert.assertTrue; 8 9 import java.util.ArrayList; 10 import java.util.Arrays; 11 import java.util.Collections; 12 import java.util.List; 13 14 import org.junit.Before; 15 import org.junit.Rule; 5 16 import org.junit.Test; 6 import org.openstreetmap.josm.JOSMFixture; 17 import org.openstreetmap.josm.command.CommandTest.CommandTestData; 18 import org.openstreetmap.josm.data.coor.LatLon; 7 19 import org.openstreetmap.josm.data.osm.DataSet; 20 import org.openstreetmap.josm.data.osm.Node; 21 import org.openstreetmap.josm.data.osm.OsmPrimitive; 8 22 import org.openstreetmap.josm.data.osm.User; 9 23 import org.openstreetmap.josm.data.osm.Way; 10 24 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 25 import org.openstreetmap.josm.testutils.JOSMTestRules; 11 26 27 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 12 28 import nl.jqno.equalsverifier.EqualsVerifier; 13 29 import nl.jqno.equalsverifier.Warning; … … 19 35 20 36 /** 21 * Setup test.37 * We need prefs for nodes. 22 38 */ 23 @BeforeClass 24 public static void setUpBeforeClass() { 25 JOSMFixture.createUnitTestFixture().init(false); 39 @Rule 40 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 41 public JOSMTestRules test = new JOSMTestRules().preferences().i18n(); 42 private CommandTestData testData; 43 44 /** 45 * Set up the test data. 46 */ 47 @Before 48 public void createTestData() { 49 testData = new CommandTestData(); 50 } 51 52 /** 53 * Test that empty ways are prevented. 54 */ 55 @Test(expected = IllegalArgumentException.class) 56 public void testPreventEmptyWays() { 57 new ChangeNodesCommand(testData.existingWay, Collections.<Node>emptyList()); 58 } 59 60 /** 61 * Test {@link ChangeNodesCommand#executeCommand()} 62 */ 63 @Test 64 public void testChange() { 65 List<Node> newNodes = testData.existingWay.getNodes(); 66 Collections.reverse(newNodes); 67 68 new ChangeNodesCommand(testData.existingWay, newNodes).executeCommand(); 69 assertArrayEquals(newNodes.toArray(), testData.existingWay.getNodes().toArray()); 70 71 // tags are unchanged 72 assertEquals("existing", testData.existingWay.get("existing")); 73 assertTrue(testData.existingWay.isModified()); 74 } 75 76 /** 77 * Test {@link ChangeCommand#undoCommand()} 78 */ 79 @Test 80 public void testUndo() { 81 List<Node> newNodes = testData.existingWay.getNodes(); 82 Collections.reverse(newNodes); 83 84 ChangeNodesCommand command = new ChangeNodesCommand(testData.existingWay, newNodes); 85 command.executeCommand(); 86 command.undoCommand(); 87 Collections.reverse(newNodes); 88 assertArrayEquals(newNodes.toArray(), testData.existingWay.getNodes().toArray()); 89 assertFalse(testData.existingWay.isModified()); 90 } 91 92 /** 93 * Tests {@link ChangeNodesCommand#fillModifiedData(java.util.Collection, java.util.Collection, java.util.Collection)} 94 */ 95 @Test 96 public void testFillModifiedData() { 97 ArrayList<OsmPrimitive> modified = new ArrayList<>(); 98 ArrayList<OsmPrimitive> deleted = new ArrayList<>(); 99 ArrayList<OsmPrimitive> added = new ArrayList<>(); 100 new ChangeNodesCommand(testData.existingWay, Arrays.asList(testData.existingNode)).fillModifiedData(modified, 101 deleted, added); 102 assertArrayEquals(new Object[] {testData.existingWay}, modified.toArray()); 103 assertArrayEquals(new Object[] {}, deleted.toArray()); 104 assertArrayEquals(new Object[] {}, added.toArray()); 105 } 106 107 /** 108 * Test {@link ChangeNodesCommand#getDescriptionText()} 109 */ 110 @Test 111 public void testDescription() { 112 Node node = new Node(LatLon.ZERO); 113 node.put("name", "xy"); 114 Way way = new Way(); 115 way.addNode(node); 116 way.put("name", "xy"); 117 118 assertTrue( 119 new ChangeNodesCommand(way, Arrays.asList(node)).getDescriptionText().matches("Change nodes of.*xy.*")); 26 120 } 27 121 -
trunk/test/unit/org/openstreetmap/josm/command/ChangePropertyCommandTest.java
r9943 r10663 2 2 package org.openstreetmap.josm.command; 3 3 4 import org.junit.BeforeClass; 4 import static org.junit.Assert.assertArrayEquals; 5 import static org.junit.Assert.assertEquals; 6 import static org.junit.Assert.assertFalse; 7 import static org.junit.Assert.assertNull; 8 import static org.junit.Assert.assertTrue; 9 10 import java.util.ArrayList; 11 import java.util.Arrays; 12 import java.util.Collection; 13 import java.util.HashMap; 14 import java.util.List; 15 16 import org.junit.Before; 17 import org.junit.Rule; 5 18 import org.junit.Test; 6 import org.openstreetmap.josm. JOSMFixture;19 import org.openstreetmap.josm.command.CommandTest.CommandTestData; 7 20 import org.openstreetmap.josm.data.osm.DataSet; 21 import org.openstreetmap.josm.data.osm.Node; 22 import org.openstreetmap.josm.data.osm.OsmPrimitive; 23 import org.openstreetmap.josm.data.osm.Relation; 24 import org.openstreetmap.josm.data.osm.TagMap; 8 25 import org.openstreetmap.josm.data.osm.User; 26 import org.openstreetmap.josm.data.osm.Way; 9 27 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 10 28 import org.openstreetmap.josm.testutils.JOSMTestRules; 29 30 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 11 31 import nl.jqno.equalsverifier.EqualsVerifier; 12 32 import nl.jqno.equalsverifier.Warning; … … 18 38 19 39 /** 20 * Setup test. 21 */ 22 @BeforeClass 23 public static void setUpBeforeClass() { 24 JOSMFixture.createUnitTestFixture().init(false); 40 * We need prefs for nodes. 41 */ 42 @Rule 43 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 44 public JOSMTestRules test = new JOSMTestRules().preferences().i18n(); 45 private CommandTestData testData; 46 47 /** 48 * Set up the test data. 49 */ 50 @Before 51 public void createTestData() { 52 testData = new CommandTestData(); 53 } 54 55 /** 56 * Checks that the short constructors create the right {@link ChangePropertyCommand} 57 */ 58 @Test 59 public void testShortConstructor() { 60 ChangePropertyCommand command = new ChangePropertyCommand(Arrays.asList(testData.existingNode), "a", "b"); 61 assertEquals("b", command.getTags().get("a")); 62 assertEquals(1, command.getTags().size()); 63 assertEquals(1, command.getObjectsNumber()); 64 65 command = new ChangePropertyCommand(testData.existingNode, "a", "b"); 66 assertEquals("b", command.getTags().get("a")); 67 assertEquals(1, command.getTags().size()); 68 assertEquals(1, command.getObjectsNumber()); 69 } 70 71 /** 72 * Checks that {@link ChangePropertyCommand} adds/updates a property 73 */ 74 @Test 75 public void testUpdateSingleProperty() { 76 Node node1 = testData.createNode(14); 77 Node node2 = testData.createNode(15); 78 node2.removeAll(); 79 80 TagMap tags = new TagMap(); 81 tags.put("existing", "new"); 82 new ChangePropertyCommand(Arrays.<OsmPrimitive>asList(node1, node2), tags).executeCommand(); 83 assertEquals("new", node1.get("existing")); 84 assertEquals("new", node2.get("existing")); 85 86 assertTrue(node1.isModified()); 87 assertTrue(node2.isModified()); 88 } 89 90 /** 91 * Checks that {@link ChangePropertyCommand} removes a property 92 */ 93 @Test 94 public void testRemoveProperty() { 95 Node node1 = testData.createNode(14); 96 Node node2 = testData.createNode(15); 97 node2.removeAll(); 98 99 HashMap<String, String> tags = new HashMap<>(); 100 tags.put("existing", ""); 101 new ChangePropertyCommand(Arrays.<OsmPrimitive>asList(node1, node2), tags).executeCommand(); 102 assertNull(node1.get("existing")); 103 assertNull(node2.get("existing")); 104 105 assertTrue(node1.isModified()); 106 assertFalse(node2.isModified()); 107 } 108 109 /** 110 * Checks that {@link ChangePropertyCommand} adds/updates multiple properties 111 */ 112 @Test 113 public void testUpdateMultipleProperties() { 114 Node node1 = testData.createNode(14); 115 Node node2 = testData.createNode(15); 116 node2.removeAll(); 117 node2.put("test", "xx"); 118 node2.put("remove", "xx"); 119 120 HashMap<String, String> tags = new HashMap<>(); 121 tags.put("existing", "existing"); 122 tags.put("test", "test"); 123 tags.put("remove", ""); 124 new ChangePropertyCommand(Arrays.<OsmPrimitive>asList(node1, node2), tags).executeCommand(); 125 assertEquals("existing", node1.get("existing")); 126 assertEquals("existing", node2.get("existing")); 127 assertEquals("test", node1.get("test")); 128 assertEquals("test", node2.get("test")); 129 assertNull(node1.get("remove")); 130 assertNull(node2.get("remove")); 131 132 assertTrue(node1.isModified()); 133 assertTrue(node2.isModified()); 134 } 135 136 /** 137 * Checks that {@link ChangePropertyCommand} adds/updates a property 138 */ 139 @Test 140 public void testUpdateIgnoresExistingProperty() { 141 Node node1 = testData.createNode(14); 142 Node node2 = testData.createNode(15); 143 node2.removeAll(); 144 145 TagMap tags = new TagMap(); 146 tags.put("existing", "existing"); 147 new ChangePropertyCommand(Arrays.<OsmPrimitive>asList(node1, node2), tags).executeCommand(); 148 assertEquals("existing", node1.get("existing")); 149 assertEquals("existing", node2.get("existing")); 150 151 assertFalse(node1.isModified()); 152 assertTrue(node2.isModified()); 153 } 154 155 /** 156 * Tests {@link ChangePropertyCommand#fillModifiedData(java.util.Collection, java.util.Collection, java.util.Collection)} 157 * and {@link ChangePropertyCommand#getObjectsNumber()} 158 */ 159 @Test 160 public void testFillModifiedData() { 161 Node node1 = testData.createNode(14); 162 Node node2 = testData.createNode(15); 163 node2.put("existing", "new"); 164 165 TagMap tags = new TagMap(); 166 tags.put("existing", "new"); 167 168 ArrayList<OsmPrimitive> modified = new ArrayList<>(); 169 ArrayList<OsmPrimitive> deleted = new ArrayList<>(); 170 ArrayList<OsmPrimitive> added = new ArrayList<>(); 171 new ChangePropertyCommand(Arrays.asList(node1, node2), tags).fillModifiedData(modified, deleted, added); 172 assertArrayEquals(new Object[] {node1}, modified.toArray()); 173 assertArrayEquals(new Object[] {}, deleted.toArray()); 174 assertArrayEquals(new Object[] {}, added.toArray()); 175 176 assertEquals(1, new ChangePropertyCommand(Arrays.asList(node1, node2), tags).getObjectsNumber()); 177 178 tags.clear(); 179 assertEquals(0, new ChangePropertyCommand(Arrays.asList(node1, node2), tags).getObjectsNumber()); 180 181 tags.put("a", "b"); 182 assertEquals(2, new ChangePropertyCommand(Arrays.asList(node1, node2), tags).getObjectsNumber()); 183 } 184 185 /** 186 * Test {@link ChangePropertyCommand#getDescriptionText()} 187 */ 188 @Test 189 public void testDescription() { 190 Node node1 = testData.createNode(14); 191 Node node2 = testData.createNode(15); 192 Node node3 = testData.createNode(16); 193 node1.put("name", "xy"); 194 node2.put("existing", "new"); 195 node3.put("existing", null); 196 197 TagMap tags = new TagMap(); 198 tags.put("existing", "new"); 199 200 HashMap<String, String> tagsRemove = new HashMap<>(); 201 tagsRemove.put("existing", ""); 202 203 Way way = new Way(); 204 way.addNode(node1); 205 way.put("name", "xy"); 206 way.put("existing", "existing"); 207 Relation relation = new Relation(); 208 relation.put("name", "xy"); 209 relation.put("existing", "existing"); 210 211 // nop 212 assertTrue(new ChangePropertyCommand(Arrays.asList(node2), tags).getDescriptionText() 213 .matches("Set.*tags for 0 objects")); 214 215 // change 1 key on 1 element. 216 assertTrue(new ChangePropertyCommand(Arrays.asList(node1, node2), tags).getDescriptionText() 217 .matches("Set existing=new for node.*xy.*")); 218 assertTrue(new ChangePropertyCommand(Arrays.asList(way, node2), tags).getDescriptionText() 219 .matches("Set existing=new for way.*xy.*")); 220 assertTrue(new ChangePropertyCommand(Arrays.asList(relation, node2), tags).getDescriptionText() 221 .matches("Set existing=new for relation.*xy.*")); 222 223 // remove 1 key on 1 element 224 assertTrue(new ChangePropertyCommand(Arrays.asList(node1, node3), tagsRemove).getDescriptionText() 225 .matches("Remove \"existing\" for node.*xy.*")); 226 assertTrue(new ChangePropertyCommand(Arrays.asList(way, node3), tagsRemove).getDescriptionText() 227 .matches("Remove \"existing\" for way.*xy.*")); 228 assertTrue(new ChangePropertyCommand(Arrays.asList(relation, node3), tagsRemove).getDescriptionText() 229 .matches("Remove \"existing\" for relation.*xy.*")); 230 231 // change 1 key on 3 elements 232 assertEquals("Set existing=new for 3 objects", 233 new ChangePropertyCommand(Arrays.asList(node1, node2, way, relation), tags).getDescriptionText()); 234 // remove 1 key on 3 elements 235 assertEquals("Remove \"existing\" for 3 objects", 236 new ChangePropertyCommand(Arrays.asList(node1, node3, way, relation), tagsRemove).getDescriptionText()); 237 238 // add 2 keys on 3 elements 239 tags.put("name", "a"); 240 node2.put("name", "a"); 241 assertEquals("Set 2 tags for 3 objects", 242 new ChangePropertyCommand(Arrays.asList(node1, node2, way, relation), tags).getDescriptionText()); 243 244 tagsRemove.put("name", ""); 245 // remove 2 key on 3 elements 246 assertEquals("Deleted 2 tags for 3 objects", 247 new ChangePropertyCommand(Arrays.asList(node1, node3, way, relation), tagsRemove).getDescriptionText()); 248 } 249 250 /** 251 * Test {@link ChangePropertyCommand#getChildren()} 252 */ 253 @Test 254 public void testChildren() { 255 Node node1 = testData.createNode(15); 256 Node node2 = testData.createNode(16); 257 node1.put("name", "node1"); 258 node2.put("name", "node2"); 259 260 assertNull(new ChangePropertyCommand(Arrays.asList(node1), "a", "b").getChildren()); 261 262 Collection<PseudoCommand> children = new ChangePropertyCommand(Arrays.asList(node1, node2), "a", "b").getChildren(); 263 assertEquals(2, children.size()); 264 List<Node> nodesToExpect = new ArrayList<>(Arrays.asList(node1, node2)); 265 for (PseudoCommand c : children) { 266 assertNull(c.getChildren()); 267 Collection<? extends OsmPrimitive> part = c.getParticipatingPrimitives(); 268 assertEquals(1, part.size()); 269 OsmPrimitive node = part.iterator().next(); 270 assertTrue(nodesToExpect.remove(node)); 271 272 assertTrue(c.getDescriptionText().matches(".*" + node.get("name") + ".*")); 273 } 25 274 } 26 275 -
trunk/test/unit/org/openstreetmap/josm/command/ChangePropertyKeyCommandTest.java
r9943 r10663 2 2 package org.openstreetmap.josm.command; 3 3 4 import org.junit.BeforeClass; 4 import static org.junit.Assert.assertEquals; 5 import static org.junit.Assert.assertFalse; 6 import static org.junit.Assert.assertNull; 7 import static org.junit.Assert.assertTrue; 8 9 import java.util.ArrayList; 10 import java.util.Arrays; 11 import java.util.Collection; 12 13 import org.junit.Before; 14 import org.junit.Rule; 5 15 import org.junit.Test; 6 import org.openstreetmap.josm. JOSMFixture;16 import org.openstreetmap.josm.command.CommandTest.CommandTestData; 7 17 import org.openstreetmap.josm.data.osm.DataSet; 18 import org.openstreetmap.josm.data.osm.Node; 19 import org.openstreetmap.josm.data.osm.OsmPrimitive; 8 20 import org.openstreetmap.josm.data.osm.User; 9 21 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 22 import org.openstreetmap.josm.testutils.JOSMTestRules; 10 23 24 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 11 25 import nl.jqno.equalsverifier.EqualsVerifier; 12 26 import nl.jqno.equalsverifier.Warning; … … 18 32 19 33 /** 20 * Setup test.34 * We need prefs for nodes. 21 35 */ 22 @BeforeClass 23 public static void setUpBeforeClass() { 24 JOSMFixture.createUnitTestFixture().init(false); 36 @Rule 37 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 38 public JOSMTestRules test = new JOSMTestRules().preferences().i18n(); 39 private CommandTestData testData; 40 41 /** 42 * Set up the test data. 43 */ 44 @Before 45 public void createTestData() { 46 testData = new CommandTestData(); 47 } 48 49 /** 50 * Tests that a key is changed. 51 */ 52 @Test 53 public void testChangeKeySingle() { 54 assertTrue(new ChangePropertyKeyCommand(testData.existingNode, "existing", "newKey").executeCommand()); 55 56 assertNull(testData.existingNode.get("existing")); 57 assertEquals("existing", testData.existingNode.get("newKey")); 58 assertTrue(testData.existingNode.isModified()); 59 } 60 61 /** 62 * Tests that a key is changed. 63 */ 64 @Test 65 public void testChangeKey() { 66 assertTrue(new ChangePropertyKeyCommand(Arrays.asList(testData.existingNode, testData.existingWay), "existing", 67 "newKey").executeCommand()); 68 69 assertNull(testData.existingNode.get("existing")); 70 assertEquals("existing", testData.existingNode.get("newKey")); 71 assertTrue(testData.existingNode.isModified()); 72 assertNull(testData.existingWay.get("existing")); 73 assertEquals("existing", testData.existingWay.get("newKey")); 74 assertTrue(testData.existingWay.isModified()); 75 } 76 77 /** 78 * Tests that nop operations are ignored. 79 */ 80 @Test 81 public void testChangeKeyIgnored() { 82 Node node1 = testData.createNode(15); 83 node1.removeAll(); 84 Node node2 = testData.createNode(16); 85 Node node3 = testData.createNode(17); 86 87 assertTrue(new ChangePropertyKeyCommand(Arrays.asList(node1, node2), "nonexisting", "newKey").executeCommand()); 88 89 assertFalse(node1.isModified()); 90 assertFalse(node2.isModified()); 91 92 assertTrue(new ChangePropertyKeyCommand(Arrays.asList(node1, node2), "existing", "newKey").executeCommand()); 93 94 assertFalse(node1.isModified()); 95 assertTrue(node2.isModified()); 96 97 // removes existing 98 assertTrue(new ChangePropertyKeyCommand(Arrays.asList(node1, node3), "newKey", "existing").executeCommand()); 99 100 assertFalse(node1.isModified()); 101 assertTrue(node3.isModified()); 102 assertNull(node3.get("newKey")); 103 assertNull(node3.get("existing")); 104 } 105 106 /** 107 * Test {@link ChangePropertyKeyCommand#getDescriptionText()} 108 */ 109 @Test 110 public void testDescription() { 111 Node node1 = testData.createNode(15); 112 node1.put("name", "xy"); 113 114 assertTrue(new ChangePropertyKeyCommand(node1, "a", "b").getDescriptionText() 115 .matches("Replace \"a\" by \"b\" for.*xy.*")); 116 assertTrue(new ChangePropertyKeyCommand(Arrays.asList(node1, testData.existingNode), "a", "b") 117 .getDescriptionText().matches("Replace \"a\" by \"b\" for 2 objects")); 118 } 119 120 /** 121 * Test {@link ChangePropertyCommand#getChildren()} 122 */ 123 @Test 124 public void testChildren() { 125 Node node1 = testData.createNode(15); 126 Node node2 = testData.createNode(16); 127 node1.put("name", "node1"); 128 node2.put("name", "node2"); 129 130 ArrayList<Node> nodesToExpect = new ArrayList<>(Arrays.asList(node1, node2)); 131 132 assertNull(new ChangePropertyKeyCommand(node1, "a", "b").getChildren()); 133 Collection<PseudoCommand> children = new ChangePropertyKeyCommand(Arrays.asList(node1, node2), "a", "b").getChildren(); 134 assertEquals(2, children.size()); 135 for (PseudoCommand c : children) { 136 assertNull(c.getChildren()); 137 Collection<? extends OsmPrimitive> part = c.getParticipatingPrimitives(); 138 assertEquals(1, part.size()); 139 OsmPrimitive node = part.iterator().next(); 140 assertTrue(nodesToExpect.remove(node)); 141 142 assertTrue(c.getDescriptionText().contains(node.getName())); 143 } 25 144 } 26 145 -
trunk/test/unit/org/openstreetmap/josm/command/ChangeRelationMemberRoleCommandTest.java
r9943 r10663 2 2 package org.openstreetmap.josm.command; 3 3 4 import org.junit.BeforeClass; 4 import static org.junit.Assert.assertArrayEquals; 5 import static org.junit.Assert.assertEquals; 6 import static org.junit.Assert.assertFalse; 7 import static org.junit.Assert.assertNull; 8 import static org.junit.Assert.assertTrue; 9 10 import java.util.ArrayList; 11 12 import org.junit.Before; 13 import org.junit.Rule; 5 14 import org.junit.Test; 6 import org.openstreetmap.josm. JOSMFixture;15 import org.openstreetmap.josm.command.CommandTest.CommandTestDataWithRelation; 7 16 import org.openstreetmap.josm.data.osm.DataSet; 17 import org.openstreetmap.josm.data.osm.OsmPrimitive; 8 18 import org.openstreetmap.josm.data.osm.Relation; 9 19 import org.openstreetmap.josm.data.osm.User; 10 20 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 21 import org.openstreetmap.josm.testutils.JOSMTestRules; 11 22 23 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 12 24 import nl.jqno.equalsverifier.EqualsVerifier; 13 25 import nl.jqno.equalsverifier.Warning; … … 19 31 20 32 /** 21 * Setup test.33 * We need prefs for nodes. 22 34 */ 23 @BeforeClass 24 public static void setUpBeforeClass() { 25 JOSMFixture.createUnitTestFixture().init(false); 35 @Rule 36 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 37 public JOSMTestRules test = new JOSMTestRules().preferences().i18n(); 38 private CommandTestDataWithRelation testData; 39 40 /** 41 * Set up the test data. 42 */ 43 @Before 44 public void createTestData() { 45 testData = new CommandTestDataWithRelation(); 46 } 47 48 /** 49 * Test if {@link ChangeRelationMemberRoleCommand} changes the role by index 50 */ 51 @Test 52 public void testRoleChanged() { 53 assertTrue(new ChangeRelationMemberRoleCommand(testData.existingRelation, 0, "newRole").executeCommand()); 54 assertEquals("newRole", testData.existingRelation.getMember(0).getRole()); 55 assertEquals(testData.existingNode, testData.existingRelation.getMember(0).getMember()); 56 assertEquals("way", testData.existingRelation.getMember(1).getRole()); 57 58 assertTrue(testData.existingRelation.isModified()); 59 60 assertTrue(new ChangeRelationMemberRoleCommand(testData.existingRelation, 1, "newRole").executeCommand()); 61 assertEquals("newRole", testData.existingRelation.getMember(1).getRole()); 62 } 63 64 /** 65 * Wrong index should be ignored. 66 */ 67 @Test 68 public void testWrongIndex() { 69 // should be ignored 70 ChangeRelationMemberRoleCommand command1 = new ChangeRelationMemberRoleCommand(testData.existingRelation, -1, "newRole"); 71 assertTrue(command1.executeCommand()); 72 ChangeRelationMemberRoleCommand command2 = new ChangeRelationMemberRoleCommand(testData.existingRelation, 8, "newRole"); 73 assertTrue(command2.executeCommand()); 74 assertFalse(testData.existingRelation.isModified()); 75 76 command1.undoCommand(); 77 command2.undoCommand(); 78 assertFalse(testData.existingRelation.isModified()); 79 } 80 81 82 /** 83 * Same role should be ignored. 84 */ 85 @Test 86 public void testSameRole() { 87 // should be ignored 88 assertTrue(new ChangeRelationMemberRoleCommand(testData.existingRelation, 0, "node").executeCommand()); 89 assertFalse(testData.existingRelation.isModified()); 90 } 91 92 /** 93 * Test {@link ChangeRelationMemberRoleCommand#undoCommand()}. 94 */ 95 @Test 96 public void testUndo() { 97 ChangeRelationMemberRoleCommand command = new ChangeRelationMemberRoleCommand(testData.existingRelation, 0, "newRole"); 98 command.executeCommand(); 99 assertEquals("newRole", testData.existingRelation.getMember(0).getRole()); 100 assertTrue(testData.existingRelation.isModified()); 101 102 command.undoCommand(); 103 assertEquals("node", testData.existingRelation.getMember(0).getRole()); 104 assertFalse(testData.existingRelation.isModified()); 105 106 command.executeCommand(); 107 assertEquals("newRole", testData.existingRelation.getMember(0).getRole()); 108 assertTrue(testData.existingRelation.isModified()); 109 } 110 111 /** 112 * Tests {@link ChangeCommand#fillModifiedData(java.util.Collection, java.util.Collection, java.util.Collection)} 113 */ 114 @Test 115 public void testFillModifiedData() { 116 ArrayList<OsmPrimitive> modified = new ArrayList<>(); 117 ArrayList<OsmPrimitive> deleted = new ArrayList<>(); 118 ArrayList<OsmPrimitive> added = new ArrayList<>(); 119 new ChangeRelationMemberRoleCommand(testData.existingRelation, 0, "newRole").fillModifiedData(modified, deleted, added); 120 assertArrayEquals(new Object[] {testData.existingRelation}, modified.toArray()); 121 assertArrayEquals(new Object[] {}, deleted.toArray()); 122 assertArrayEquals(new Object[] {}, added.toArray()); 123 } 124 125 /** 126 * Test {@link ChangeRelationMemberRoleCommand#getDescriptionText()} 127 */ 128 @Test 129 public void testDescription() { 130 testData.existingRelation.put("name", "xy"); 131 assertTrue(new ChangeRelationMemberRoleCommand(testData.existingRelation, 0, "newRole").getDescriptionText() 132 .matches("Change relation member role for relation.*xy.*")); 133 } 134 135 /** 136 * Test {@link ChangeRelationMemberRoleCommand#getChildren()} 137 */ 138 @Test 139 public void testChildren() { 140 assertNull(new ChangeRelationMemberRoleCommand(testData.existingRelation, 0, "newRole").getChildren()); 26 141 } 27 142 -
trunk/test/unit/org/openstreetmap/josm/command/CommandTest.java
r9943 r10663 2 2 package org.openstreetmap.josm.command; 3 3 4 import org.junit.BeforeClass; 4 import static org.junit.Assert.assertFalse; 5 import static org.junit.Assert.assertSame; 6 import static org.junit.Assert.assertTrue; 7 8 import java.util.Arrays; 9 import java.util.Collection; 10 11 import org.junit.Before; 12 import org.junit.Rule; 5 13 import org.junit.Test; 6 import org.openstreetmap.josm.JOSMFixture; 14 import org.openstreetmap.josm.Main; 15 import org.openstreetmap.josm.data.coor.LatLon; 7 16 import org.openstreetmap.josm.data.osm.DataSet; 17 import org.openstreetmap.josm.data.osm.Node; 18 import org.openstreetmap.josm.data.osm.OsmPrimitive; 19 import org.openstreetmap.josm.data.osm.Relation; 20 import org.openstreetmap.josm.data.osm.RelationMember; 8 21 import org.openstreetmap.josm.data.osm.User; 22 import org.openstreetmap.josm.data.osm.Way; 9 23 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 10 24 import org.openstreetmap.josm.testutils.JOSMTestRules; 25 26 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 11 27 import nl.jqno.equalsverifier.EqualsVerifier; 12 28 import nl.jqno.equalsverifier.Warning; … … 18 34 19 35 /** 20 * Setup test. 21 */ 22 @BeforeClass 23 public static void setUpBeforeClass() { 24 JOSMFixture.createUnitTestFixture().init(false); 36 * We need prefs for nodes / data sets. 37 */ 38 @Rule 39 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 40 public JOSMTestRules test = new JOSMTestRules().preferences().i18n(); 41 private CommandTestData testData; 42 43 /** 44 * Set up the test data. 45 */ 46 @Before 47 public void createTestData() { 48 testData = new CommandTestData(); 49 } 50 51 /** 52 * Test {@link Command#invalidBecauselayerRemoved(org.openstreetmap.josm.gui.layer.Layer)} 53 */ 54 @Test 55 public void testInvalidBecauselayerRemoved() { 56 OsmDataLayer layer2 = new OsmDataLayer(new DataSet(), "test", null); 57 58 Command command = new NopCommand(); 59 assertFalse(command.invalidBecauselayerRemoved(layer2)); 60 assertTrue(command.invalidBecauselayerRemoved(testData.layer)); 61 62 Command command2 = new NopCommand(layer2); 63 assertTrue(command2.invalidBecauselayerRemoved(layer2)); 64 assertFalse(command2.invalidBecauselayerRemoved(testData.layer)); 65 } 66 67 /** 68 * Test {@link Command#getLayer()} 69 */ 70 @Test 71 public void testGetLayer() { 72 OsmDataLayer layer2 = new OsmDataLayer(new DataSet(), "test", null); 73 Command command = new NopCommand(); 74 Command command2 = new NopCommand(layer2); 75 assertSame(testData.layer, command.getLayer()); 76 assertSame(layer2, command2.getLayer()); 25 77 } 26 78 … … 40 92 .verify(); 41 93 } 94 95 private static final class NopCommand extends Command { 96 NopCommand() { 97 super(); 98 } 99 100 NopCommand(OsmDataLayer layer) { 101 super(layer); 102 } 103 104 @Override 105 public String getDescriptionText() { 106 return ""; 107 } 108 109 @Override 110 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, 111 Collection<OsmPrimitive> added) { 112 // nop 113 } 114 } 115 116 /** 117 * A change test data consisting of two nodes and a way. 118 * @author Michael Zangl 119 */ 120 public static class CommandTestData { 121 /** 122 * A test layer 123 */ 124 public final OsmDataLayer layer; 125 /** 126 * A test node 127 */ 128 public final Node existingNode; 129 /** 130 * A second test node 131 */ 132 public final Node existingNode2; 133 /** 134 * A test way 135 */ 136 public final Way existingWay; 137 138 /** 139 * Creates the new test data and adds {@link #layer} to the layer manager. 140 */ 141 public CommandTestData() { 142 layer = new OsmDataLayer(new DataSet(), "layer", null); 143 Main.getLayerManager().addLayer(layer); 144 145 existingNode = createNode(5); 146 existingNode2 = createNode(6); 147 148 existingWay = createWay(10, existingNode, existingNode2); 149 } 150 151 /** 152 * Create and add a new test node. 153 * @param id the id 154 * @return The node. 155 */ 156 public Node createNode(long id) { 157 Node node = new Node(); 158 node.setOsmId(id, 1); 159 node.setCoor(LatLon.ZERO); 160 node.put("existing", "existing"); 161 layer.data.addPrimitive(node); 162 return node; 163 } 164 165 /** 166 * Create and add a new test way. 167 * @param id the id 168 * @param nodes The nodes 169 * @return The way. 170 */ 171 public Way createWay(int id, Node...nodes) { 172 Way way = new Way(); 173 way.setOsmId(id, 1); 174 way.setNodes(Arrays.asList(nodes)); 175 way.put("existing", "existing"); 176 layer.data.addPrimitive(way); 177 return way; 178 } 179 180 /** 181 * Create and add a new test relation. 182 * @param id the id 183 * @param members The members 184 * @return The relation. 185 */ 186 public Relation createRelation(int id, RelationMember...members) { 187 Relation relation = new Relation(id, 1); 188 for (RelationMember member : members) { 189 relation.addMember(member); 190 } 191 relation.put("existing", "existing"); 192 layer.data.addPrimitive(relation); 193 return relation; 194 } 195 } 196 197 /** 198 * A change test data consisting of two nodes, a way and a relation. 199 * @author Michael Zangl 200 */ 201 public static class CommandTestDataWithRelation extends CommandTestData { 202 /** 203 * A test relation 204 */ 205 public final Relation existingRelation; 206 207 /** 208 * Creates the new test data and adds {@link #layer} to the layer manager. 209 */ 210 public CommandTestDataWithRelation() { 211 existingRelation = createRelation(20, new RelationMember("node", existingNode), new RelationMember("way", existingWay)); 212 } 213 } 42 214 } -
trunk/test/unit/org/openstreetmap/josm/command/DeleteCommandTest.java
r9943 r10663 2 2 package org.openstreetmap.josm.command; 3 3 4 import org.junit.BeforeClass; 4 import static org.junit.Assert.assertArrayEquals; 5 import static org.junit.Assert.assertEquals; 6 import static org.junit.Assert.assertFalse; 7 import static org.junit.Assert.assertTrue; 8 9 import java.util.ArrayList; 10 import java.util.Arrays; 11 import java.util.Collection; 12 import java.util.List; 13 14 import org.junit.Before; 15 import org.junit.Rule; 5 16 import org.junit.Test; 6 import org.openstreetmap.josm. JOSMFixture;17 import org.openstreetmap.josm.command.CommandTest.CommandTestDataWithRelation; 7 18 import org.openstreetmap.josm.data.osm.DataSet; 19 import org.openstreetmap.josm.data.osm.Node; 20 import org.openstreetmap.josm.data.osm.OsmPrimitive; 21 import org.openstreetmap.josm.data.osm.Relation; 8 22 import org.openstreetmap.josm.data.osm.User; 23 import org.openstreetmap.josm.data.osm.Way; 24 import org.openstreetmap.josm.data.osm.WaySegment; 9 25 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 10 26 import org.openstreetmap.josm.testutils.JOSMTestRules; 27 28 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 11 29 import nl.jqno.equalsverifier.EqualsVerifier; 12 30 import nl.jqno.equalsverifier.Warning; … … 18 36 19 37 /** 20 * Setup test. 21 */ 22 @BeforeClass 23 public static void setUpBeforeClass() { 24 JOSMFixture.createUnitTestFixture().init(false); 38 * We need prefs for nodes. 39 */ 40 @Rule 41 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 42 public JOSMTestRules test = new JOSMTestRules().preferences().i18n(); 43 private CommandTestDataWithRelation testData; 44 45 /** 46 * Set up the test data. 47 */ 48 @Before 49 public void createTestData() { 50 testData = new CommandTestDataWithRelation(); 51 } 52 53 /** 54 * A simple deletion test with no references 55 */ 56 @Test 57 public void testSimpleDelete() { 58 Node node = testData.createNode(15); 59 assertTrue(testData.layer.data.allPrimitives().contains(node)); 60 61 new DeleteCommand(node).executeCommand(); 62 63 assertTrue(node.isDeleted()); 64 assertTrue(node.isModified()); 65 assertFalse(testData.layer.data.allNonDeletedPrimitives().contains(node)); 66 } 67 68 /** 69 * A delete should not delete refered objects but should should remove the reference. 70 */ 71 @Test 72 public void testDeleteIgnoresReferences() { 73 assertTrue(testData.existingNode.getReferrers().contains(testData.existingRelation)); 74 new DeleteCommand(testData.existingRelation).executeCommand(); 75 76 assertTrue(testData.existingRelation.isDeleted()); 77 assertEquals(0, testData.existingRelation.getMembersCount()); 78 assertFalse(testData.existingNode.isDeleted()); 79 assertFalse(testData.existingWay.isDeleted()); 80 assertFalse(testData.existingNode.getReferrers().contains(testData.existingRelation)); 81 82 // same for the way 83 assertTrue(testData.existingNode.getReferrers().contains(testData.existingWay)); 84 new DeleteCommand(testData.existingWay).executeCommand(); 85 assertEquals(0, testData.existingWay.getNodesCount()); 86 assertFalse(testData.existingNode.getReferrers().contains(testData.existingWay)); 87 } 88 89 /** 90 * A delete should delete all objects with references to the deleted one 91 */ 92 @Test(expected = IllegalArgumentException.class) 93 public void testDeleteFailsOnDelted() { 94 new DeleteCommand(testData.existingRelation).executeCommand(); 95 96 new DeleteCommand(testData.existingRelation).executeCommand(); 97 } 98 99 /** 100 * A delete should delete all objects with references to the deleted one 101 */ 102 @Test 103 public void testReferedDelete() { 104 DeleteCommand.deleteWithReferences(testData.layer, Arrays.asList(testData.existingNode), true).executeCommand(); 105 106 assertTrue(testData.existingNode.isDeleted()); 107 assertEquals(0, testData.existingWay.getNodesCount()); 108 assertTrue(testData.existingWay.isDeleted()); 109 } 110 111 /** 112 * Delete nodes that would be without reference afterwards. 113 */ 114 @Test 115 public void testDelteNodesInWay() { 116 testData.existingNode.removeAll(); 117 // That untagged node should be deleted. 118 testData.existingNode2.removeAll(); 119 DeleteCommand.delete(testData.layer, Arrays.asList(testData.existingWay), true, true).executeCommand(); 120 121 assertTrue(testData.existingWay.isDeleted()); 122 assertTrue(testData.existingNode2.isDeleted()); 123 assertFalse(testData.existingNode.isDeleted()); 124 assertFalse(testData.existingRelation.isDeleted()); 125 126 // Same test, now with tagged nodes 127 Node node1 = testData.createNode(15); 128 Node node2 = testData.createNode(16); 129 Node node3 = testData.createNode(17); 130 Node node4 = testData.createNode(18); 131 node2.removeAll(); 132 node4.removeAll(); 133 Way way1 = new Way(25, 1); 134 way1.setNodes(Arrays.asList(node1, node2, node3)); 135 testData.layer.data.addPrimitive(way1); 136 Way way2 = new Way(26, 1); 137 way2.setNodes(Arrays.asList(node2, node3, node4)); 138 testData.layer.data.addPrimitive(way2); 139 DeleteCommand.delete(testData.layer, Arrays.asList(way1, way2), true, true).executeCommand(); 140 141 assertTrue(way1.isDeleted()); 142 assertTrue(way2.isDeleted()); 143 assertFalse(node1.isDeleted()); 144 assertTrue(node2.isDeleted()); 145 assertFalse(node3.isDeleted()); 146 assertTrue(node4.isDeleted()); 147 } 148 149 /** 150 * Test that {@link DeleteCommand} checks for non-null. 151 */ 152 @Test(expected = IllegalArgumentException.class) 153 public void testConsistency() { 154 new DeleteCommand(Arrays.asList(testData.existingNode, testData.existingWay, null)); 155 } 156 157 /** 158 * Test that {@link DeleteCommand} checks for the dataset 159 */ 160 @Test(expected = IllegalArgumentException.class) 161 public void testConsistencyDataset() { 162 testData.layer.data.removePrimitive(testData.existingNode); 163 new DeleteCommand(Arrays.asList(testData.existingNode, testData.existingWay)); 164 } 165 166 /** 167 * Test that {@link DeleteCommand} checks for non-empty list 168 */ 169 @Test(expected = IllegalArgumentException.class) 170 public void testConsistencyNonEmpty() { 171 new DeleteCommand(Arrays.<OsmPrimitive>asList()); 172 } 173 174 /** 175 * Test that {@link DeleteCommand} checks for non-null list 176 */ 177 @Test(expected = IllegalArgumentException.class) 178 public void testConsistencyNonNull() { 179 new DeleteCommand((Collection<OsmPrimitive>) null); 180 } 181 182 /** 183 * Test {@link DeleteCommand#undoCommand()} 184 */ 185 @Test 186 public void testUndo() { 187 DeleteCommand command = new DeleteCommand( 188 Arrays.asList(testData.existingNode, testData.existingNode2, testData.existingWay)); 189 command.executeCommand(); 190 191 assertTrue(testData.existingNode.isDeleted()); 192 assertTrue(testData.existingWay.isDeleted()); 193 194 command.undoCommand(); 195 196 assertFalse(testData.existingNode.isDeleted()); 197 assertFalse(testData.existingWay.isDeleted()); 198 assertEquals("existing", testData.existingNode.get("existing")); 199 200 command.executeCommand(); 201 202 assertTrue(testData.existingNode.isDeleted()); 203 assertTrue(testData.existingWay.isDeleted()); 204 } 205 206 /** 207 * Test {@link DeleteCommand#deleteWaySegment(OsmDataLayer, org.openstreetmap.josm.data.osm.WaySegment)} 208 * Way with only 1 segment 209 */ 210 @Test 211 public void testDeleteWaySegment() { 212 Way way1 = testData.createWay(100, testData.createNode(101), testData.createNode(102)); 213 WaySegment ws = new WaySegment(way1, 0); 214 Command command = DeleteCommand.deleteWaySegment(testData.layer, ws); 215 command.executeCommand(); 216 217 assertTrue(way1.isDeleted()); 218 } 219 220 /** 221 * Test {@link DeleteCommand#deleteWaySegment(OsmDataLayer, org.openstreetmap.josm.data.osm.WaySegment)} 222 * Delete end of way 223 */ 224 @Test 225 public void testDeleteWaySegmentEndOfWay() { 226 Way way = testData.createWay(200, testData.createNode(201), testData.createNode(202), testData.createNode(203), 227 testData.createNode(204)); 228 WaySegment ws = new WaySegment(way, 2); 229 Command command = DeleteCommand.deleteWaySegment(testData.layer, ws); 230 command.executeCommand(); 231 232 assertEquals(3, way.getNodesCount()); 233 assertEquals(201, way.getNodeId(0)); 234 assertEquals(202, way.getNodeId(1)); 235 assertEquals(203, way.getNodeId(2)); 236 } 237 238 /** 239 * Test {@link DeleteCommand#deleteWaySegment(OsmDataLayer, org.openstreetmap.josm.data.osm.WaySegment)} 240 * Delete start of way 241 */ 242 @Test 243 public void testDeleteWaySegmentStartOfWay() { 244 Way way = testData.createWay(100, testData.createNode(101), testData.createNode(102), testData.createNode(103), 245 testData.createNode(104)); 246 WaySegment ws = new WaySegment(way, 0); 247 Command command = DeleteCommand.deleteWaySegment(testData.layer, ws); 248 command.executeCommand(); 249 250 assertEquals(3, way.getNodesCount()); 251 assertEquals(102, way.getNodeId(0)); 252 assertEquals(103, way.getNodeId(1)); 253 assertEquals(104, way.getNodeId(2)); 254 } 255 256 /** 257 * Test {@link DeleteCommand#deleteWaySegment(OsmDataLayer, org.openstreetmap.josm.data.osm.WaySegment)} 258 * Delete start of way 259 */ 260 @Test 261 public void testDeleteWaySegmentSplit() { 262 Node node103 = testData.createNode(103); 263 Node node104 = testData.createNode(104); 264 Way way = testData.createWay(100, testData.createNode(101), testData.createNode(102), node103, node104); 265 WaySegment ws = new WaySegment(way, 1); 266 Command command = DeleteCommand.deleteWaySegment(testData.layer, ws); 267 command.executeCommand(); 268 269 assertEquals(2, way.getNodesCount()); 270 assertEquals(101, way.getNodeId(0)); 271 assertEquals(102, way.getNodeId(1)); 272 // there needs to be a new way 273 assertEquals(1, node104.getReferrers().size()); 274 Way newWay = (Way) node104.getReferrers().get(0); 275 assertEquals(2, newWay.getNodesCount()); 276 assertEquals(103, newWay.getNodeId(0)); 277 assertEquals(104, newWay.getNodeId(1)); 278 } 279 280 /** 281 * Test {@link DeleteCommand#deleteWaySegment(OsmDataLayer, org.openstreetmap.josm.data.osm.WaySegment)} 282 * Delete start of way 283 */ 284 @Test 285 public void testDeleteWaySegmentCycle() { 286 Node n = testData.createNode(101); 287 Way way = testData.createWay(100, n, testData.createNode(102), testData.createNode(103), 288 testData.createNode(104), n); 289 WaySegment ws = new WaySegment(way, 2); 290 Command command = DeleteCommand.deleteWaySegment(testData.layer, ws); 291 command.executeCommand(); 292 293 assertEquals(4, way.getNodesCount()); 294 assertEquals(104, way.getNodeId(0)); 295 assertEquals(101, way.getNodeId(1)); 296 assertEquals(102, way.getNodeId(2)); 297 assertEquals(103, way.getNodeId(3)); 298 } 299 300 /** 301 * Tests {@link DeleteCommand#getChildren()} 302 */ 303 @Test 304 public void testGetChildren() { 305 testData.existingNode.put("name", "xy"); 306 Collection<PseudoCommand> children = new DeleteCommand(Arrays.<OsmPrimitive>asList(testData.existingNode, testData.existingNode2)) 307 .getChildren(); 308 assertEquals(2, children.size()); 309 assertTrue(children.stream().allMatch(c -> c.getParticipatingPrimitives().size() == 1)); 310 assertTrue(children.stream().anyMatch(c -> c.getParticipatingPrimitives().iterator().next() == testData.existingNode)); 311 assertTrue(children.stream().anyMatch(c -> c.getParticipatingPrimitives().iterator().next() == testData.existingNode2)); 312 assertTrue(children.stream().anyMatch(c -> c.getDescriptionText().matches("Deleted '.*xy.*'"))); 313 } 314 315 /** 316 * Tests {@link DeleteCommand#fillModifiedData(java.util.Collection, java.util.Collection, java.util.Collection)} 317 */ 318 @Test 319 public void testFillModifiedData() { 320 ArrayList<OsmPrimitive> modified = new ArrayList<>(); 321 ArrayList<OsmPrimitive> deleted = new ArrayList<>(); 322 ArrayList<OsmPrimitive> added = new ArrayList<>(); 323 new DeleteCommand(Arrays.<OsmPrimitive>asList(testData.existingNode)).fillModifiedData(modified, deleted, added); 324 // intentionally left empty. 325 assertArrayEquals(new Object[] {}, modified.toArray()); 326 assertArrayEquals(new Object[] {}, deleted.toArray()); 327 assertArrayEquals(new Object[] {}, added.toArray()); 328 } 329 330 /** 331 * Tests {@link DeleteCommand#getParticipatingPrimitives()} 332 */ 333 @Test 334 public void testGetParticipatingPrimitives() { 335 DeleteCommand command = new DeleteCommand(Arrays.<OsmPrimitive>asList(testData.existingNode)); 336 assertArrayEquals(new Object[] {testData.existingNode }, command.getParticipatingPrimitives().toArray()); 337 338 DeleteCommand command2 = new DeleteCommand( 339 Arrays.<OsmPrimitive>asList(testData.existingNode, testData.existingWay)); 340 assertArrayEquals(new Object[] {testData.existingNode, testData.existingWay}, 341 command2.getParticipatingPrimitives().toArray()); 342 } 343 344 /** 345 * Test {@link DeleteCommand#getDescriptionText()} 346 */ 347 @Test 348 public void testDescription() { 349 Node node = testData.createNode(100); 350 node.put("name", "xy"); 351 Way way = testData.createWay(101); 352 way.put("name", "xy"); 353 Relation relation = testData.createRelation(102); 354 relation.put("name", "xy"); 355 356 List<OsmPrimitive> nodeList = Arrays.<OsmPrimitive>asList(node); 357 assertTrue(new DeleteCommand(nodeList).getDescriptionText().matches("Delete node .*xy.*")); 358 List<OsmPrimitive> wayList = Arrays.<OsmPrimitive>asList(way); 359 assertTrue(new DeleteCommand(wayList).getDescriptionText().matches("Delete way .*xy.*")); 360 List<OsmPrimitive> relationList = Arrays.<OsmPrimitive>asList(relation); 361 assertTrue(new DeleteCommand(relationList).getDescriptionText().matches("Delete relation .*xy.*")); 362 363 List<OsmPrimitive> nodesList = Arrays.<OsmPrimitive>asList(node, testData.createNode(110)); 364 assertTrue(new DeleteCommand(nodesList).getDescriptionText().matches("Delete 2 nodes")); 365 List<OsmPrimitive> waysList = Arrays.<OsmPrimitive>asList(way, testData.createWay(111)); 366 assertTrue(new DeleteCommand(waysList).getDescriptionText().matches("Delete 2 ways")); 367 List<OsmPrimitive> relationsList = Arrays.<OsmPrimitive>asList(relation, testData.createRelation(112)); 368 assertTrue(new DeleteCommand(relationsList).getDescriptionText().matches("Delete 2 relations")); 369 370 List<OsmPrimitive> mixed = Arrays.<OsmPrimitive>asList(node, way, relation); 371 assertTrue(new DeleteCommand(mixed).getDescriptionText().matches("Delete 3 objects")); 25 372 } 26 373 -
trunk/test/unit/org/openstreetmap/josm/command/MoveCommandTest.java
r9943 r10663 2 2 package org.openstreetmap.josm.command; 3 3 4 import org.junit.BeforeClass; 4 import static org.junit.Assert.assertArrayEquals; 5 import static org.junit.Assert.assertEquals; 6 import static org.junit.Assert.assertTrue; 7 8 import java.util.ArrayList; 9 import java.util.Arrays; 10 import java.util.Collections; 11 import java.util.List; 12 import java.util.Set; 13 14 import org.junit.Before; 15 import org.junit.Rule; 5 16 import org.junit.Test; 6 import org.openstreetmap.josm.JOSMFixture; 17 import org.openstreetmap.josm.Main; 18 import org.openstreetmap.josm.command.CommandTest.CommandTestDataWithRelation; 19 import org.openstreetmap.josm.data.coor.EastNorth; 7 20 import org.openstreetmap.josm.data.coor.LatLon; 8 21 import org.openstreetmap.josm.data.osm.DataSet; 22 import org.openstreetmap.josm.data.osm.Node; 23 import org.openstreetmap.josm.data.osm.OsmPrimitive; 9 24 import org.openstreetmap.josm.data.osm.User; 10 25 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 11 26 import org.openstreetmap.josm.testutils.JOSMTestRules; 27 28 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 12 29 import nl.jqno.equalsverifier.EqualsVerifier; 13 30 import nl.jqno.equalsverifier.Warning; … … 17 34 */ 18 35 public class MoveCommandTest { 19 20 /** 21 * Setup test. 22 */ 23 @BeforeClass 24 public static void setUpBeforeClass() { 25 JOSMFixture.createUnitTestFixture().init(false); 36 /** 37 * We need prefs for nodes. 38 */ 39 @Rule 40 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 41 public JOSMTestRules test = new JOSMTestRules().preferences().i18n().projection(); 42 private CommandTestDataWithRelation testData; 43 44 /** 45 * Set up the test data. 46 */ 47 @Before 48 public void createTestData() { 49 testData = new CommandTestDataWithRelation(); 50 } 51 52 /** 53 * Test the various constructors. 54 */ 55 @Test 56 public void testConstructors() { 57 EastNorth offset = new EastNorth(1, 2); 58 LatLon destLatLon = Main.getProjection().eastNorth2latlon(offset); 59 EastNorth start = new EastNorth(2, 0); 60 61 Set<OsmPrimitive> nodeAsCollection = Collections.<OsmPrimitive>singleton(testData.existingNode); 62 assertEquals(1, nodeAsCollection.size()); 63 checkCommandAfterConstructor(new MoveCommand(nodeAsCollection, offset)); 64 checkCommandAfterConstructor(new MoveCommand(testData.existingNode, destLatLon)); 65 checkCommandAfterConstructor(new MoveCommand(nodeAsCollection, 1, 2)); 66 checkCommandAfterConstructor(new MoveCommand(nodeAsCollection, start, start.add(offset))); 67 checkCommandAfterConstructor(new MoveCommand(testData.existingNode, 1, 2)); 68 checkCommandAfterConstructor(new MoveCommand(testData.existingNode, start, start.add(offset))); 69 } 70 71 private void checkCommandAfterConstructor(MoveCommand moveCommand) { 72 ArrayList<OsmPrimitive> nodes = new ArrayList<>(); 73 moveCommand.fillModifiedData(nodes, null, null); 74 assertEquals(nodes, new ArrayList<>(Collections.<OsmPrimitive>singleton(testData.existingNode))); 75 76 assertEquals("east", 1, moveCommand.getOffset().east(), 0.0001); 77 assertEquals("north", 2, moveCommand.getOffset().north(), 0.0001); 78 } 79 80 /** 81 * Test {@link MoveCommand#executeCommand()} for simple nodes. 82 */ 83 @Test 84 public void testSingleMove() { 85 MoveCommand command = new MoveCommand(testData.existingNode, 1, 2); 86 testData.existingNode.setEastNorth(new EastNorth(3, 7)); 87 command.executeCommand(); 88 assertEquals("east", 4, testData.existingNode.getEastNorth().east(), 0.0001); 89 assertEquals("north", 9, testData.existingNode.getEastNorth().north(), 0.0001); 90 } 91 92 /** 93 * Test {@link MoveCommand#executeCommand()} for multiple nodes. 94 */ 95 @Test 96 public void testMultipleMove() { 97 MoveCommand command = new MoveCommand( 98 Arrays.asList(testData.existingNode, testData.existingNode2, testData.existingWay), 99 new EastNorth(1, 2)); 100 101 testData.existingNode.setEastNorth(new EastNorth(3, 7)); 102 testData.existingNode2.setEastNorth(new EastNorth(4, 7)); 103 command.executeCommand(); 104 105 assertEquals("east", 4, testData.existingNode.getEastNorth().east(), 0.0001); 106 assertEquals("north", 9, testData.existingNode.getEastNorth().north(), 0.0001); 107 assertEquals("east", 5, testData.existingNode2.getEastNorth().east(), 0.0001); 108 assertEquals("north", 9, testData.existingNode2.getEastNorth().north(), 0.0001); 109 } 110 111 /** 112 * Test {@link MoveCommand#moveAgain(double, double)} and {@link MoveCommand#moveAgainTo(double, double)}. 113 */ 114 @Test 115 public void testMoveAgain() { 116 MoveCommand command = new MoveCommand(testData.existingNode, 1, 2); 117 assertEquals("east", 1, command.getOffset().east(), 0.0001); 118 assertEquals("north", 2, command.getOffset().north(), 0.0001); 119 120 command.moveAgain(1, 2); 121 assertEquals("east", 2, command.getOffset().east(), 0.0001); 122 assertEquals("north", 4, command.getOffset().north(), 0.0001); 123 124 command.moveAgain(-9, -3); 125 assertEquals("east", -7, command.getOffset().east(), 0.0001); 126 assertEquals("north", 1, command.getOffset().north(), 0.0001); 127 128 command.moveAgainTo(1, 2); 129 assertEquals("east", 1, command.getOffset().east(), 0.0001); 130 assertEquals("north", 2, command.getOffset().north(), 0.0001); 131 } 132 133 /** 134 * Test {@link MoveCommand#saveCheckpoint()} and {@link MoveCommand#resetToCheckpoint()} 135 */ 136 @Test 137 public void testCheckpoint() { 138 MoveCommand command = new MoveCommand(testData.existingNode, 2, 4); 139 assertEquals("east", 2, command.getOffset().east(), 0.0001); 140 assertEquals("north", 4, command.getOffset().north(), 0.0001); 141 142 command.saveCheckpoint(); 143 command.moveAgain(3, 7); 144 assertEquals("east", 5, command.getOffset().east(), 0.0001); 145 assertEquals("north", 11, command.getOffset().north(), 0.0001); 146 147 command.resetToCheckpoint(); 148 assertEquals("east", 2, command.getOffset().east(), 0.0001); 149 assertEquals("north", 4, command.getOffset().north(), 0.0001); 150 } 151 152 /** 153 * Test the start point mechanism. 154 */ 155 @Test 156 public void testStartPoint() { 157 EastNorth start = new EastNorth(10, 20); 158 MoveCommand command = new MoveCommand(testData.existingNode, start, start.add(1, 2)); 159 assertEquals("east", 1, command.getOffset().east(), 0.0001); 160 assertEquals("north", 2, command.getOffset().north(), 0.0001); 161 162 command.applyVectorTo(start.add(3, 4)); 163 assertEquals("east", 3, command.getOffset().east(), 0.0001); 164 assertEquals("north", 4, command.getOffset().north(), 0.0001); 165 166 // set to 100, 200 167 command.changeStartPoint(new EastNorth(103, 204)); 168 command.applyVectorTo(new EastNorth(101, 202)); 169 assertEquals("east", 1, command.getOffset().east(), 0.0001); 170 assertEquals("north", 2, command.getOffset().north(), 0.0001); 171 } 172 173 /** 174 * Test the start point mechanism ignored. 175 */ 176 @Test 177 public void testNoStartPoint() { 178 MoveCommand command = new MoveCommand(testData.existingNode, 1, 0); 179 // ignored 180 command.applyVectorTo(new EastNorth(3, 4)); 181 assertEquals("east", 1, command.getOffset().east(), 0.0001); 182 assertEquals("north", 0, command.getOffset().north(), 0.0001); 183 184 // set to 100, 200 185 command.changeStartPoint(new EastNorth(101, 200)); 186 // works 187 command.applyVectorTo(new EastNorth(101, 202)); 188 assertEquals("east", 1, command.getOffset().east(), 0.0001); 189 assertEquals("north", 2, command.getOffset().north(), 0.0001); 190 } 191 192 /** 193 * Test {@link MoveCommand#undoCommand()} 194 */ 195 @Test 196 public void testUndo() { 197 testData.existingNode.setEastNorth(new EastNorth(3, 7)); 198 MoveCommand command = new MoveCommand(testData.existingNode, 1, 2); 199 command.executeCommand(); 200 assertEquals("east", 4, testData.existingNode.getEastNorth().east(), 0.0001); 201 assertEquals("north", 9, testData.existingNode.getEastNorth().north(), 0.0001); 202 203 command.undoCommand(); 204 assertEquals("east", 3, testData.existingNode.getEastNorth().east(), 0.0001); 205 assertEquals("north", 7, testData.existingNode.getEastNorth().north(), 0.0001); 206 207 command.executeCommand(); 208 assertEquals("east", 4, testData.existingNode.getEastNorth().east(), 0.0001); 209 assertEquals("north", 9, testData.existingNode.getEastNorth().north(), 0.0001); 210 } 211 212 /** 213 * Tests {@link MoveCommand#fillModifiedData(java.util.Collection, java.util.Collection, java.util.Collection)} 214 */ 215 @Test 216 public void testFillModifiedData() { 217 ArrayList<OsmPrimitive> modified = new ArrayList<>(); 218 ArrayList<OsmPrimitive> deleted = new ArrayList<>(); 219 ArrayList<OsmPrimitive> added = new ArrayList<>(); 220 new MoveCommand(Arrays.<OsmPrimitive>asList(testData.existingNode), 1, 2).fillModifiedData(modified, 221 deleted, added); 222 assertArrayEquals(new Object[] {testData.existingNode }, modified.toArray()); 223 assertArrayEquals(new Object[] {}, deleted.toArray()); 224 assertArrayEquals(new Object[] {}, added.toArray()); 225 } 226 227 /** 228 * Tests {@link MoveCommand#getParticipatingPrimitives()} 229 */ 230 @Test 231 public void testGetParticipatingPrimitives() { 232 MoveCommand command = new MoveCommand(Arrays.<OsmPrimitive>asList(testData.existingNode), 1, 2); 233 command.executeCommand(); 234 assertArrayEquals(new Object[] {testData.existingNode}, command.getParticipatingPrimitives().toArray()); 235 236 MoveCommand command2 = new MoveCommand( 237 Arrays.<OsmPrimitive>asList(testData.existingNode, testData.existingWay), 1, 2); 238 command2.executeCommand(); 239 assertArrayEquals(new Object[] {testData.existingNode, testData.existingNode2}, 240 command2.getParticipatingPrimitives().toArray()); 241 } 242 243 /** 244 * Test {@link MoveCommand#getDescriptionText()} 245 */ 246 @Test 247 public void testDescription() { 248 Node node = new Node(LatLon.ZERO); 249 node.put("name", "xy"); 250 251 List<OsmPrimitive> nodeList = Arrays.<OsmPrimitive>asList(node); 252 assertTrue(new MoveCommand(nodeList, 1, 2).getDescriptionText().matches("Move 1 node")); 253 List<OsmPrimitive> nodes = Arrays.<OsmPrimitive>asList(node, testData.existingNode, testData.existingNode2); 254 assertTrue(new MoveCommand(nodes, 1, 2).getDescriptionText().matches("Move 3 nodes")); 26 255 } 27 256 -
trunk/test/unit/org/openstreetmap/josm/command/PurgeCommandTest.java
r9943 r10663 2 2 package org.openstreetmap.josm.command; 3 3 4 import org.junit.BeforeClass; 4 import static org.junit.Assert.assertArrayEquals; 5 import static org.junit.Assert.assertFalse; 6 import static org.junit.Assert.assertNotNull; 7 import static org.junit.Assert.assertNull; 8 import static org.junit.Assert.assertSame; 9 import static org.junit.Assert.assertTrue; 10 11 import java.util.ArrayList; 12 import java.util.Arrays; 13 import java.util.List; 14 15 import org.junit.Before; 16 import org.junit.Rule; 5 17 import org.junit.Test; 6 import org.openstreetmap.josm. JOSMFixture;18 import org.openstreetmap.josm.command.CommandTest.CommandTestDataWithRelation; 7 19 import org.openstreetmap.josm.data.conflict.Conflict; 8 20 import org.openstreetmap.josm.data.osm.DataSet; … … 10 22 import org.openstreetmap.josm.data.osm.Node; 11 23 import org.openstreetmap.josm.data.osm.OsmPrimitive; 24 import org.openstreetmap.josm.data.osm.Relation; 25 import org.openstreetmap.josm.data.osm.RelationMember; 12 26 import org.openstreetmap.josm.data.osm.Storage; 13 27 import org.openstreetmap.josm.data.osm.User; 14 28 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 29 import org.openstreetmap.josm.testutils.JOSMTestRules; 15 30 31 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 16 32 import nl.jqno.equalsverifier.EqualsVerifier; 17 33 import nl.jqno.equalsverifier.Warning; … … 21 37 */ 22 38 public class PurgeCommandTest { 39 /** 40 * We need prefs for nodes. 41 */ 42 @Rule 43 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 44 public JOSMTestRules test = new JOSMTestRules().preferences(); 45 private CommandTestDataWithRelation testData; 23 46 24 47 /** 25 * Set up test.48 * Set up the test data. 26 49 */ 27 @BeforeClass 28 public static void setUpBeforeClass() { 29 JOSMFixture.createUnitTestFixture().init(false); 50 @Before 51 public void createTestData() { 52 testData = new CommandTestDataWithRelation(); 53 } 54 55 /** 56 * Test {@link PurgeCommand#executeCommand()} 57 */ 58 @Test 59 public void testExecute() { 60 Relation relationParent = testData.createRelation(100, new RelationMember("child", testData.existingRelation)); 61 Relation relationParent2 = testData.createRelation(101, new RelationMember("child", testData.existingRelation)); 62 // to check that algorithm ignores it: 63 Relation relationParent3 = testData.createRelation(102, new RelationMember("child", testData.existingRelation)); 64 PurgeCommand command = new PurgeCommand(testData.layer, 65 Arrays.<OsmPrimitive>asList(testData.existingNode, testData.existingNode2, testData.existingWay, 66 testData.existingRelation, relationParent, relationParent2), 67 Arrays.<OsmPrimitive>asList(testData.existingNode2, testData.existingWay, testData.existingRelation)); 68 command.executeCommand(); 69 assertTrue(testData.existingNode2.isIncomplete()); 70 assertTrue(testData.existingWay.isIncomplete()); 71 assertTrue(testData.existingRelation.isIncomplete()); 72 assertNull(relationParent.getDataSet()); 73 assertNull(relationParent2.getDataSet()); 74 assertNotNull(relationParent3.getDataSet()); 75 assertFalse(relationParent3.isIncomplete()); 76 assertNull(testData.existingNode.getDataSet()); 77 assertFalse(testData.existingNode.isIncomplete()); 78 } 79 80 /** 81 * Test {@link PurgeCommand#undoCommand()} 82 */ 83 @Test 84 public void testUndo() { 85 PurgeCommand command = new PurgeCommand(testData.layer, 86 Arrays.<OsmPrimitive>asList(testData.existingNode, testData.existingWay), 87 Arrays.<OsmPrimitive>asList(testData.existingWay)); 88 command.executeCommand(); 89 assertTrue(testData.existingWay.isIncomplete()); 90 assertNull(testData.existingNode.getDataSet()); 91 92 command.undoCommand(); 93 assertFalse(testData.existingWay.isIncomplete()); 94 assertSame(testData.layer.data, testData.existingNode.getDataSet()); 95 96 command.executeCommand(); 97 assertTrue(testData.existingWay.isIncomplete()); 98 assertNull(testData.existingNode.getDataSet()); 99 } 100 101 /** 102 * Tests {@link PurgeCommand#fillModifiedData(java.util.Collection, java.util.Collection, java.util.Collection)} 103 */ 104 @Test 105 public void testFillModifiedData() { 106 ArrayList<OsmPrimitive> modified = new ArrayList<>(); 107 ArrayList<OsmPrimitive> deleted = new ArrayList<>(); 108 ArrayList<OsmPrimitive> added = new ArrayList<>(); 109 PurgeCommand command = new PurgeCommand(testData.layer, Arrays.<OsmPrimitive>asList(testData.existingNode), 110 Arrays.<OsmPrimitive>asList(testData.existingRelation)); 111 command.fillModifiedData(modified, deleted, added); 112 // intentianally empty (?) 113 assertArrayEquals(new Object[] {}, modified.toArray()); 114 assertArrayEquals(new Object[] {}, deleted.toArray()); 115 assertArrayEquals(new Object[] {}, added.toArray()); 116 } 117 118 /** 119 * Tests {@link PurgeCommand#getParticipatingPrimitives()} 120 */ 121 @Test 122 public void testGetParticipatingPrimitives() { 123 PurgeCommand command = new PurgeCommand(testData.layer, Arrays.<OsmPrimitive>asList(testData.existingNode), 124 Arrays.<OsmPrimitive>asList(testData.existingRelation)); 125 assertArrayEquals(new Object[] {testData.existingNode }, command.getParticipatingPrimitives().toArray()); 126 } 127 128 /** 129 * Test {@link PurgeCommand#getDescriptionText()} 130 */ 131 @Test 132 public void testDescription() { 133 List<OsmPrimitive> shortList = Arrays.<OsmPrimitive>asList(testData.existingWay); 134 assertTrue(new PurgeCommand(testData.layer, shortList, Arrays.<OsmPrimitive>asList()).getDescriptionText() 135 .matches("Purged 1 object")); 136 List<OsmPrimitive> longList = Arrays.<OsmPrimitive>asList(testData.existingNode, testData.existingNode2, 137 testData.existingWay); 138 assertTrue(new PurgeCommand(testData.layer, longList, Arrays.<OsmPrimitive>asList()).getDescriptionText() 139 .matches("Purged 3 objects")); 30 140 } 31 141 -
trunk/test/unit/org/openstreetmap/josm/command/RemoveNodesCommandTest.java
r9943 r10663 2 2 package org.openstreetmap.josm.command; 3 3 4 import org.junit.BeforeClass; 4 import static org.junit.Assert.assertArrayEquals; 5 import static org.junit.Assert.assertFalse; 6 import static org.junit.Assert.assertTrue; 7 8 import java.util.ArrayList; 9 import java.util.Collections; 10 11 import org.junit.Before; 12 import org.junit.Rule; 5 13 import org.junit.Test; 6 import org.openstreetmap.josm. JOSMFixture;14 import org.openstreetmap.josm.command.CommandTest.CommandTestDataWithRelation; 7 15 import org.openstreetmap.josm.data.osm.DataSet; 16 import org.openstreetmap.josm.data.osm.OsmPrimitive; 8 17 import org.openstreetmap.josm.data.osm.User; 9 18 import org.openstreetmap.josm.data.osm.Way; 10 19 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 20 import org.openstreetmap.josm.testutils.JOSMTestRules; 11 21 22 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 12 23 import nl.jqno.equalsverifier.EqualsVerifier; 13 24 import nl.jqno.equalsverifier.Warning; … … 19 30 20 31 /** 21 * Setup test.32 * We need prefs for nodes. 22 33 */ 23 @BeforeClass 24 public static void setUpBeforeClass() { 25 JOSMFixture.createUnitTestFixture().init(false); 34 @Rule 35 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 36 public JOSMTestRules test = new JOSMTestRules().preferences(); 37 private CommandTestDataWithRelation testData; 38 39 /** 40 * Set up the test data. 41 */ 42 @Before 43 public void createTestData() { 44 testData = new CommandTestDataWithRelation(); 45 } 46 47 /** 48 * Test {@link RemoveNodesCommand#executeCommand()} 49 */ 50 @Test 51 public void testExecute() { 52 RemoveNodesCommand command = new RemoveNodesCommand(testData.existingWay, 53 Collections.singletonList(testData.existingNode)); 54 55 command.executeCommand(); 56 57 assertFalse(testData.existingWay.containsNode(testData.existingNode)); 58 assertTrue(testData.existingWay.containsNode(testData.existingNode2)); 59 assertTrue(testData.existingWay.isModified()); 60 } 61 62 /** 63 * Test {@link RemoveNodesCommand#undoCommand()} 64 */ 65 @Test 66 public void testUndo() { 67 RemoveNodesCommand command = new RemoveNodesCommand(testData.existingWay, 68 Collections.singletonList(testData.existingNode)); 69 70 command.executeCommand(); 71 72 command.undoCommand(); 73 assertTrue(testData.existingWay.containsNode(testData.existingNode)); 74 assertTrue(testData.existingWay.containsNode(testData.existingNode2)); 75 assertFalse(testData.existingWay.isModified()); 76 77 command.executeCommand(); 78 79 assertFalse(testData.existingWay.containsNode(testData.existingNode)); 80 assertTrue(testData.existingWay.containsNode(testData.existingNode2)); 81 assertTrue(testData.existingWay.isModified()); 82 } 83 84 /** 85 * Tests {@link RemoveNodesCommand#fillModifiedData(java.util.Collection, java.util.Collection, java.util.Collection)} 86 */ 87 @Test 88 public void testFillModifiedData() { 89 ArrayList<OsmPrimitive> modified = new ArrayList<>(); 90 ArrayList<OsmPrimitive> deleted = new ArrayList<>(); 91 ArrayList<OsmPrimitive> added = new ArrayList<>(); 92 RemoveNodesCommand command = new RemoveNodesCommand(testData.existingWay, 93 Collections.singletonList(testData.existingNode)); 94 command.fillModifiedData(modified, deleted, added); 95 assertArrayEquals(new Object[] {testData.existingWay }, modified.toArray()); 96 assertArrayEquals(new Object[] {}, deleted.toArray()); 97 assertArrayEquals(new Object[] {}, added.toArray()); 98 } 99 100 /** 101 * Tests {@link RemoveNodesCommand#getParticipatingPrimitives()} 102 */ 103 @Test 104 public void testGetParticipatingPrimitives() { 105 RemoveNodesCommand command = new RemoveNodesCommand(testData.existingWay, 106 Collections.singletonList(testData.existingNode)); 107 command.executeCommand(); 108 assertArrayEquals(new Object[] {testData.existingWay }, command.getParticipatingPrimitives().toArray()); 109 } 110 111 /** 112 * Test {@link RemoveNodesCommand#getDescriptionText()} 113 */ 114 @Test 115 public void testDescription() { 116 assertTrue(new RemoveNodesCommand(testData.existingWay, Collections.singletonList(testData.existingNode)) 117 .getDescriptionText().matches("Removed nodes from .*")); 26 118 } 27 119 -
trunk/test/unit/org/openstreetmap/josm/command/RotateCommandTest.java
r9943 r10663 2 2 package org.openstreetmap.josm.command; 3 3 4 import org.junit.BeforeClass; 4 import static org.junit.Assert.assertArrayEquals; 5 import static org.junit.Assert.assertEquals; 6 7 import java.util.ArrayList; 8 import java.util.Arrays; 9 10 import org.junit.Before; 11 import org.junit.Rule; 5 12 import org.junit.Test; 6 import org.openstreetmap.josm.JOSMFixture; 13 import org.openstreetmap.josm.command.CommandTest.CommandTestData; 14 import org.openstreetmap.josm.data.coor.EastNorth; 7 15 import org.openstreetmap.josm.data.coor.LatLon; 8 16 import org.openstreetmap.josm.data.osm.DataSet; 17 import org.openstreetmap.josm.data.osm.Node; 18 import org.openstreetmap.josm.data.osm.OsmPrimitive; 9 19 import org.openstreetmap.josm.data.osm.User; 10 20 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 21 import org.openstreetmap.josm.testutils.JOSMTestRules; 11 22 23 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 12 24 import nl.jqno.equalsverifier.EqualsVerifier; 13 25 import nl.jqno.equalsverifier.Warning; … … 19 31 20 32 /** 21 * Setup test.33 * We need prefs for nodes. 22 34 */ 23 @BeforeClass 24 public static void setUpBeforeClass() { 25 JOSMFixture.createUnitTestFixture().init(false); 35 @Rule 36 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 37 public JOSMTestRules test = new JOSMTestRules().preferences().projection(); 38 private CommandTestData testData; 39 40 /** 41 * Set up the test data. 42 */ 43 @Before 44 public void createTestData() { 45 testData = new CommandTestData(); 46 } 47 48 /** 49 * Test a simple 45° rotation. Tests {@link RotateCommand#executeCommand()} 50 */ 51 @Test 52 public void testRotate() { 53 // pivot needs to be at 0,0 54 Node n1 = new Node(new EastNorth(10, 10)); 55 Node n2 = new Node(new EastNorth(-1, 0)); 56 Node n3 = new Node(new EastNorth(-9, -10)); 57 RotateCommand rotate = new RotateCommand(Arrays.asList(n1, n2, n3), new EastNorth(0, 0)); 58 rotate.setRotationAngle(Math.PI / 4); 59 rotate.executeCommand(); 60 61 assertEquals(Math.sqrt(2) * 10, n1.getEastNorth().east(), 0.0001); 62 assertEquals(0, n1.getEastNorth().north(), 0.0001); 63 assertEquals(-1 / Math.sqrt(2), n2.getEastNorth().east(), 0.0001); 64 assertEquals(1 / Math.sqrt(2), n2.getEastNorth().north(), 0.0001); 65 } 66 67 /** 68 * Test {@link RotateCommand#undoCommand()} 69 */ 70 @Test 71 public void testUndo() { 72 Node n1 = new Node(new EastNorth(10, 10)); 73 Node n2 = new Node(new EastNorth(-1, 0)); 74 Node n3 = new Node(new EastNorth(-9, -10)); 75 RotateCommand rotate = new RotateCommand(Arrays.asList(n1, n2, n3), new EastNorth(0, 0)); 76 rotate.setRotationAngle(Math.PI / 4); 77 rotate.executeCommand(); 78 rotate.undoCommand(); 79 80 assertEquals(10, n1.getEastNorth().east(), 0.0001); 81 assertEquals(10, n1.getEastNorth().north(), 0.0001); 82 assertEquals(-1, n2.getEastNorth().east(), 0.0001); 83 assertEquals(0, n2.getEastNorth().north(), 0.0001); 84 85 rotate.executeCommand(); 86 87 assertEquals(-1 / Math.sqrt(2), n2.getEastNorth().east(), 0.0001); 88 assertEquals(1 / Math.sqrt(2), n2.getEastNorth().north(), 0.0001); 89 } 90 91 /** 92 * Tests {@link RotateCommand#fillModifiedData(java.util.Collection, java.util.Collection, java.util.Collection)} 93 */ 94 @Test 95 public void testFillModifiedData() { 96 ArrayList<OsmPrimitive> modified = new ArrayList<>(); 97 ArrayList<OsmPrimitive> deleted = new ArrayList<>(); 98 ArrayList<OsmPrimitive> added = new ArrayList<>(); 99 RotateCommand command = new RotateCommand(Arrays.asList(testData.existingNode), 100 new EastNorth(0, 0)); 101 // intentionally empty 102 command.fillModifiedData(modified, deleted, added); 103 assertArrayEquals(new Object[] {}, modified.toArray()); 104 assertArrayEquals(new Object[] {}, deleted.toArray()); 105 assertArrayEquals(new Object[] {}, added.toArray()); 106 } 107 108 /** 109 * Tests {@link RotateCommand#getParticipatingPrimitives()} 110 */ 111 @Test 112 public void testGetParticipatingPrimitives() { 113 RotateCommand command = new RotateCommand(Arrays.asList(testData.existingNode), new EastNorth(0, 0)); 114 command.executeCommand(); 115 assertArrayEquals(new Object[] {testData.existingNode}, command.getParticipatingPrimitives().toArray()); 116 } 117 118 /** 119 * Test {@link RotateCommand#getDescriptionText()} 120 */ 121 @Test 122 public void testDescription() { 123 assertEquals("Rotate 1 node", 124 new RotateCommand(Arrays.asList(testData.existingNode), new EastNorth(0, 0)) 125 .getDescriptionText()); 126 assertEquals("Rotate 2 nodes", 127 new RotateCommand(Arrays.asList(testData.existingNode, testData.existingNode2), new EastNorth(0, 0)) 128 .getDescriptionText()); 26 129 } 27 130 … … 32 135 public void equalsContract() { 33 136 EqualsVerifier.forClass(RotateCommand.class).usingGetClass() 34 .withPrefabValues(LatLon.class, 35 LatLon.ZERO, new LatLon(45, 45)) 36 .withPrefabValues(DataSet.class, 37 new DataSet(), new DataSet()) 38 .withPrefabValues(User.class, 39 User.createOsmUser(1, "foo"), User.createOsmUser(2, "bar")) 40 .withPrefabValues(OsmDataLayer.class, 41 new OsmDataLayer(new DataSet(), "1", null), new OsmDataLayer(new DataSet(), "2", null)) 42 .suppress(Warning.NONFINAL_FIELDS) 43 .verify(); 137 .withPrefabValues(LatLon.class, LatLon.ZERO, new LatLon(45, 45)) 138 .withPrefabValues(DataSet.class, new DataSet(), new DataSet()) 139 .withPrefabValues(User.class, User.createOsmUser(1, "foo"), User.createOsmUser(2, "bar")) 140 .withPrefabValues(OsmDataLayer.class, new OsmDataLayer(new DataSet(), "1", null), 141 new OsmDataLayer(new DataSet(), "2", null)) 142 .suppress(Warning.NONFINAL_FIELDS).verify(); 44 143 } 45 144 } -
trunk/test/unit/org/openstreetmap/josm/command/ScaleCommandTest.java
r9943 r10663 2 2 package org.openstreetmap.josm.command; 3 3 4 import org.junit.BeforeClass; 4 import static org.junit.Assert.assertArrayEquals; 5 import static org.junit.Assert.assertEquals; 6 7 import java.util.ArrayList; 8 import java.util.Arrays; 9 10 import org.junit.Before; 11 import org.junit.Rule; 5 12 import org.junit.Test; 6 import org.openstreetmap.josm.JOSMFixture; 13 import org.openstreetmap.josm.command.CommandTest.CommandTestData; 14 import org.openstreetmap.josm.data.coor.EastNorth; 7 15 import org.openstreetmap.josm.data.coor.LatLon; 8 16 import org.openstreetmap.josm.data.osm.DataSet; 17 import org.openstreetmap.josm.data.osm.Node; 18 import org.openstreetmap.josm.data.osm.OsmPrimitive; 9 19 import org.openstreetmap.josm.data.osm.User; 10 20 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 21 import org.openstreetmap.josm.testutils.JOSMTestRules; 11 22 23 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 12 24 import nl.jqno.equalsverifier.EqualsVerifier; 13 25 import nl.jqno.equalsverifier.Warning; … … 19 31 20 32 /** 21 * Setup test.33 * We need prefs for nodes. 22 34 */ 23 @BeforeClass 24 public static void setUpBeforeClass() { 25 JOSMFixture.createUnitTestFixture().init(false); 35 @Rule 36 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 37 public JOSMTestRules test = new JOSMTestRules().preferences().projection(); 38 private CommandTestData testData; 39 40 /** 41 * Set up the test data. 42 */ 43 @Before 44 public void createTestData() { 45 testData = new CommandTestData(); 46 } 47 48 /** 49 * Test a simple 2.5 scale. Tests {@link ScaleCommand#executeCommand()} 50 */ 51 @Test 52 public void testScale() { 53 // pivot needs to be at 0,0 54 Node n1 = new Node(new EastNorth(10, 10)); 55 Node n2 = new Node(new EastNorth(-1, 0)); 56 Node n3 = new Node(new EastNorth(-9, -10)); 57 ScaleCommand scale = new ScaleCommand(Arrays.asList(n1, n2, n3), new EastNorth(0, 0)); 58 scale.setScalingFactor(2.5); 59 scale.executeCommand(); 60 61 assertEquals(25, n1.getEastNorth().east(), 0.0001); 62 assertEquals(25, n1.getEastNorth().north(), 0.0001); 63 assertEquals(-2.5, n2.getEastNorth().east(), 0.0001); 64 assertEquals(0, n2.getEastNorth().north(), 0.0001); 65 } 66 67 /** 68 * Test {@link ScaleCommand#undoCommand()} 69 */ 70 @Test 71 public void testUndo() { 72 Node n1 = new Node(new EastNorth(10, 10)); 73 Node n2 = new Node(new EastNorth(-1, 0)); 74 Node n3 = new Node(new EastNorth(-9, -10)); 75 ScaleCommand scale = new ScaleCommand(Arrays.asList(n1, n2, n3), new EastNorth(0, 0)); 76 scale.setScalingFactor(2.5); 77 scale.executeCommand(); 78 scale.undoCommand(); 79 80 assertEquals(10, n1.getEastNorth().east(), 0.0001); 81 assertEquals(10, n1.getEastNorth().north(), 0.0001); 82 assertEquals(-1, n2.getEastNorth().east(), 0.0001); 83 assertEquals(0, n2.getEastNorth().north(), 0.0001); 84 85 scale.executeCommand(); 86 87 assertEquals(-2.5, n2.getEastNorth().east(), 0.0001); 88 assertEquals(0, n2.getEastNorth().north(), 0.0001); 89 } 90 91 /** 92 * Tests {@link ScaleCommand#fillModifiedData(java.util.Collection, java.util.Collection, java.util.Collection)} 93 */ 94 @Test 95 public void testFillModifiedData() { 96 ArrayList<OsmPrimitive> modified = new ArrayList<>(); 97 ArrayList<OsmPrimitive> deleted = new ArrayList<>(); 98 ArrayList<OsmPrimitive> added = new ArrayList<>(); 99 ScaleCommand command = new ScaleCommand(Arrays.asList(testData.existingNode), 100 new EastNorth(0, 0)); 101 // intentionally empty 102 command.fillModifiedData(modified, deleted, added); 103 assertArrayEquals(new Object[] {}, modified.toArray()); 104 assertArrayEquals(new Object[] {}, deleted.toArray()); 105 assertArrayEquals(new Object[] {}, added.toArray()); 106 } 107 108 /** 109 * Tests {@link ScaleCommand#getParticipatingPrimitives()} 110 */ 111 @Test 112 public void testGetParticipatingPrimitives() { 113 ScaleCommand command = new ScaleCommand(Arrays.asList(testData.existingNode), new EastNorth(0, 0)); 114 command.executeCommand(); 115 assertArrayEquals(new Object[] {testData.existingNode }, command.getParticipatingPrimitives().toArray()); 116 } 117 118 /** 119 * Test {@link ScaleCommand#getDescriptionText()} 120 */ 121 @Test 122 public void testDescription() { 123 assertEquals("Scale 1 node", 124 new ScaleCommand(Arrays.asList(testData.existingNode), new EastNorth(0, 0)) 125 .getDescriptionText()); 126 assertEquals("Scale 2 nodes", 127 new ScaleCommand(Arrays.asList(testData.existingNode, testData.existingNode2), new EastNorth(0, 0)) 128 .getDescriptionText()); 26 129 } 27 130 -
trunk/test/unit/org/openstreetmap/josm/command/SelectCommandTest.java
r9943 r10663 2 2 package org.openstreetmap.josm.command; 3 3 4 import org.junit.BeforeClass; 4 import static org.junit.Assert.assertArrayEquals; 5 import static org.junit.Assert.assertFalse; 6 import static org.junit.Assert.assertTrue; 7 8 import java.util.ArrayList; 9 import java.util.Arrays; 10 import java.util.List; 11 12 import org.junit.Before; 13 import org.junit.Rule; 5 14 import org.junit.Test; 6 import org.openstreetmap.josm. JOSMFixture;15 import org.openstreetmap.josm.command.CommandTest.CommandTestDataWithRelation; 7 16 import org.openstreetmap.josm.data.osm.DataSet; 17 import org.openstreetmap.josm.data.osm.OsmPrimitive; 8 18 import org.openstreetmap.josm.data.osm.User; 9 19 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 20 import org.openstreetmap.josm.testutils.JOSMTestRules; 10 21 22 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 11 23 import nl.jqno.equalsverifier.EqualsVerifier; 12 24 import nl.jqno.equalsverifier.Warning; … … 18 30 19 31 /** 20 * Setup test.32 * We need prefs for nodes. 21 33 */ 22 @BeforeClass 23 public static void setUpBeforeClass() { 24 JOSMFixture.createUnitTestFixture().init(false); 34 @Rule 35 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 36 public JOSMTestRules test = new JOSMTestRules().preferences(); 37 private CommandTestDataWithRelation testData; 38 39 /** 40 * Set up the test data. 41 */ 42 @Before 43 public void createTestData() { 44 testData = new CommandTestDataWithRelation(); 45 } 46 47 /** 48 * Test {@link SelectCommand#executeCommand()} 49 */ 50 @Test 51 public void testExecute() { 52 SelectCommand command = new SelectCommand(Arrays.asList(testData.existingNode, testData.existingWay)); 53 54 testData.layer.data.setSelected(Arrays.asList(testData.existingNode2)); 55 56 command.executeCommand(); 57 58 assertTrue(testData.existingNode.isSelected()); 59 assertFalse(testData.existingNode2.isSelected()); 60 assertTrue(testData.existingWay.isSelected()); 61 } 62 63 /** 64 * Test {@link SelectCommand#executeCommand()} 65 */ 66 @Test 67 public void testExecuteAfterModify() { 68 List<OsmPrimitive> list = new ArrayList<>(Arrays.asList(testData.existingNode, testData.existingWay)); 69 SelectCommand command = new SelectCommand(list); 70 71 list.remove(testData.existingNode); 72 list.add(testData.existingNode2); 73 74 command.executeCommand(); 75 76 assertTrue(testData.existingNode.isSelected()); 77 assertFalse(testData.existingNode2.isSelected()); 78 assertTrue(testData.existingWay.isSelected()); 79 } 80 81 /** 82 * Test {@link SelectCommand#undoCommand()} 83 */ 84 @Test 85 public void testUndo() { 86 SelectCommand command = new SelectCommand(Arrays.asList(testData.existingNode, testData.existingWay)); 87 testData.layer.data.setSelected(Arrays.asList(testData.existingNode2)); 88 89 command.executeCommand(); 90 91 command.undoCommand(); 92 93 assertFalse(testData.existingNode.isSelected()); 94 assertTrue(testData.existingNode2.isSelected()); 95 assertFalse(testData.existingWay.isSelected()); 96 97 command.executeCommand(); 98 99 assertTrue(testData.existingNode.isSelected()); 100 assertFalse(testData.existingNode2.isSelected()); 101 assertTrue(testData.existingWay.isSelected()); 102 } 103 104 /** 105 * Tests {@link SelectCommand#fillModifiedData(java.util.Collection, java.util.Collection, java.util.Collection)} 106 */ 107 @Test 108 public void testFillModifiedData() { 109 ArrayList<OsmPrimitive> modified = new ArrayList<>(); 110 ArrayList<OsmPrimitive> deleted = new ArrayList<>(); 111 ArrayList<OsmPrimitive> added = new ArrayList<>(); 112 SelectCommand command = new SelectCommand(Arrays.asList(testData.existingNode, testData.existingWay)); 113 command.fillModifiedData(modified, deleted, added); 114 // intentionally empty. 115 assertArrayEquals(new Object[] {}, modified.toArray()); 116 assertArrayEquals(new Object[] {}, deleted.toArray()); 117 assertArrayEquals(new Object[] {}, added.toArray()); 118 } 119 120 /** 121 * Tests {@link SelectCommand#getParticipatingPrimitives()} 122 */ 123 @Test 124 public void testGetParticipatingPrimitives() { 125 SelectCommand command = new SelectCommand(Arrays.asList(testData.existingNode, testData.existingWay)); 126 command.executeCommand(); 127 assertArrayEquals(new Object[] {}, command.getParticipatingPrimitives().toArray()); 128 } 129 130 /** 131 * Test {@link SelectCommand#getDescriptionText()} 132 */ 133 @Test 134 public void testDescription() { 135 assertTrue(new SelectCommand(Arrays.<OsmPrimitive>asList(testData.existingNode)) 136 .getDescriptionText().matches("Selected 1 object")); 137 assertTrue(new SelectCommand(Arrays.asList(testData.existingNode, testData.existingWay)) 138 .getDescriptionText().matches("Selected 2 objects")); 139 assertTrue(new SelectCommand(Arrays.<OsmPrimitive>asList()) 140 .getDescriptionText().matches("Selected 0 objects")); 141 assertTrue(new SelectCommand(null) 142 .getDescriptionText().matches("Selected 0 objects")); 25 143 } 26 144 -
trunk/test/unit/org/openstreetmap/josm/command/SequenceCommandTest.java
r9943 r10663 2 2 package org.openstreetmap.josm.command; 3 3 4 import org.junit.BeforeClass; 4 import static org.junit.Assert.assertArrayEquals; 5 import static org.junit.Assert.assertEquals; 6 import static org.junit.Assert.assertFalse; 7 import static org.junit.Assert.assertNull; 8 import static org.junit.Assert.assertTrue; 9 import static org.junit.Assert.fail; 10 11 import java.util.ArrayList; 12 import java.util.Arrays; 13 import java.util.Collection; 14 15 import org.junit.Before; 16 import org.junit.Rule; 5 17 import org.junit.Test; 6 import org.openstreetmap.josm. JOSMFixture;18 import org.openstreetmap.josm.command.CommandTest.CommandTestDataWithRelation; 7 19 import org.openstreetmap.josm.data.osm.DataSet; 8 20 import org.openstreetmap.josm.data.osm.Node; 21 import org.openstreetmap.josm.data.osm.OsmPrimitive; 9 22 import org.openstreetmap.josm.data.osm.User; 10 23 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 11 24 import org.openstreetmap.josm.testutils.JOSMTestRules; 25 26 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 12 27 import nl.jqno.equalsverifier.EqualsVerifier; 13 28 import nl.jqno.equalsverifier.Warning; … … 19 34 20 35 /** 21 * Setup test. 22 */ 23 @BeforeClass 24 public static void setUpBeforeClass() { 25 JOSMFixture.createUnitTestFixture().init(false); 36 * We need prefs for nodes. 37 */ 38 @Rule 39 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 40 public JOSMTestRules test = new JOSMTestRules().preferences(); 41 private CommandTestDataWithRelation testData; 42 43 /** 44 * Set up the test data. 45 */ 46 @Before 47 public void createTestData() { 48 testData = new CommandTestDataWithRelation(); 49 } 50 51 /** 52 * Test {@link SequenceCommand#executeCommand()} 53 */ 54 @Test 55 public void testExecute() { 56 final TestCommand command1 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode)); 57 TestCommand command2 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode2)) { 58 @Override 59 public boolean executeCommand() { 60 assertTrue(command1.executed); 61 return super.executeCommand(); 62 } 63 }; 64 SequenceCommand command = new SequenceCommand("seq", Arrays.<Command>asList(command1, command2)); 65 66 command.executeCommand(); 67 68 assertTrue(command1.executed); 69 assertTrue(command2.executed); 70 } 71 72 /** 73 * Test {@link SequenceCommand#undoCommand()} 74 */ 75 @Test 76 public void testUndo() { 77 final TestCommand command2 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode2)); 78 TestCommand command1 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode)) { 79 @Override 80 public void undoCommand() { 81 assertFalse(command2.executed); 82 super.undoCommand(); 83 } 84 }; 85 SequenceCommand command = new SequenceCommand("seq", Arrays.<Command>asList(command1, command2)); 86 87 command.executeCommand(); 88 89 command.undoCommand(); 90 91 assertFalse(command1.executed); 92 assertFalse(command2.executed); 93 94 command.executeCommand(); 95 96 assertTrue(command1.executed); 97 assertTrue(command2.executed); 98 } 99 100 /** 101 * Test {@link SequenceCommand#undoCommand()} 102 */ 103 @Test 104 public void testGetLastCommand() { 105 final TestCommand command1 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode)); 106 final TestCommand command2 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode2)); 107 108 assertEquals(command2, new SequenceCommand("seq", command1, command2).getLastCommand()); 109 assertNull(new SequenceCommand("seq").getLastCommand()); 110 } 111 112 /** 113 * Tests {@link SequenceCommand#fillModifiedData(java.util.Collection, java.util.Collection, java.util.Collection)} 114 */ 115 @Test 116 public void testFillModifiedData() { 117 Command command1 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode)); 118 Command command2 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode2)); 119 Command command3 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingWay)) { 120 @Override 121 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, 122 Collection<OsmPrimitive> added) { 123 deleted.addAll(primitives); 124 } 125 }; 126 Command command4 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingRelation)) { 127 @Override 128 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, 129 Collection<OsmPrimitive> added) { 130 added.addAll(primitives); 131 } 132 }; 133 134 ArrayList<OsmPrimitive> modified = new ArrayList<>(); 135 ArrayList<OsmPrimitive> deleted = new ArrayList<>(); 136 ArrayList<OsmPrimitive> added = new ArrayList<>(); 137 SequenceCommand command = new SequenceCommand("seq", command1, command2, command3, command4); 138 command.fillModifiedData(modified, deleted, added); 139 assertArrayEquals(new Object[] {testData.existingNode, testData.existingNode2}, modified.toArray()); 140 assertArrayEquals(new Object[] {testData.existingWay}, deleted.toArray()); 141 assertArrayEquals(new Object[] {testData.existingRelation}, added.toArray()); 142 } 143 144 /** 145 * Tests {@link SequenceCommand#getParticipatingPrimitives()} 146 */ 147 @Test 148 public void testGetParticipatingPrimitives() { 149 Command command1 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode)); 150 Command command2 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode2)); 151 152 SequenceCommand command = new SequenceCommand("seq", command1, command2); 153 command.executeCommand(); 154 Collection<? extends OsmPrimitive> primitives = command.getParticipatingPrimitives(); 155 assertEquals(2, primitives.size()); 156 assertTrue(primitives.contains(testData.existingNode)); 157 assertTrue(primitives.contains(testData.existingNode2)); 158 } 159 160 /** 161 * Test {@link SequenceCommand#getDescriptionText()} 162 */ 163 @Test 164 public void testDescription() { 165 assertTrue(new SequenceCommand("test").getDescriptionText().matches("Sequence: test")); 26 166 } 27 167 … … 43 183 .verify(); 44 184 } 185 186 private static class TestCommand extends Command { 187 protected final Collection<? extends OsmPrimitive> primitives; 188 protected boolean executed; 189 190 TestCommand(Collection<? extends OsmPrimitive> primitives) { 191 super(); 192 this.primitives = primitives; 193 } 194 195 @Override 196 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, 197 Collection<OsmPrimitive> added) { 198 modified.addAll(primitives); 199 } 200 201 @Override 202 public String getDescriptionText() { 203 fail("Should not be called"); 204 return ""; 205 } 206 207 @Override 208 public Collection<? extends OsmPrimitive> getParticipatingPrimitives() { 209 return primitives; 210 } 211 212 @Override 213 public boolean executeCommand() { 214 assertFalse("Cannot execute twice", executed); 215 executed = true; 216 return true; 217 } 218 219 @Override 220 public void undoCommand() { 221 assertTrue("Cannot undo without execute", executed); 222 executed = false; 223 } 224 225 @Override 226 public String toString() { 227 return "TestCommand [primitives=" + primitives + "]"; 228 } 229 230 } 45 231 }
Note:
See TracChangeset
for help on using the changeset viewer.