Changeset 12726 in josm for trunk/test/unit
- Timestamp:
- 2017-09-04T23:45:49+02:00 (7 years ago)
- Location:
- trunk/test/unit/org/openstreetmap/josm
- Files:
-
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/TestUtils.java
r12130 r12726 22 22 23 23 import org.openstreetmap.josm.command.Command; 24 import org.openstreetmap.josm.data.osm.DataSet; 24 25 import org.openstreetmap.josm.data.osm.Node; 25 26 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 257 258 /** 258 259 * Creates a new empty command. 260 * @param ds data set 259 261 * @return a new empty command 260 262 */ 261 public static Command newCommand( ) {262 return new Command( ) {263 public static Command newCommand(DataSet ds) { 264 return new Command(ds) { 263 265 @Override 264 266 public String getDescriptionText() { -
trunk/test/unit/org/openstreetmap/josm/actions/CreateMultipolygonActionTest.java
r12659 r12726 17 17 import org.openstreetmap.josm.data.osm.RelationMember; 18 18 import org.openstreetmap.josm.data.osm.Way; 19 import org.openstreetmap.josm.data.osm.search.SearchCompiler; 19 20 import org.openstreetmap.josm.data.osm.search.SearchParseError; 20 21 import org.openstreetmap.josm.data.osm.search.SearchSetting; 21 import org.openstreetmap.josm.data.osm.search.SearchCompiler;22 22 import org.openstreetmap.josm.io.OsmReader; 23 23 import org.openstreetmap.josm.testutils.JOSMTestRules; … … 42 42 Map<String, String> refToRole = new TreeMap<>(); 43 43 for (RelationMember i : relation.getMembers()) { 44 refToRole.put(i.getMember().get("ref"), i.getRole()); 44 String ref = i.getMember().get("ref"); 45 if (ref != null) { 46 refToRole.put(ref, i.getRole()); 47 } 45 48 } 46 49 return refToRole; -
trunk/test/unit/org/openstreetmap/josm/actions/SplitWayActionTest.java
r12643 r12726 162 162 void doTestRouteRelation(final boolean wayIsReversed, final int indexOfWayToKeep) { 163 163 final DataSet dataSet = new DataSet(); 164 final OsmDataLayer layer = new OsmDataLayer(dataSet, OsmDataLayer.createNewName(), null);165 164 final Node n1 = new Node(new LatLon(1, 0)); 166 165 final Node n2 = new Node(new LatLon(2, 0)); … … 197 196 }; 198 197 final SplitWayAction.SplitWayResult result = SplitWayAction.splitWay( 199 layer,w2, SplitWayAction.buildSplitChunks(w2, Arrays.asList(n3, n4, n5)), new ArrayList<OsmPrimitive>(), strategy);198 w2, SplitWayAction.buildSplitChunks(w2, Arrays.asList(n3, n4, n5)), new ArrayList<OsmPrimitive>(), strategy); 200 199 MainApplication.undoRedo.add(result.getCommand()); 201 200 -
trunk/test/unit/org/openstreetmap/josm/command/AddCommandTest.java
r12636 r12726 16 16 import org.openstreetmap.josm.data.osm.User; 17 17 import org.openstreetmap.josm.data.osm.Way; 18 import org.openstreetmap.josm.gui.MainApplication;19 18 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 20 19 import org.openstreetmap.josm.testutils.JOSMTestRules; … … 41 40 @Test 42 41 public void testAdd() { 43 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 44 MainApplication.getLayerManager().addLayer(layer1); 45 assertArrayEquals(new Object[0], layer1.data.allPrimitives().toArray()); 42 DataSet ds = new DataSet(); 43 assertArrayEquals(new Object[0], ds.allPrimitives().toArray()); 46 44 47 45 Node osm = new Node(LatLon.ZERO); 48 assertTrue(new AddCommand( osm).executeCommand());46 assertTrue(new AddCommand(ds, osm).executeCommand()); 49 47 50 assertArrayEquals(new Object[] {osm}, layer1.data.allPrimitives().toArray());51 assertArrayEquals(new Object[] {osm}, layer1.data.allModifiedPrimitives().toArray());48 assertArrayEquals(new Object[] {osm}, ds.allPrimitives().toArray()); 49 assertArrayEquals(new Object[] {osm}, ds.allModifiedPrimitives().toArray()); 52 50 assertTrue(osm.isModified()); 53 51 } 54 52 55 53 /** 56 * Tests if the add command respects the layer.54 * Tests if the add command respects the data set. 57 55 */ 58 56 @Test 59 57 public void testAddToLayer() { 60 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 61 OsmDataLayer layer2 = new OsmDataLayer(new DataSet(), "l1", null); 62 63 MainApplication.getLayerManager().addLayer(layer1); 64 MainApplication.getLayerManager().addLayer(layer2); 58 DataSet ds1 = new DataSet(); 59 DataSet ds2 = new DataSet(); 65 60 66 61 Node osm = new Node(LatLon.ZERO); 67 assertTrue(new AddCommand( layer2, osm).executeCommand());62 assertTrue(new AddCommand(ds2, osm).executeCommand()); 68 63 69 assertArrayEquals(new Object[0], layer1.data.allPrimitives().toArray());70 assertArrayEquals(new Object[] {osm}, layer2.data.allPrimitives().toArray());64 assertArrayEquals(new Object[0], ds1.allPrimitives().toArray()); 65 assertArrayEquals(new Object[] {osm}, ds2.allPrimitives().toArray()); 71 66 } 72 67 … … 76 71 @Test 77 72 public void testUndo() { 78 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null);79 MainApplication.getLayerManager().addLayer(layer1);80 73 Node osm = new Node(LatLon.ZERO); 81 layer1.data.addPrimitive(osm);74 DataSet ds = new DataSet(osm); 82 75 83 AddCommand command = new AddCommand( new Node(LatLon.ZERO));76 AddCommand command = new AddCommand(ds, new Node(LatLon.ZERO)); 84 77 command.executeCommand(); 85 78 86 79 command.undoCommand(); 87 assertArrayEquals(new Object[] {osm}, layer1.data.allPrimitives().toArray());80 assertArrayEquals(new Object[] {osm}, ds.allPrimitives().toArray()); 88 81 } 89 82 … … 95 88 Node osm = new Node(LatLon.ZERO); 96 89 97 assertArrayEquals(new Object[] {osm}, new AddCommand( osm).getParticipatingPrimitives().toArray());90 assertArrayEquals(new Object[] {osm}, new AddCommand(new DataSet(), osm).getParticipatingPrimitives().toArray()); 98 91 } 99 92 … … 108 101 ArrayList<OsmPrimitive> deleted = new ArrayList<>(); 109 102 ArrayList<OsmPrimitive> added = new ArrayList<>(); 110 new AddCommand( osm).fillModifiedData(modified, deleted, added);103 new AddCommand(new DataSet(), osm).fillModifiedData(modified, deleted, added); 111 104 assertArrayEquals(new Object[] {}, modified.toArray()); 112 105 assertArrayEquals(new Object[] {}, deleted.toArray()); … … 127 120 relation.put("name", "xy"); 128 121 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.*")); 122 DataSet ds = new DataSet(); 123 assertTrue(new AddCommand(ds, node).getDescriptionText().matches("Add node.*xy.*")); 124 assertTrue(new AddCommand(ds, way).getDescriptionText().matches("Add way.*xy.*")); 125 assertTrue(new AddCommand(ds, relation).getDescriptionText().matches("Add relation.*xy.*")); 132 126 } 133 127 -
trunk/test/unit/org/openstreetmap/josm/command/AddPrimitivesCommandTest.java
r12636 r12726 23 23 import org.openstreetmap.josm.data.osm.Way; 24 24 import org.openstreetmap.josm.data.osm.WayData; 25 import org.openstreetmap.josm.gui.MainApplication;26 25 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 27 26 import org.openstreetmap.josm.testutils.JOSMTestRules; … … 48 47 @Test 49 48 public void testAdd() { 50 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 51 MainApplication.getLayerManager().addLayer(layer1); 52 53 List<PrimitiveData> testData = createTestData(); 54 assertTrue(new AddPrimitivesCommand(testData).executeCommand()); 55 56 testContainsTestData(layer1); 57 assertEquals(3, layer1.data.getAllSelected().size()); 49 DataSet ds = new DataSet(); 50 51 List<PrimitiveData> testData = createTestData(); 52 assertTrue(new AddPrimitivesCommand(testData, ds).executeCommand()); 53 54 testContainsTestData(ds); 55 assertEquals(3, ds.getAllSelected().size()); 58 56 } 59 57 … … 63 61 @Test 64 62 public void testAddSetSelection() { 65 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 66 MainApplication.getLayerManager().addLayer(layer1); 67 68 List<PrimitiveData> testData = createTestData(); 69 assertTrue(new AddPrimitivesCommand(testData, testData.subList(2, 3)).executeCommand()); 70 71 testContainsTestData(layer1); 72 73 assertEquals(1, layer1.data.getAllSelected().size()); 74 assertEquals(1, layer1.data.getSelectedWays().size()); 75 } 76 77 /** 78 * Tests if the add command respects the layer. 63 DataSet ds = new DataSet(); 64 65 List<PrimitiveData> testData = createTestData(); 66 assertTrue(new AddPrimitivesCommand(testData, testData.subList(2, 3), ds).executeCommand()); 67 68 testContainsTestData(ds); 69 70 assertEquals(1, ds.getAllSelected().size()); 71 assertEquals(1, ds.getSelectedWays().size()); 72 } 73 74 /** 75 * Tests if the add command respects the data set. 79 76 */ 80 77 @Test 81 78 public void testAddToLayer() { 82 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 83 OsmDataLayer layer2 = new OsmDataLayer(new DataSet(), "l1", null); 84 85 MainApplication.getLayerManager().addLayer(layer1); 86 MainApplication.getLayerManager().addLayer(layer2); 87 88 List<PrimitiveData> testData = createTestData(); 89 assertTrue(new AddPrimitivesCommand(testData, testData.subList(2, 3), layer1).executeCommand()); 90 91 testContainsTestData(layer1); 92 assertTrue(layer2.data.allPrimitives().isEmpty()); 93 94 assertEquals(1, layer1.data.getAllSelected().size()); 95 assertEquals(1, layer1.data.getSelectedWays().size()); 79 DataSet ds1 = new DataSet(); 80 DataSet ds2 = new DataSet(); 81 82 List<PrimitiveData> testData = createTestData(); 83 assertTrue(new AddPrimitivesCommand(testData, testData.subList(2, 3), ds1).executeCommand()); 84 85 testContainsTestData(ds1); 86 assertTrue(ds2.allPrimitives().isEmpty()); 87 88 assertEquals(1, ds1.getAllSelected().size()); 89 assertEquals(1, ds1.getSelectedWays().size()); 96 90 } 97 91 … … 101 95 @Test 102 96 public void testAddIgnoresExisting() { 103 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 104 MainApplication.getLayerManager().addLayer(layer1); 105 106 List<PrimitiveData> testData = createTestData(); 107 assertTrue(new AddPrimitivesCommand(testData).executeCommand()); 108 assertEquals(2, layer1.data.getNodes().size()); 109 assertEquals(1, layer1.data.getWays().size()); 97 DataSet ds = new DataSet(); 98 99 List<PrimitiveData> testData = createTestData(); 100 assertTrue(new AddPrimitivesCommand(testData, ds).executeCommand()); 101 assertEquals(2, ds.getNodes().size()); 102 assertEquals(1, ds.getWays().size()); 110 103 111 104 testData.set(2, createTestNode(7)); 112 assertTrue(new AddPrimitivesCommand(testData ).executeCommand());113 114 assertEquals(3, layer1.data.getNodes().size());115 assertEquals(1, layer1.data.getWays().size());105 assertTrue(new AddPrimitivesCommand(testData, ds).executeCommand()); 106 107 assertEquals(3, ds.getNodes().size()); 108 assertEquals(1, ds.getWays().size()); 116 109 } 117 110 … … 121 114 @Test 122 115 public void testDescription() { 123 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 124 MainApplication.getLayerManager().addLayer(layer1); 116 DataSet ds = new DataSet(); 125 117 126 118 List<PrimitiveData> testData = createTestData(); 127 119 NodeData data2 = createTestNode(7); 128 120 129 AddPrimitivesCommand command1 = new AddPrimitivesCommand(testData );130 AddPrimitivesCommand command2 = new AddPrimitivesCommand(Arrays.<PrimitiveData>asList(data2) );121 AddPrimitivesCommand command1 = new AddPrimitivesCommand(testData, ds); 122 AddPrimitivesCommand command2 = new AddPrimitivesCommand(Arrays.<PrimitiveData>asList(data2), ds); 131 123 132 124 assertEquals("Added 3 objects", command1.getDescriptionText()); … … 146 138 @Test 147 139 public void testUndo() { 148 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 149 MainApplication.getLayerManager().addLayer(layer1); 150 151 List<PrimitiveData> testData = createTestData(); 152 153 AddPrimitivesCommand command = new AddPrimitivesCommand(testData); 140 DataSet ds = new DataSet(); 141 142 List<PrimitiveData> testData = createTestData(); 143 144 AddPrimitivesCommand command = new AddPrimitivesCommand(testData, ds); 154 145 155 146 assertTrue(command.executeCommand()); 156 147 157 assertEquals(3, layer1.data.allPrimitives().size());158 assertEquals(1, layer1.data.getWays().size());159 Way way = layer1.data.getWays().iterator().next();148 assertEquals(3, ds.allPrimitives().size()); 149 assertEquals(1, ds.getWays().size()); 150 Way way = ds.getWays().iterator().next(); 160 151 161 152 for (int i = 0; i < 2; i++) { … … 163 154 command.undoCommand(); 164 155 165 assertEquals(0, layer1.data.allPrimitives().size());166 assertEquals(0, layer1.data.getWays().size());156 assertEquals(0, ds.allPrimitives().size()); 157 assertEquals(0, ds.getWays().size()); 167 158 168 159 // redo 169 160 assertTrue(command.executeCommand()); 170 161 171 assertEquals(3, layer1.data.allPrimitives().size());172 assertEquals(1, layer1.data.getWays().size());173 assertSame(way, layer1.data.getWays().iterator().next());162 assertEquals(3, ds.allPrimitives().size()); 163 assertEquals(1, ds.getWays().size()); 164 assertSame(way, ds.getWays().iterator().next()); 174 165 } 175 166 } … … 181 172 @Test 182 173 public void testUndoIgnoresExisting() { 183 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 184 MainApplication.getLayerManager().addLayer(layer1); 185 186 List<PrimitiveData> testData = createTestData(); 187 188 assertTrue(new AddPrimitivesCommand(testData).executeCommand()); 189 assertEquals(2, layer1.data.getNodes().size()); 190 assertEquals(1, layer1.data.getWays().size()); 174 DataSet ds = new DataSet(); 175 176 List<PrimitiveData> testData = createTestData(); 177 178 assertTrue(new AddPrimitivesCommand(testData, ds).executeCommand()); 179 assertEquals(2, ds.getNodes().size()); 180 assertEquals(1, ds.getWays().size()); 191 181 192 182 testData.set(2, createTestNode(7)); 193 183 194 AddPrimitivesCommand command = new AddPrimitivesCommand(testData );184 AddPrimitivesCommand command = new AddPrimitivesCommand(testData, ds); 195 185 196 186 assertTrue(command.executeCommand()); 197 187 198 assertEquals(3, layer1.data.getNodes().size());199 assertEquals(1, layer1.data.getWays().size());188 assertEquals(3, ds.getNodes().size()); 189 assertEquals(1, ds.getWays().size()); 200 190 201 191 for (int i = 0; i < 2; i++) { … … 203 193 command.undoCommand(); 204 194 205 assertEquals(2, layer1.data.getNodes().size());206 assertEquals(1, layer1.data.getWays().size());195 assertEquals(2, ds.getNodes().size()); 196 assertEquals(1, ds.getWays().size()); 207 197 208 198 // redo 209 199 assertTrue(command.executeCommand()); 210 200 211 assertEquals(3, layer1.data.getNodes().size());212 assertEquals(1, layer1.data.getWays().size());201 assertEquals(3, ds.getNodes().size()); 202 assertEquals(1, ds.getWays().size()); 213 203 } 214 204 } … … 219 209 @Test 220 210 public void testParticipatingPrimitives() { 221 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 222 MainApplication.getLayerManager().addLayer(layer1); 223 224 List<PrimitiveData> testData = createTestData(); 225 AddPrimitivesCommand command = new AddPrimitivesCommand(testData); 211 DataSet ds = new DataSet(); 212 213 List<PrimitiveData> testData = createTestData(); 214 AddPrimitivesCommand command = new AddPrimitivesCommand(testData, ds); 226 215 assertTrue(command.executeCommand()); 227 216 228 217 assertEquals(3, command.getParticipatingPrimitives().size()); 229 HashSet<OsmPrimitive> should = new HashSet<>( layer1.data.allPrimitives());218 HashSet<OsmPrimitive> should = new HashSet<>(ds.allPrimitives()); 230 219 assertEquals(should, new HashSet<>(command.getParticipatingPrimitives())); 231 220 … … 245 234 246 235 List<PrimitiveData> testData = createTestData(); 247 new AddPrimitivesCommand(testData ).fillModifiedData(modified, deleted, added);236 new AddPrimitivesCommand(testData, new DataSet()).fillModifiedData(modified, deleted, added); 248 237 249 238 assertArrayEquals(new Object[] {}, modified.toArray()); … … 252 241 } 253 242 254 private void testContainsTestData( OsmDataLayer layer1) {255 assertEquals(3, layer1.data.allPrimitives().size());256 assertEquals(2, layer1.data.getNodes().size());257 assertEquals(1, layer1.data.getWays().size());258 assertEquals(3, layer1.data.allModifiedPrimitives().size());259 for (OsmPrimitive n : layer1.data.allPrimitives()) {243 private void testContainsTestData(DataSet data) { 244 assertEquals(3, data.allPrimitives().size()); 245 assertEquals(2, data.getNodes().size()); 246 assertEquals(1, data.getWays().size()); 247 assertEquals(3, data.allModifiedPrimitives().size()); 248 for (OsmPrimitive n : data.allPrimitives()) { 260 249 assertEquals("test", n.get("test")); 261 250 assertTrue(n.isModified()); 262 251 } 263 252 264 for (Node n : layer1.data.getNodes()) {253 for (Node n : data.getNodes()) { 265 254 assertEquals(LatLon.ZERO, n.getCoor()); 266 255 } 267 256 268 for (Way w : layer1.data.getWays()) {257 for (Way w : data.getWays()) { 269 258 assertEquals(2, w.getNodes().size()); 270 259 assertEquals(5, w.getNode(0).getId()); -
trunk/test/unit/org/openstreetmap/josm/command/ChangeCommandTest.java
r10758 r12726 142 142 Relation relation = new Relation(); 143 143 relation.put("name", "xy"); 144 DataSet ds = new DataSet(node, way, relation); 144 145 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.*"));146 assertTrue(new ChangeCommand(ds, node, node).getDescriptionText().matches("Change node.*xy.*")); 147 assertTrue(new ChangeCommand(ds, way, way).getDescriptionText().matches("Change way.*xy.*")); 148 assertTrue(new ChangeCommand(ds, relation, relation).getDescriptionText().matches("Change relation.*xy.*")); 148 149 } 149 150 -
trunk/test/unit/org/openstreetmap/josm/command/ChangeNodesCommandTest.java
r10758 r12726 115 115 way.addNode(node); 116 116 way.put("name", "xy"); 117 117 DataSet ds = new DataSet(node, way); 118 118 assertTrue( 119 new ChangeNodesCommand( way, Arrays.asList(node)).getDescriptionText().matches("Change nodes of.*xy.*"));119 new ChangeNodesCommand(ds, way, Arrays.asList(node)).getDescriptionText().matches("Change nodes of.*xy.*")); 120 120 } 121 121 -
trunk/test/unit/org/openstreetmap/josm/command/ChangePropertyCommandTest.java
r10758 r12726 201 201 tagsRemove.put("existing", ""); 202 202 203 Way way = new Way(); 204 way.addNode(node1); 203 Way way = testData.createWay(20, node1); 205 204 way.put("name", "xy"); 206 205 way.put("existing", "existing"); 207 Relation relation = new Relation();206 Relation relation = testData.createRelation(30); 208 207 relation.put("name", "xy"); 209 208 relation.put("existing", "existing"); -
trunk/test/unit/org/openstreetmap/josm/command/CommandTest.java
r12718 r12726 2 2 package org.openstreetmap.josm.command; 3 3 4 import static org.junit.Assert.assertSame;4 import java.util.Arrays; 5 5 6 import java.util.Arrays;7 import java.util.Collection;8 9 import org.junit.Before;10 6 import org.junit.Rule; 11 7 import org.junit.Test; … … 13 9 import org.openstreetmap.josm.data.osm.DataSet; 14 10 import org.openstreetmap.josm.data.osm.Node; 15 import org.openstreetmap.josm.data.osm.OsmPrimitive;16 11 import org.openstreetmap.josm.data.osm.Relation; 17 12 import org.openstreetmap.josm.data.osm.RelationMember; … … 37 32 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 38 33 public JOSMTestRules test = new JOSMTestRules().preferences().i18n(); 39 private CommandTestData testData;40 41 /**42 * Set up the test data.43 */44 @Before45 public void createTestData() {46 testData = new CommandTestData();47 }48 49 /**50 * Test {@link Command#getLayer()}51 * @deprecated to be removed end of 201752 */53 @Test54 @Deprecated55 public void testGetLayer() {56 OsmDataLayer layer2 = new OsmDataLayer(new DataSet(), "test", null);57 Command command = new NopCommand();58 Command command2 = new NopCommand(layer2.data);59 assertSame(testData.layer, command.getLayer());60 assertSame(layer2, command2.getLayer());61 }62 34 63 35 /** … … 75 47 .suppress(Warning.NONFINAL_FIELDS) 76 48 .verify(); 77 }78 79 private static final class NopCommand extends Command {80 NopCommand() {81 super();82 }83 84 NopCommand(DataSet dataset) {85 super(dataset);86 }87 88 @Override89 public String getDescriptionText() {90 return "";91 }92 93 @Override94 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,95 Collection<OsmPrimitive> added) {96 // nop97 }98 49 } 99 50 -
trunk/test/unit/org/openstreetmap/josm/command/DeleteCommandTest.java
r10775 r12726 11 11 import java.util.Collection; 12 12 import java.util.List; 13 import java.util.NoSuchElementException; 13 14 14 15 import org.junit.Before; … … 113 114 */ 114 115 @Test 115 public void testDel teNodesInWay() {116 public void testDeleteNodesInWay() { 116 117 testData.existingNode.removeAll(); 117 118 // That untagged node should be deleted. 118 119 testData.existingNode2.removeAll(); 119 DeleteCommand.delete( testData.layer,Arrays.asList(testData.existingWay), true, true).executeCommand();120 DeleteCommand.delete(Arrays.asList(testData.existingWay), true, true).executeCommand(); 120 121 121 122 assertTrue(testData.existingWay.isDeleted()); … … 137 138 way2.setNodes(Arrays.asList(node2, node3, node4)); 138 139 testData.layer.data.addPrimitive(way2); 139 DeleteCommand.delete( testData.layer,Arrays.asList(way1, way2), true, true).executeCommand();140 DeleteCommand.delete(Arrays.asList(way1, way2), true, true).executeCommand(); 140 141 141 142 assertTrue(way1.isDeleted()); … … 167 168 * Test that {@link DeleteCommand} checks for non-empty list 168 169 */ 169 @Test(expected = IllegalArgumentException.class)170 @Test(expected = NoSuchElementException.class) 170 171 public void testConsistencyNonEmpty() { 171 172 new DeleteCommand(Arrays.<OsmPrimitive>asList()); … … 175 176 * Test that {@link DeleteCommand} checks for non-null list 176 177 */ 177 @Test(expected = IllegalArgumentException.class)178 @Test(expected = NullPointerException.class) 178 179 public void testConsistencyNonNull() { 179 180 new DeleteCommand((Collection<OsmPrimitive>) null); -
trunk/test/unit/org/openstreetmap/josm/command/MoveCommandTest.java
r10758 r12726 248 248 Node node = new Node(LatLon.ZERO); 249 249 node.put("name", "xy"); 250 250 new DataSet(node); 251 251 List<OsmPrimitive> nodeList = Arrays.<OsmPrimitive>asList(node); 252 252 assertTrue(new MoveCommand(nodeList, 1, 2).getDescriptionText().matches("Move 1 node")); -
trunk/test/unit/org/openstreetmap/josm/command/RotateCommandTest.java
r10758 r12726 55 55 Node n2 = new Node(new EastNorth(-1, 0)); 56 56 Node n3 = new Node(new EastNorth(-9, -10)); 57 new DataSet(n1, n2, n3); 57 58 RotateCommand rotate = new RotateCommand(Arrays.asList(n1, n2, n3), new EastNorth(0, 0)); 58 59 rotate.setRotationAngle(Math.PI / 4); … … 73 74 Node n2 = new Node(new EastNorth(-1, 0)); 74 75 Node n3 = new Node(new EastNorth(-9, -10)); 76 new DataSet(n1, n2, n3); 75 77 RotateCommand rotate = new RotateCommand(Arrays.asList(n1, n2, n3), new EastNorth(0, 0)); 76 78 rotate.setRotationAngle(Math.PI / 4); -
trunk/test/unit/org/openstreetmap/josm/command/ScaleCommandTest.java
r10758 r12726 55 55 Node n2 = new Node(new EastNorth(-1, 0)); 56 56 Node n3 = new Node(new EastNorth(-9, -10)); 57 new DataSet(n1, n2, n3); 57 58 ScaleCommand scale = new ScaleCommand(Arrays.asList(n1, n2, n3), new EastNorth(0, 0)); 58 59 scale.setScalingFactor(2.5); … … 73 74 Node n2 = new Node(new EastNorth(-1, 0)); 74 75 Node n3 = new Node(new EastNorth(-9, -10)); 76 new DataSet(n1, n2, n3); 75 77 ScaleCommand scale = new ScaleCommand(Arrays.asList(n1, n2, n3), new EastNorth(0, 0)); 76 78 scale.setScalingFactor(2.5); -
trunk/test/unit/org/openstreetmap/josm/command/SelectCommandTest.java
r12368 r12726 50 50 @Test 51 51 public void testExecute() { 52 SelectCommand command = new SelectCommand( Arrays.asList(testData.existingNode, testData.existingWay));52 SelectCommand command = new SelectCommand(testData.layer.data, Arrays.asList(testData.existingNode, testData.existingWay)); 53 53 54 54 testData.layer.data.setSelected(Arrays.asList(testData.existingNode2)); … … 67 67 public void testExecuteAfterModify() { 68 68 List<OsmPrimitive> list = new ArrayList<>(Arrays.asList(testData.existingNode, testData.existingWay)); 69 SelectCommand command = new SelectCommand( list);69 SelectCommand command = new SelectCommand(testData.layer.data, list); 70 70 71 71 list.remove(testData.existingNode); … … 84 84 @Test 85 85 public void testUndo() { 86 SelectCommand command = new SelectCommand( Arrays.asList(testData.existingNode, testData.existingWay));86 SelectCommand command = new SelectCommand(testData.layer.data, Arrays.asList(testData.existingNode, testData.existingWay)); 87 87 testData.layer.data.setSelected(Arrays.asList(testData.existingNode2)); 88 88 … … 110 110 ArrayList<OsmPrimitive> deleted = new ArrayList<>(); 111 111 ArrayList<OsmPrimitive> added = new ArrayList<>(); 112 SelectCommand command = new SelectCommand( Arrays.asList(testData.existingNode, testData.existingWay));112 SelectCommand command = new SelectCommand(testData.layer.data, Arrays.asList(testData.existingNode, testData.existingWay)); 113 113 command.fillModifiedData(modified, deleted, added); 114 114 // intentionally empty. … … 123 123 @Test 124 124 public void testGetParticipatingPrimitives() { 125 SelectCommand command = new SelectCommand( Arrays.asList(testData.existingNode));125 SelectCommand command = new SelectCommand(testData.layer.data, Arrays.asList(testData.existingNode)); 126 126 command.executeCommand(); 127 127 assertArrayEquals(new Object[] {testData.existingNode}, command.getParticipatingPrimitives().toArray()); … … 133 133 @Test 134 134 public void testDescription() { 135 assertTrue(new SelectCommand(Arrays.<OsmPrimitive>asList(testData.existingNode)) 135 DataSet ds = testData.layer.data; 136 assertTrue(new SelectCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode)) 136 137 .getDescriptionText().matches("Selected 1 object")); 137 assertTrue(new SelectCommand( Arrays.asList(testData.existingNode, testData.existingWay))138 assertTrue(new SelectCommand(ds, Arrays.asList(testData.existingNode, testData.existingWay)) 138 139 .getDescriptionText().matches("Selected 2 objects")); 139 assertTrue(new SelectCommand( Arrays.<OsmPrimitive>asList())140 assertTrue(new SelectCommand(ds, Arrays.<OsmPrimitive>asList()) 140 141 .getDescriptionText().matches("Selected 0 objects")); 141 assertTrue(new SelectCommand( null)142 assertTrue(new SelectCommand(ds, null) 142 143 .getDescriptionText().matches("Selected 0 objects")); 143 144 } -
trunk/test/unit/org/openstreetmap/josm/command/SequenceCommandTest.java
r11874 r12726 12 12 import java.util.Arrays; 13 13 import java.util.Collection; 14 import java.util.Collections; 14 15 15 16 import org.junit.Before; … … 54 55 @Test 55 56 public void testExecute() { 56 final TestCommand command1 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode)); 57 TestCommand command2 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode2)) { 57 DataSet ds = new DataSet(); 58 final TestCommand command1 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode)); 59 TestCommand command2 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode2)) { 58 60 @Override 59 61 public boolean executeCommand() { … … 75 77 @Test 76 78 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 DataSet ds = new DataSet(); 80 final TestCommand command2 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode2)); 81 TestCommand command1 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode)) { 79 82 @Override 80 83 public void undoCommand() { … … 103 106 @Test 104 107 public void testExecuteRollback() { 105 TestCommand command1 = new TestCommand(null); 106 FailingCommand command2 = new FailingCommand(); 107 TestCommand command3 = new TestCommand(null); 108 DataSet ds = new DataSet(); 109 TestCommand command1 = new TestCommand(ds, null); 110 FailingCommand command2 = new FailingCommand(ds); 111 TestCommand command3 = new TestCommand(ds, null); 108 112 SequenceCommand command = new SequenceCommand("seq", Arrays.<Command>asList(command1, command2, command3)); 109 113 assertFalse(command.executeCommand()); … … 119 123 @Test 120 124 public void testContinueOnErrors() { 121 TestCommand command1 = new TestCommand(null); 122 FailingCommand command2 = new FailingCommand(); 123 TestCommand command3 = new TestCommand(null); 125 DataSet ds = new DataSet(); 126 TestCommand command1 = new TestCommand(ds, null); 127 FailingCommand command2 = new FailingCommand(ds); 128 TestCommand command3 = new TestCommand(ds, null); 124 129 SequenceCommand command = new SequenceCommand("seq", Arrays.<Command>asList(command1, command2, command3), true); 125 130 assertTrue(command.executeCommand()); … … 137 142 @Test 138 143 public void testGetLastCommand() { 139 final TestCommand command1 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode)); 140 final TestCommand command2 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode2)); 141 142 assertEquals(command2, new SequenceCommand("seq", command1, command2).getLastCommand()); 143 assertNull(new SequenceCommand("seq").getLastCommand()); 144 DataSet ds = new DataSet(); 145 final TestCommand command1 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode)); 146 final TestCommand command2 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode2)); 147 148 assertEquals(command2, new SequenceCommand(ds, "seq", Arrays.asList(command1, command2), false).getLastCommand()); 149 assertNull(new SequenceCommand(ds, "seq", Collections.emptyList(), false).getLastCommand()); 144 150 } 145 151 … … 149 155 @Test 150 156 public void testFillModifiedData() { 151 Command command1 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode)); 152 Command command2 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode2)); 153 Command command3 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingWay)) { 157 DataSet ds = new DataSet(); 158 Command command1 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode)); 159 Command command2 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode2)); 160 Command command3 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingWay)) { 154 161 @Override 155 162 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, … … 158 165 } 159 166 }; 160 Command command4 = new TestCommand( Arrays.<OsmPrimitive>asList(testData.existingRelation)) {167 Command command4 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingRelation)) { 161 168 @Override 162 169 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, … … 181 188 @Test 182 189 public void testGetParticipatingPrimitives() { 183 Command command1 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode)); 184 Command command2 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode2)); 190 DataSet ds = new DataSet(); 191 Command command1 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode)); 192 Command command2 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode2)); 185 193 186 194 SequenceCommand command = new SequenceCommand("seq", command1, command2); … … 197 205 @Test 198 206 public void testDescription() { 199 assertTrue(new SequenceCommand( "test").getDescriptionText().matches("Sequence: test"));207 assertTrue(new SequenceCommand(new DataSet(), "test", Collections.emptyList(), false).getDescriptionText().matches("Sequence: test")); 200 208 } 201 209 … … 205 213 @Test 206 214 public void testEqualsContract() { 215 DataSet ds = new DataSet(); 207 216 EqualsVerifier.forClass(SequenceCommand.class).usingGetClass() 208 217 .withPrefabValues(Command.class, 209 new AddCommand( new Node(1)), new AddCommand(new Node(2)))218 new AddCommand(ds, new Node(1)), new AddCommand(ds, new Node(2))) 210 219 .withPrefabValues(DataSet.class, 211 220 new DataSet(), new DataSet()) … … 222 231 protected boolean executed; 223 232 224 TestCommand( Collection<? extends OsmPrimitive> primitives) {225 super( );233 TestCommand(DataSet ds, Collection<? extends OsmPrimitive> primitives) { 234 super(ds); 226 235 this.primitives = primitives; 227 236 } … … 266 275 private static class FailingCommand extends TestCommand { 267 276 268 FailingCommand( ) {269 super( null);277 FailingCommand(DataSet ds) { 278 super(ds, null); 270 279 } 271 280 … … 286 295 return "FailingCommand"; 287 296 } 288 289 } 290 297 } 291 298 } -
trunk/test/unit/org/openstreetmap/josm/command/conflict/ConflictAddCommandTest.java
r12672 r12726 6 6 import static org.junit.Assert.assertTrue; 7 7 8 import org.junit.After;9 8 import org.junit.Before; 10 9 import org.junit.Rule; 11 10 import org.junit.Test; 11 import org.openstreetmap.josm.command.CommandTest.CommandTestData; 12 12 import org.openstreetmap.josm.data.conflict.Conflict; 13 13 import org.openstreetmap.josm.data.osm.DataSet; … … 15 15 import org.openstreetmap.josm.data.osm.User; 16 16 import org.openstreetmap.josm.data.osm.Way; 17 import org.openstreetmap.josm.gui.MainApplication;18 17 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 19 18 import org.openstreetmap.josm.testutils.JOSMTestRules; … … 28 27 public class ConflictAddCommandTest { 29 28 30 private OsmDataLayer layer;31 32 29 /** 33 30 * Setup test. … … 36 33 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 37 34 public JOSMTestRules test = new JOSMTestRules().platform(); 35 private CommandTestData testData; 38 36 39 37 /** … … 42 40 @Before 43 41 public void setUp() { 44 layer = new OsmDataLayer(new DataSet(), null, null); 45 MainApplication.getLayerManager().addLayer(layer); 46 } 47 48 /** 49 * Cleanup test resources. 50 */ 51 @After 52 public void tearDown() { 53 MainApplication.getLayerManager().removeLayer(layer); 42 testData = new CommandTestData(); 54 43 } 55 44 … … 59 48 @Test 60 49 public void testExecuteUndoCommand() { 61 DataSet ds = MainApplication.getLayerManager().getEditDataSet();62 Conflict<Node> conflict = new Conflict<>( new Node(), new Node());50 DataSet ds = testData.layer.data; 51 Conflict<Node> conflict = new Conflict<>(testData.existingNode, testData.existingNode2); 63 52 ConflictAddCommand cmd = new ConflictAddCommand(ds, conflict); 64 53 assertTrue(cmd.executeCommand()); … … 75 64 @Test 76 65 public void testGetDescriptionIcon() { 77 OsmDataLayer layer = MainApplication.getLayerManager().getEditLayer(); 78 Conflict<Node> conflict = new Conflict<>(new Node(), new Node()); 79 assertNotNull(new ConflictAddCommand(layer, conflict).getDescriptionIcon()); 66 Conflict<Node> conflict = new Conflict<>(testData.existingNode, testData.existingNode2); 67 assertNotNull(new ConflictAddCommand(testData.layer.data, conflict).getDescriptionIcon()); 80 68 } 81 69 -
trunk/test/unit/org/openstreetmap/josm/command/conflict/CoordinateConflictResolveCommandTest.java
r12636 r12726 6 6 import static org.junit.Assert.assertTrue; 7 7 8 import org.junit.After;9 8 import org.junit.Before; 10 9 import org.junit.Rule; 11 10 import org.junit.Test; 11 import org.openstreetmap.josm.command.CommandTest.CommandTestData; 12 12 import org.openstreetmap.josm.data.conflict.Conflict; 13 13 import org.openstreetmap.josm.data.coor.LatLon; … … 16 16 import org.openstreetmap.josm.data.osm.User; 17 17 import org.openstreetmap.josm.data.osm.Way; 18 import org.openstreetmap.josm.gui.MainApplication;19 18 import org.openstreetmap.josm.gui.conflict.pair.MergeDecisionType; 20 19 import org.openstreetmap.josm.gui.layer.OsmDataLayer; … … 30 29 public class CoordinateConflictResolveCommandTest { 31 30 32 private OsmDataLayer layer;31 private CommandTestData testData; 33 32 34 33 /** … … 44 43 @Before 45 44 public void setUp() { 46 layer = new OsmDataLayer(new DataSet(), null, null); 47 MainApplication.getLayerManager().addLayer(layer); 45 testData = new CommandTestData(); 48 46 } 49 47 50 /** 51 * Cleanup test resources. 52 */ 53 @After 54 public void tearDown() { 55 MainApplication.getLayerManager().removeLayer(layer); 56 } 57 58 private static Conflict<Node> createConflict() { 59 return new Conflict<>(new Node(LatLon.ZERO), new Node(new LatLon(50, 50))); 48 private Conflict<Node> createConflict() { 49 return new Conflict<>(testData.existingNode, testData.existingNode2); 60 50 } 61 51 -
trunk/test/unit/org/openstreetmap/josm/data/validation/tests/MapCSSTagCheckerTest.java
r12620 r12726 25 25 import org.openstreetmap.josm.command.PseudoCommand; 26 26 import org.openstreetmap.josm.command.SequenceCommand; 27 import org.openstreetmap.josm.data.osm. Node;27 import org.openstreetmap.josm.data.osm.DataSet; 28 28 import org.openstreetmap.josm.data.osm.OsmPrimitive; 29 29 import org.openstreetmap.josm.data.osm.OsmUtils; … … 82 82 assertEquals("fixAdd: natural=wetland", check.fixCommands.get(1).toString()); 83 83 assertEquals("fixAdd: wetland=marsh", check.fixCommands.get(2).toString()); 84 final Node n1 = new Node(); 85 n1.put("natural", "marsh"); 84 final OsmPrimitive n1 = OsmUtils.createPrimitive("node natural=marsh"); 85 final OsmPrimitive n2 = OsmUtils.createPrimitive("node natural=wood"); 86 new DataSet(n1, n2); 86 87 assertTrue(check.test(n1)); 87 88 assertEquals("deprecated", check.getErrorForPrimitive(n1).getMessage()); … … 90 91 assertEquals("Sequence: Fix of natural=marsh is deprecated", check.fixPrimitive(n1).getDescriptionText()); 91 92 assertEquals("{natural=}", ((ChangePropertyCommand) check.fixPrimitive(n1).getChildren().iterator().next()).getTags().toString()); 92 final Node n2 = new Node();93 n2.put("natural", "wood");94 93 assertFalse(check.test(n2)); 95 94 assertEquals("The key is natural and the value is marsh", … … 109 108 "fixAdd: \"highway=construction\";\n" + 110 109 "}")).parseChecks.get(0); 110 new DataSet(p); 111 111 final Command command = check.fixPrimitive(p); 112 112 assertTrue(command instanceof SequenceCommand); -
trunk/test/unit/org/openstreetmap/josm/gui/conflict/pair/ConflictResolverTest.java
r11102 r12726 5 5 import static org.junit.Assert.assertNotNull; 6 6 7 import java.util.NoSuchElementException; 8 7 9 import org.junit.Rule; 8 10 import org.junit.Test; … … 10 12 import org.openstreetmap.josm.data.conflict.Conflict; 11 13 import org.openstreetmap.josm.data.coor.LatLon; 14 import org.openstreetmap.josm.data.osm.DataSet; 12 15 import org.openstreetmap.josm.data.osm.Node; 13 16 import org.openstreetmap.josm.data.osm.Relation; … … 32 35 * Unit test of {@link ConflictResolver#buildResolveCommand} - empty case. 33 36 */ 34 @Test 37 @Test(expected = NoSuchElementException.class) 35 38 public void testBuildResolveCommandEmpty() { 36 39 assertNotNull(new ConflictResolver().buildResolveCommand()); … … 47 50 Node n2 = new Node(LatLon.NORTH_POLE); 48 51 n2.put("source", "theirs"); 52 new DataSet(n1, n2); 49 53 resolver.populate(new Conflict<>(n1, n2)); 50 54 resolver.decideRemaining(MergeDecisionType.KEEP_MINE); … … 62 66 Way w2 = new Way(); 63 67 w2.put("source", "theirs"); 68 new DataSet(w1, w2); 64 69 resolver.populate(new Conflict<>(w1, w2)); 65 70 resolver.decideRemaining(MergeDecisionType.KEEP_MINE); … … 77 82 Relation r2 = new Relation(); 78 83 r2.put("source", "theirs"); 84 new DataSet(r1, r2); 79 85 resolver.populate(new Conflict<>(r1, r2)); 80 86 resolver.decideRemaining(MergeDecisionType.KEEP_MINE); -
trunk/test/unit/org/openstreetmap/josm/gui/datatransfer/OsmTransferHandlerTest.java
r12564 r12726 64 64 public void testPasteTags() { 65 65 Node n = new Node(LatLon.ZERO); 66 new DataSet(n); 66 67 67 68 ClipboardUtils.copyString("test=ok"); -
trunk/test/unit/org/openstreetmap/josm/gui/dialogs/CommandStackDialogTest.java
r12641 r12726 46 46 @Test 47 47 public void testCommandStackDialogNotEmpty() { 48 OsmDataLayer layer = new OsmDataLayer(new DataSet(), "", null); 48 DataSet ds = new DataSet(); 49 OsmDataLayer layer = new OsmDataLayer(ds, "", null); 49 50 MainApplication.getLayerManager().addLayer(layer); 50 51 try { 51 Command cmd1 = TestUtils.newCommand( );52 Command cmd2 = TestUtils.newCommand( );52 Command cmd1 = TestUtils.newCommand(ds); 53 Command cmd2 = TestUtils.newCommand(ds); 53 54 MainApplication.undoRedo.add(cmd1); 54 55 MainApplication.undoRedo.add(cmd2);
Note:
See TracChangeset
for help on using the changeset viewer.