Ticket #13223: patch-test-command-3.patch
File patch-test-command-3.patch, 137.0 KB (added by , 8 years ago) |
---|
-
src/org/openstreetmap/josm/command/ChangeNodesCommand.java
diff --git a/src/org/openstreetmap/josm/command/ChangeNodesCommand.java b/src/org/openstreetmap/josm/command/ChangeNodesCommand.java index 147e75e..ca60540 100644
a b public class ChangeNodesCommand extends Command { 37 37 public ChangeNodesCommand(Way way, List<Node> newNodes) { 38 38 this.way = way; 39 39 this.newNodes = newNodes; 40 if (newNodes.isEmpty()) { 41 throw new IllegalArgumentException("Cannot set nodes to be an empty list."); 42 } 40 43 } 41 44 42 45 @Override … … public class ChangeNodesCommand extends Command { 54 57 55 58 @Override 56 59 public String getDescriptionText() { 57 return tr("Change dnodes of {0}", way.getDisplayName(DefaultNameFormatter.getInstance()));60 return tr("Change nodes of {0}", way.getDisplayName(DefaultNameFormatter.getInstance())); 58 61 } 59 62 60 63 @Override -
src/org/openstreetmap/josm/command/ChangePropertyCommand.java
diff --git a/src/org/openstreetmap/josm/command/ChangePropertyCommand.java b/src/org/openstreetmap/josm/command/ChangePropertyCommand.java index eb4fc87..d23f1d0 100644
a b public class ChangePropertyCommand extends Command { 155 155 OsmPrimitive primitive = objects.get(0); 156 156 String msg; 157 157 Map.Entry<String, String> entry = tags.entrySet().iterator().next(); 158 if (entry.getValue() == null ) {158 if (entry.getValue() == null || entry.getValue().isEmpty()) { 159 159 switch(OsmPrimitiveType.from(primitive)) { 160 160 case NODE: msg = marktr("Remove \"{0}\" for node ''{1}''"); break; 161 161 case WAY: msg = marktr("Remove \"{0}\" for way ''{1}''"); break; … … public class ChangePropertyCommand extends Command { 174 174 } 175 175 } else if (objects.size() > 1 && tags.size() == 1) { 176 176 Map.Entry<String, String> entry = tags.entrySet().iterator().next(); 177 if (entry.getValue() == null ) {177 if (entry.getValue() == null || entry.getValue().isEmpty()) { 178 178 /* I18n: plural form for objects, but value < 2 not possible! */ 179 179 text = trn("Remove \"{0}\" for {1} object", "Remove \"{0}\" for {1} objects", objects.size(), entry.getKey(), objects.size()); 180 180 } else { … … public class ChangePropertyCommand extends Command { 185 185 } else { 186 186 boolean allnull = true; 187 187 for (Map.Entry<String, String> tag : this.tags.entrySet()) { 188 if (tag.getValue() != null ) {188 if (tag.getValue() != null && !tag.getValue().isEmpty()) { 189 189 allnull = false; 190 190 break; 191 191 } … … public class ChangePropertyCommand extends Command { 225 225 @Override public Collection<? extends OsmPrimitive> getParticipatingPrimitives() { 226 226 return Collections.singleton(osm); 227 227 } 228 229 228 }); 230 229 } 231 230 return children; -
src/org/openstreetmap/josm/command/ChangePropertyKeyCommand.java
diff --git a/src/org/openstreetmap/josm/command/ChangePropertyKeyCommand.java b/src/org/openstreetmap/josm/command/ChangePropertyKeyCommand.java index 735350b..f883d76 100644
a b public class ChangePropertyKeyCommand extends Command { 65 65 if (!super.executeCommand()) 66 66 return false; // save old 67 67 for (OsmPrimitive osm : objects) { 68 if (osm.hasKey s()) {68 if (osm.hasKey(key) || osm.hasKey(newKey)) { 69 69 osm.setModified(true); 70 70 String oldValue = osm.get(key); 71 71 osm.put(newKey, oldValue); … … public class ChangePropertyKeyCommand extends Command { 86 86 if (objects.size() == 1) { 87 87 NameVisitor v = new NameVisitor(); 88 88 objects.get(0).accept(v); 89 text += ' '+tr(v.className)+' '+v.name;89 text += " "+tr(v.className)+" "+v.name; 90 90 } else { 91 text += ' '+objects.size()+' '+trn("object", "objects", objects.size());91 text += " "+objects.size()+" "+trn("object", "objects", objects.size()); 92 92 } 93 93 return text; 94 94 } … … public class ChangePropertyKeyCommand extends Command { 107 107 final NameVisitor v = new NameVisitor(); 108 108 for (final OsmPrimitive osm : objects) { 109 109 osm.accept(v); 110 final String name = v.name; 111 final Icon icon = v.icon; 110 112 children.add(new PseudoCommand() { 111 113 @Override 112 114 public String getDescriptionText() { 113 return v.name;115 return name; 114 116 } 115 117 116 118 @Override 117 119 public Icon getDescriptionIcon() { 118 return v.icon;120 return icon; 119 121 } 120 122 121 123 @Override -
src/org/openstreetmap/josm/command/ChangeRelationMemberRoleCommand.java
diff --git a/src/org/openstreetmap/josm/command/ChangeRelationMemberRoleCommand.java b/src/org/openstreetmap/josm/command/ChangeRelationMemberRoleCommand.java index c57e468..48c5237 100644
a b public class ChangeRelationMemberRoleCommand extends Command { 48 48 @Override 49 49 public boolean executeCommand() { 50 50 if (position < 0 || position >= relation.getMembersCount()) 51 return false;51 return true; 52 52 53 53 oldRole = relation.getMember(position).getRole(); 54 54 if (newRole.equals(oldRole)) return true; … … public class ChangeRelationMemberRoleCommand extends Command { 61 61 62 62 @Override 63 63 public void undoCommand() { 64 relation.setMember(position, new RelationMember(oldRole, relation.getMember(position).getMember())); 65 if (oldModified != null) { 66 relation.setModified(oldModified); 64 if (position >= 0 && position < relation.getMembersCount()) { 65 relation.setMember(position, new RelationMember(oldRole, relation.getMember(position).getMember())); 66 if (oldModified != null) { 67 relation.setModified(oldModified); 68 } 67 69 } 68 70 } 69 71 -
src/org/openstreetmap/josm/command/Command.java
diff --git a/src/org/openstreetmap/josm/command/Command.java b/src/org/openstreetmap/josm/command/Command.java index 921f55f..4e7b266 100644
a b public abstract class Command implements PseudoCommand { 187 187 * any buffer if it is not longer applicable to the dataset (e.g. it was part of 188 188 * the removed layer) 189 189 * 190 * @param oldLayer the old layer 191 * @return true if this command 190 * @param oldLayer the old layer that was removed 191 * @return true if this command is invalid after that layer is removed. 192 192 */ 193 193 public boolean invalidBecauselayerRemoved(Layer oldLayer) { 194 if (!(oldLayer instanceof OsmDataLayer))195 return false;196 194 return layer == oldLayer; 197 195 } 198 196 -
src/org/openstreetmap/josm/command/DeleteCommand.java
diff --git a/src/org/openstreetmap/josm/command/DeleteCommand.java b/src/org/openstreetmap/josm/command/DeleteCommand.java index edf5e39..1eb5d37 100644
a b import org.openstreetmap.josm.tools.Utils; 50 50 * @since 23 51 51 */ 52 52 public class DeleteCommand extends Command { 53 private static final class DeleteChildCommand implements PseudoCommand { 54 private final OsmPrimitive osm; 55 56 private DeleteChildCommand(OsmPrimitive osm) { 57 this.osm = osm; 58 } 59 60 @Override 61 public String getDescriptionText() { 62 return tr("Deleted ''{0}''", osm.getDisplayName(DefaultNameFormatter.getInstance())); 63 } 64 65 @Override 66 public Icon getDescriptionIcon() { 67 return ImageProvider.get(osm.getDisplayType()); 68 } 69 70 @Override 71 public Collection<? extends OsmPrimitive> getParticipatingPrimitives() { 72 return Collections.singleton(osm); 73 } 74 75 @Override 76 public String toString() { 77 return "DeleteChildCommand [osm=" + osm + "]"; 78 } 79 } 80 53 81 /** 54 82 * The primitives that get deleted. 55 83 */ … … public class DeleteCommand extends Command { 64 92 */ 65 93 public DeleteCommand(Collection<? extends OsmPrimitive> data) { 66 94 CheckParameterUtil.ensureParameterNotNull(data, "data"); 67 if (data.isEmpty())68 throw new IllegalArgumentException(tr("At least one object to delete required, got empty collection"));69 95 this.toDelete = data; 70 96 checkConsistency(); 71 97 } … … public class DeleteCommand extends Command { 105 131 public DeleteCommand(OsmDataLayer layer, Collection<? extends OsmPrimitive> data) { 106 132 super(layer); 107 133 CheckParameterUtil.ensureParameterNotNull(data, "data"); 108 if (data.isEmpty())109 throw new IllegalArgumentException(tr("At least one object to delete required, got empty collection"));110 134 this.toDelete = data; 111 135 checkConsistency(); 112 136 } 113 137 114 138 private void checkConsistency() { 139 if (toDelete.isEmpty()) { 140 throw new IllegalArgumentException(tr("At least one object to delete required, got empty collection")); 141 } 115 142 for (OsmPrimitive p : toDelete) { 116 143 if (p == null) { 117 144 throw new IllegalArgumentException("Primitive to delete must not be null"); … … public class DeleteCommand extends Command { 215 242 else { 216 243 List<PseudoCommand> children = new ArrayList<>(toDelete.size()); 217 244 for (final OsmPrimitive osm : toDelete) { 218 children.add(new PseudoCommand() { 219 220 @Override public String getDescriptionText() { 221 return tr("Deleted ''{0}''", osm.getDisplayName(DefaultNameFormatter.getInstance())); 222 } 223 224 @Override public Icon getDescriptionIcon() { 225 return ImageProvider.get(osm.getDisplayType()); 226 } 227 228 @Override public Collection<? extends OsmPrimitive> getParticipatingPrimitives() { 229 return Collections.singleton(osm); 230 } 231 232 }); 245 children.add(new DeleteChildCommand(osm)); 233 246 } 234 247 return children; 235 248 … … public class DeleteCommand extends Command { 440 453 return new SequenceCommand(tr("Delete"), cmds); 441 454 } 442 455 456 /** 457 * Create a command that deletes a single way segment. The way may be split by this. 458 * @param layer The layer the segment is in. 459 * @param ws The way segment that should be deleted 460 * @return A matching command to safely delete that segment. 461 */ 443 462 public static Command deleteWaySegment(OsmDataLayer layer, WaySegment ws) { 444 463 if (ws.way.getNodesCount() < 3) 445 464 return delete(layer, Collections.singleton(ws.way), false); -
src/org/openstreetmap/josm/command/MoveCommand.java
diff --git a/src/org/openstreetmap/josm/command/MoveCommand.java b/src/org/openstreetmap/josm/command/MoveCommand.java index 65466ce..d4838b4 100644
a b public class MoveCommand extends Command { 244 244 return nodes; 245 245 } 246 246 247 /** 248 * Gets the offset. 249 * @return The current offset. 250 */ 251 protected EastNorth getOffset() { 252 return new EastNorth(x, y); 253 } 254 247 255 @Override 248 256 public int hashCode() { 249 257 return Objects.hash(super.hashCode(), nodes, startEN, x, y, backupX, backupY, oldState); -
src/org/openstreetmap/josm/command/RotateCommand.java
diff --git a/src/org/openstreetmap/josm/command/RotateCommand.java b/src/org/openstreetmap/josm/command/RotateCommand.java index c4fdc8e..2b4f17a 100644
a b public class RotateCommand extends TransformNodesCommand { 38 38 * @param objects objects to fetch nodes from 39 39 * @param currentEN cuurent eats/north 40 40 */ 41 public RotateCommand(Collection< OsmPrimitive> objects, EastNorth currentEN) {41 public RotateCommand(Collection<? extends OsmPrimitive> objects, EastNorth currentEN) { 42 42 super(objects); 43 43 44 44 pivot = getNodesCenter(); … … public class RotateCommand extends TransformNodesCommand { 70 70 } 71 71 72 72 /** 73 * Set the rotation angle. 74 * @param rotationAngle The rotate angle 75 */ 76 protected void setRotationAngle(double rotationAngle) { 77 this.rotationAngle = rotationAngle; 78 } 79 80 /** 73 81 * Rotate nodes. 74 82 */ 75 83 @Override 76 84 protected void transformNodes() { 85 double cosPhi = Math.cos(rotationAngle); 86 double sinPhi = Math.sin(rotationAngle); 77 87 for (Node n : nodes) { 78 double cosPhi = Math.cos(rotationAngle);79 double sinPhi = Math.sin(rotationAngle);80 88 EastNorth oldEastNorth = oldStates.get(n).getEastNorth(); 81 89 double x = oldEastNorth.east() - pivot.east(); 82 90 double y = oldEastNorth.north() - pivot.north(); -
src/org/openstreetmap/josm/command/ScaleCommand.java
diff --git a/src/org/openstreetmap/josm/command/ScaleCommand.java b/src/org/openstreetmap/josm/command/ScaleCommand.java index 2c7d043..a72c46d 100644
a b public class ScaleCommand extends TransformNodesCommand { 34 34 * @param objects objects to fetch nodes from 35 35 * @param currentEN cuurent eats/north 36 36 */ 37 public ScaleCommand(Collection< OsmPrimitive> objects, EastNorth currentEN) {37 public ScaleCommand(Collection<? extends OsmPrimitive> objects, EastNorth currentEN) { 38 38 super(objects); 39 39 40 40 pivot = getNodesCenter(); … … public class ScaleCommand extends TransformNodesCommand { 57 57 double endAngle = Math.atan2(currentEN.east()-pivot.east(), currentEN.north()-pivot.north()); 58 58 double startDistance = pivot.distance(startEN); 59 59 double currentDistance = pivot.distance(currentEN); 60 s calingFactor = Math.cos(startAngle-endAngle) * currentDistance / startDistance;60 setScalingFactor(Math.cos(startAngle-endAngle) * currentDistance / startDistance); 61 61 transformNodes(); 62 62 } 63 63 64 64 /** 65 * Set the scaling factor 66 * @param scalingFactor The scaling factor. 67 */ 68 protected void setScalingFactor(double scalingFactor) { 69 this.scalingFactor = scalingFactor; 70 } 71 72 /** 65 73 * Scale nodes. 66 74 */ 67 75 @Override -
src/org/openstreetmap/josm/command/SelectCommand.java
diff --git a/src/org/openstreetmap/josm/command/SelectCommand.java b/src/org/openstreetmap/josm/command/SelectCommand.java index d893d18..7d84315 100644
a b package org.openstreetmap.josm.command; 4 4 import static org.openstreetmap.josm.tools.I18n.trn; 5 5 6 6 import java.util.Collection; 7 import java.util.Collections; 8 import java.util.HashSet; 7 9 import java.util.Objects; 8 10 9 11 import org.openstreetmap.josm.Main; … … public class SelectCommand extends Command { 27 29 * @param newSelection the primitives to select when executing the command. 28 30 */ 29 31 public SelectCommand(Collection<OsmPrimitive> newSelection) { 30 this.newSelection = newSelection; 32 if (newSelection == null || newSelection.isEmpty()) { 33 this.newSelection = Collections.emptySet(); 34 } else { 35 this.newSelection = new HashSet<>(newSelection); 36 } 31 37 } 32 38 33 39 @Override -
src/org/openstreetmap/josm/command/TransformNodesCommand.java
diff --git a/src/org/openstreetmap/josm/command/TransformNodesCommand.java b/src/org/openstreetmap/josm/command/TransformNodesCommand.java index bade457..b27d525 100644
a b public abstract class TransformNodesCommand extends Command { 48 48 * Find out the impacted nodes and store their initial state. 49 49 * @param objects objects to fetch nodes from 50 50 */ 51 public TransformNodesCommand(Collection< OsmPrimitive> objects) {51 public TransformNodesCommand(Collection<? extends OsmPrimitive> objects) { 52 52 this.nodes = AllNodesVisitor.getAllNodes(objects); 53 53 storeOldState(); 54 54 } -
test/unit/org/openstreetmap/josm/command/AddCommandTest.java
diff --git a/test/unit/org/openstreetmap/josm/command/AddCommandTest.java b/test/unit/org/openstreetmap/josm/command/AddCommandTest.java index 1c7ab4c..fee2609 100644
a b 1 1 // License: GPL. For details, see LICENSE file. 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; 15 25 … … import nl.jqno.equalsverifier.Warning; 19 29 public class AddCommandTest { 20 30 21 31 /** 22 * Setup test. 32 * We need prefs for nodes. 33 */ 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 * @since xxx 41 */ 42 @Test 43 public void testAdd() { 44 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 45 Main.getLayerManager().addLayer(layer1); 46 assertArrayEquals(new Object[0], layer1.data.allPrimitives().toArray()); 47 48 Node osm = new Node(LatLon.ZERO); 49 assertTrue(new AddCommand(osm).executeCommand()); 50 51 assertArrayEquals(new Object[] {osm}, layer1.data.allPrimitives().toArray()); 52 assertArrayEquals(new Object[] {osm}, layer1.data.allModifiedPrimitives().toArray()); 53 assertTrue(osm.isModified()); 54 } 55 56 /** 57 * Tests if the add command respects the layer. 58 * @since xxx 59 */ 60 @Test 61 public void testAddToLayer() { 62 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 63 OsmDataLayer layer2 = new OsmDataLayer(new DataSet(), "l1", null); 64 65 Main.getLayerManager().addLayer(layer1); 66 Main.getLayerManager().addLayer(layer2); 67 68 Node osm = new Node(LatLon.ZERO); 69 assertTrue(new AddCommand(layer2, osm).executeCommand()); 70 71 assertArrayEquals(new Object[0], layer1.data.allPrimitives().toArray()); 72 assertArrayEquals(new Object[] {osm}, layer2.data.allPrimitives().toArray()); 73 } 74 75 /** 76 * Test {@link AddCommand#undoCommand()} 77 * @since xxx 23 78 */ 24 @BeforeClass 25 public static void setUpBeforeClass() { 26 JOSMFixture.createUnitTestFixture().init(false); 79 @Test 80 public void testUndo() { 81 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 82 Main.getLayerManager().addLayer(layer1); 83 Node osm = new Node(LatLon.ZERO); 84 layer1.data.addPrimitive(osm); 85 86 AddCommand command = new AddCommand(new Node(LatLon.ZERO)); 87 command.executeCommand(); 88 89 command.undoCommand(); 90 assertArrayEquals(new Object[] {osm}, layer1.data.allPrimitives().toArray()); 91 } 92 93 /** 94 * Test {@link AddCommand#getParticipatingPrimitives()} 95 * @since xxx 96 */ 97 @Test 98 public void testParticipatingPrimitives() { 99 Node osm = new Node(LatLon.ZERO); 100 101 assertArrayEquals(new Object[] {osm}, new AddCommand(osm).getParticipatingPrimitives().toArray()); 102 } 103 104 /** 105 * Tests {@link AddCommand#fillModifiedData(java.util.Collection, java.util.Collection, java.util.Collection)} 106 * @since xxx 107 */ 108 @Test 109 public void testFillModifiedData() { 110 Node osm = new Node(LatLon.ZERO); 111 112 ArrayList<OsmPrimitive> modified = new ArrayList<>(); 113 ArrayList<OsmPrimitive> deleted = new ArrayList<>(); 114 ArrayList<OsmPrimitive> added = new ArrayList<>(); 115 new AddCommand(osm).fillModifiedData(modified, deleted, added); 116 assertArrayEquals(new Object[] {}, modified.toArray()); 117 assertArrayEquals(new Object[] {}, deleted.toArray()); 118 assertArrayEquals(new Object[] {osm}, added.toArray()); 119 } 120 121 /** 122 * Test {@link AddCommand#getDescriptionText()} 123 * @since xxx 124 */ 125 @Test 126 public void testDescription() { 127 Node node = new Node(LatLon.ZERO); 128 node.put("name", "xy"); 129 Way way = new Way(); 130 way.addNode(node); 131 way.put("name", "xy"); 132 Relation relation = new Relation(); 133 relation.put("name", "xy"); 134 135 assertTrue(new AddCommand(node).getDescriptionText().matches("Add node.*xy.*")); 136 assertTrue(new AddCommand(way).getDescriptionText().matches("Add way.*xy.*")); 137 assertTrue(new AddCommand(relation).getDescriptionText().matches("Add relation.*xy.*")); 27 138 } 28 139 29 140 /** -
test/unit/org/openstreetmap/josm/command/AddPrimitivesCommandTest.java
diff --git a/test/unit/org/openstreetmap/josm/command/AddPrimitivesCommandTest.java b/test/unit/org/openstreetmap/josm/command/AddPrimitivesCommandTest.java index 04aab92..08f83ae 100644
a b 1 1 // License: GPL. For details, see LICENSE file. 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; 28 import org.openstreetmap.josm.testutils.JOSMTestRules; 10 29 30 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 11 31 import nl.jqno.equalsverifier.EqualsVerifier; 12 32 import nl.jqno.equalsverifier.Warning; 13 33 … … import nl.jqno.equalsverifier.Warning; 17 37 public class AddPrimitivesCommandTest { 18 38 19 39 /** 20 * Setup test. 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 * @since xxx 49 */ 50 @Test 51 public void testAdd() { 52 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 53 Main.getLayerManager().addLayer(layer1); 54 55 List<PrimitiveData> testData = createTestData(); 56 assertTrue(new AddPrimitivesCommand(testData).executeCommand()); 57 58 testContainsTestData(layer1); 59 assertEquals(3, layer1.data.getAllSelected().size()); 60 } 61 62 /** 63 * Test if the add command sets the selection. 64 * @since xxx 65 */ 66 @Test 67 public void testAddSetSelection() { 68 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 69 Main.getLayerManager().addLayer(layer1); 70 71 List<PrimitiveData> testData = createTestData(); 72 assertTrue(new AddPrimitivesCommand(testData, testData.subList(2, 3)).executeCommand()); 73 74 testContainsTestData(layer1); 75 76 assertEquals(1, layer1.data.getAllSelected().size()); 77 assertEquals(1, layer1.data.getSelectedWays().size()); 78 } 79 80 /** 81 * Tests if the add command respects the layer. 82 * @since xxx 21 83 */ 22 @BeforeClass 23 public static void setUpBeforeClass() { 24 JOSMFixture.createUnitTestFixture().init(false); 84 @Test 85 public void testAddToLayer() { 86 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 87 OsmDataLayer layer2 = new OsmDataLayer(new DataSet(), "l1", null); 88 89 Main.getLayerManager().addLayer(layer1); 90 Main.getLayerManager().addLayer(layer2); 91 92 List<PrimitiveData> testData = createTestData(); 93 assertTrue(new AddPrimitivesCommand(testData, testData.subList(2, 3), layer1).executeCommand()); 94 95 testContainsTestData(layer1); 96 assertTrue(layer2.data.allPrimitives().isEmpty()); 97 98 assertEquals(1, layer1.data.getAllSelected().size()); 99 assertEquals(1, layer1.data.getSelectedWays().size()); 100 } 101 102 /** 103 * Tests if the add command ignores existing data 104 * @since xxx 105 */ 106 @Test 107 public void testAddIgnoresExisting() { 108 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 109 Main.getLayerManager().addLayer(layer1); 110 111 List<PrimitiveData> testData = createTestData(); 112 assertTrue(new AddPrimitivesCommand(testData).executeCommand()); 113 assertEquals(2, layer1.data.getNodes().size()); 114 assertEquals(1, layer1.data.getWays().size()); 115 116 testData.set(2, createTestNode(7)); 117 assertTrue(new AddPrimitivesCommand(testData).executeCommand()); 118 119 assertEquals(3, layer1.data.getNodes().size()); 120 assertEquals(1, layer1.data.getWays().size()); 121 } 122 123 /** 124 * Test {@link AddPrimitivesCommand#getDescriptionText()} 125 * @since xxx 126 */ 127 @Test 128 public void testDescription() { 129 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 130 Main.getLayerManager().addLayer(layer1); 131 132 List<PrimitiveData> testData = createTestData(); 133 NodeData data2 = createTestNode(7); 134 135 AddPrimitivesCommand command1 = new AddPrimitivesCommand(testData); 136 AddPrimitivesCommand command2 = new AddPrimitivesCommand(Arrays.<PrimitiveData> asList(data2)); 137 138 assertEquals("Added 3 objects", command1.getDescriptionText()); 139 assertEquals("Added 1 object", command2.getDescriptionText()); 140 141 // Name must be the same after execution. 142 assertTrue(command1.executeCommand()); 143 assertTrue(command2.executeCommand()); 144 145 assertEquals("Added 3 objects", command1.getDescriptionText()); 146 assertEquals("Added 1 object", command2.getDescriptionText()); 147 } 148 149 /** 150 * Test {@link AddPrimitivesCommand#undoCommand()} 151 * @since xxx 152 */ 153 @Test 154 public void testUndo() { 155 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 156 Main.getLayerManager().addLayer(layer1); 157 158 List<PrimitiveData> testData = createTestData(); 159 160 AddPrimitivesCommand command = new AddPrimitivesCommand(testData); 161 162 assertTrue(command.executeCommand()); 163 164 assertEquals(3, layer1.data.allPrimitives().size()); 165 assertEquals(1, layer1.data.getWays().size()); 166 Way way = layer1.data.getWays().iterator().next(); 167 168 for (int i = 0; i < 2; i++) { 169 // Needs to work multiple times. 170 command.undoCommand(); 171 172 assertEquals(0, layer1.data.allPrimitives().size()); 173 assertEquals(0, layer1.data.getWays().size()); 174 175 // redo 176 assertTrue(command.executeCommand()); 177 178 assertEquals(3, layer1.data.allPrimitives().size()); 179 assertEquals(1, layer1.data.getWays().size()); 180 assertSame(way, layer1.data.getWays().iterator().next()); 181 } 182 } 183 184 /** 185 * Test {@link AddCommand#getParticipatingPrimitives()} 186 * @since xxx 187 */ 188 @Test 189 public void testParticipatingPrimitives() { 190 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 191 Main.getLayerManager().addLayer(layer1); 192 193 List<PrimitiveData> testData = createTestData(); 194 AddPrimitivesCommand command = new AddPrimitivesCommand(testData); 195 assertTrue(command.executeCommand()); 196 197 assertEquals(3, command.getParticipatingPrimitives().size()); 198 HashSet<OsmPrimitive> should = new HashSet<>(layer1.data.allPrimitives()); 199 assertEquals(should, new HashSet<>(command.getParticipatingPrimitives())); 200 201 // needs to be the same after undo 202 command.undoCommand(); 203 assertEquals(should, new HashSet<>(command.getParticipatingPrimitives())); 204 } 205 206 /** 207 * Tests {@link AddPrimitivesCommand#fillModifiedData(java.util.Collection, java.util.Collection, java.util.Collection)} 208 * @since xxx 209 */ 210 @Test 211 public void testFillModifiedData() { 212 ArrayList<OsmPrimitive> modified = new ArrayList<>(); 213 ArrayList<OsmPrimitive> deleted = new ArrayList<>(); 214 ArrayList<OsmPrimitive> added = new ArrayList<>(); 215 216 List<PrimitiveData> testData = createTestData(); 217 new AddPrimitivesCommand(testData).fillModifiedData(modified, deleted, added); 218 219 assertArrayEquals(new Object[] {}, modified.toArray()); 220 assertArrayEquals(new Object[] {}, deleted.toArray()); 221 assertArrayEquals(new Object[] {}, added.toArray()); 222 } 223 224 private void testContainsTestData(OsmDataLayer layer1) { 225 assertEquals(3, layer1.data.allPrimitives().size()); 226 assertEquals(2, layer1.data.getNodes().size()); 227 assertEquals(1, layer1.data.getWays().size()); 228 assertEquals(0, layer1.data.allModifiedPrimitives().size()); 229 for (OsmPrimitive n : layer1.data.allPrimitives()) { 230 assertEquals("test", n.get("test")); 231 assertFalse(n.isModified()); 232 } 233 234 for (Node n : layer1.data.getNodes()) { 235 assertEquals(LatLon.ZERO, n.getCoor()); 236 } 237 238 for (Way w : layer1.data.getWays()) { 239 assertEquals(2, w.getNodes().size()); 240 assertEquals(5, w.getNode(0).getId()); 241 assertEquals(6, w.getNode(1).getId()); 242 } 243 } 244 245 private List<PrimitiveData> createTestData() { 246 NodeData node1 = createTestNode(5); 247 NodeData node2 = createTestNode(6); 248 WayData way = new WayData(); 249 way.put("test", "test"); 250 way.setNodes(Arrays.asList(node1.getId(), node2.getId())); 251 List<PrimitiveData> testData = Arrays.<PrimitiveData> asList(node1, node2, way); 252 return testData; 253 } 254 255 private NodeData createTestNode(int id) { 256 NodeData node1 = new NodeData(); 257 node1.setCoor(LatLon.ZERO); 258 node1.put("test", "test"); 259 node1.setId(id); 260 return node1; 25 261 } 26 262 27 263 /** -
test/unit/org/openstreetmap/josm/command/ChangeCommandTest.java
diff --git a/test/unit/org/openstreetmap/josm/command/ChangeCommandTest.java b/test/unit/org/openstreetmap/josm/command/ChangeCommandTest.java index 6547e00..a901fbc 100644
a b 1 1 // License: GPL. For details, see LICENSE file. 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; 15 31 … … import nl.jqno.equalsverifier.Warning; 19 35 public class ChangeCommandTest { 20 36 21 37 /** 22 * Setup test. 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 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 * @since xxx 56 */ 57 @Test(expected = IllegalArgumentException.class) 58 public void testPreventEmptyWays() { 59 Way emptyWay = new Way(); 60 new ChangeCommand(testData.existingWay, emptyWay); 61 } 62 63 /** 64 * Test {@link ChangeCommand#executeCommand()} 65 * @since xxx 66 */ 67 @Test 68 public void testChange() { 69 Node newNode = new Node(5); 70 newNode.setCoor(LatLon.NORTH_POLE); 71 newNode.put("new", "new"); 72 73 new ChangeCommand(testData.existingNode, newNode).executeCommand(); 74 75 assertEquals("new", testData.existingNode.get("new")); 76 assertEquals(null, testData.existingNode.get("existing")); 77 assertEquals(LatLon.NORTH_POLE, testData.existingNode.getCoor()); 78 79 Way newWay = new Way(10); 80 List<Node> newNodes = testData.existingWay.getNodes(); 81 Collections.reverse(newNodes); 82 newWay.setNodes(newNodes); 83 84 new ChangeCommand(testData.existingWay, newWay).executeCommand(); 85 assertArrayEquals(newNodes.toArray(), testData.existingWay.getNodes().toArray()); 86 } 87 88 /** 89 * Test {@link ChangeCommand#executeCommand()} fails if ID is changed 90 * @since xxx 91 */ 92 @Test(expected = DataIntegrityProblemException.class) 93 public void testChangeIdChange() { 94 Node newNode = new Node(1); 95 newNode.setCoor(LatLon.NORTH_POLE); 96 97 new ChangeCommand(testData.existingNode, newNode).executeCommand(); 98 } 99 100 /** 101 * Test {@link ChangeCommand#undoCommand()} 102 * @since xxx 23 103 */ 24 @BeforeClass 25 public static void setUpBeforeClass() { 26 JOSMFixture.createUnitTestFixture().init(false); 104 @Test 105 public void testUndo() { 106 Node newNode = new Node(5); 107 newNode.setCoor(LatLon.NORTH_POLE); 108 newNode.put("new", "new"); 109 110 ChangeCommand command = new ChangeCommand(testData.existingNode, newNode); 111 command.executeCommand(); 112 113 assertEquals("new", testData.existingNode.get("new")); 114 assertEquals(LatLon.NORTH_POLE, testData.existingNode.getCoor()); 115 116 command.undoCommand(); 117 assertNull(testData.existingNode.get("new")); 118 assertEquals("existing", testData.existingNode.get("existing")); 119 assertEquals(LatLon.ZERO, testData.existingNode.getCoor()); 120 } 121 122 /** 123 * Tests {@link ChangeCommand#fillModifiedData(java.util.Collection, java.util.Collection, java.util.Collection)} 124 * @since xxx 125 */ 126 @Test 127 public void testFillModifiedData() { 128 ArrayList<OsmPrimitive> modified = new ArrayList<>(); 129 ArrayList<OsmPrimitive> deleted = new ArrayList<>(); 130 ArrayList<OsmPrimitive> added = new ArrayList<>(); 131 new ChangeCommand(testData.existingNode, testData.existingNode).fillModifiedData(modified, deleted, added); 132 assertArrayEquals(new Object[] { testData.existingNode }, modified.toArray()); 133 assertArrayEquals(new Object[] {}, deleted.toArray()); 134 assertArrayEquals(new Object[] {}, added.toArray()); 135 } 136 137 /** 138 * Test {@link ChangeCommand#getDescriptionText()} 139 * @since xxx 140 */ 141 @Test 142 public void testDescription() { 143 Node node = new Node(LatLon.ZERO); 144 node.put("name", "xy"); 145 Way way = new Way(); 146 way.addNode(node); 147 way.put("name", "xy"); 148 Relation relation = new Relation(); 149 relation.put("name", "xy"); 150 151 assertTrue(new ChangeCommand(node, node).getDescriptionText().matches("Change node.*xy.*")); 152 assertTrue(new ChangeCommand(way, way).getDescriptionText().matches("Change way.*xy.*")); 153 assertTrue(new ChangeCommand(relation, relation).getDescriptionText().matches("Change relation.*xy.*")); 27 154 } 28 155 29 156 /** -
test/unit/org/openstreetmap/josm/command/ChangeNodesCommandTest.java
diff --git a/test/unit/org/openstreetmap/josm/command/ChangeNodesCommandTest.java b/test/unit/org/openstreetmap/josm/command/ChangeNodesCommandTest.java index 6a82532..fb38f41 100644
a b 1 1 // License: GPL. For details, see LICENSE file. 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; 14 30 … … import nl.jqno.equalsverifier.Warning; 18 34 public class ChangeNodesCommandTest { 19 35 20 36 /** 21 * Setup test. 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(); 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. 22 54 */ 23 @BeforeClass 24 public static void setUpBeforeClass() { 25 JOSMFixture.createUnitTestFixture().init(false); 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 * @since xxx 95 */ 96 @Test 97 public void testFillModifiedData() { 98 ArrayList<OsmPrimitive> modified = new ArrayList<>(); 99 ArrayList<OsmPrimitive> deleted = new ArrayList<>(); 100 ArrayList<OsmPrimitive> added = new ArrayList<>(); 101 new ChangeNodesCommand(testData.existingWay, Arrays.asList(testData.existingNode)).fillModifiedData(modified, 102 deleted, added); 103 assertArrayEquals(new Object[] { testData.existingWay }, modified.toArray()); 104 assertArrayEquals(new Object[] {}, deleted.toArray()); 105 assertArrayEquals(new Object[] {}, added.toArray()); 106 } 107 108 /** 109 * Test {@link ChangeNodesCommand#getDescriptionText()} 110 * @since xxx 111 */ 112 @Test 113 public void testDescription() { 114 Node node = new Node(LatLon.ZERO); 115 node.put("name", "xy"); 116 Way way = new Way(); 117 way.addNode(node); 118 way.put("name", "xy"); 119 120 assertTrue( 121 new ChangeNodesCommand(way, Arrays.asList(node)).getDescriptionText().matches("Change nodes of.*xy.*")); 26 122 } 27 123 28 124 /** -
test/unit/org/openstreetmap/josm/command/ChangePropertyCommandTest.java
diff --git a/test/unit/org/openstreetmap/josm/command/ChangePropertyCommandTest.java b/test/unit/org/openstreetmap/josm/command/ChangePropertyCommandTest.java index be5e164..4695f2a 100644
a b 1 1 // License: GPL. For details, see LICENSE file. 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; 28 import org.openstreetmap.josm.testutils.JOSMTestRules; 10 29 30 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 11 31 import nl.jqno.equalsverifier.EqualsVerifier; 12 32 import nl.jqno.equalsverifier.Warning; 13 33 … … import nl.jqno.equalsverifier.Warning; 17 37 public class ChangePropertyCommandTest { 18 38 19 39 /** 20 * Setup test. 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 * @since xxx 58 */ 59 @Test 60 public void testShortConstructor() { 61 ChangePropertyCommand command = new ChangePropertyCommand(Arrays.asList(testData.existingNode), "a", "b"); 62 assertEquals("b", command.getTags().get("a")); 63 assertEquals(1, command.getTags().size()); 64 assertEquals(1, command.getObjectsNumber()); 65 66 command = new ChangePropertyCommand(testData.existingNode, "a", "b"); 67 assertEquals("b", command.getTags().get("a")); 68 assertEquals(1, command.getTags().size()); 69 assertEquals(1, command.getObjectsNumber()); 70 } 71 72 /** 73 * Checks that {@link ChangePropertyCommand} adds/updates a property 74 * @since xxx 75 */ 76 @Test 77 public void testUpdateSingleProperty() { 78 Node node1 = testData.createNode(14); 79 Node node2 = testData.createNode(15); 80 node2.removeAll(); 81 82 TagMap tags = new TagMap(); 83 tags.put("existing", "new"); 84 new ChangePropertyCommand(Arrays.<OsmPrimitive> asList(node1, node2), tags).executeCommand(); 85 assertEquals("new", node1.get("existing")); 86 assertEquals("new", node2.get("existing")); 87 88 assertTrue(node1.isModified()); 89 assertTrue(node2.isModified()); 90 } 91 92 /** 93 * Checks that {@link ChangePropertyCommand} removes a property 94 * @since xxx 95 */ 96 @Test 97 public void testRemoveProperty() { 98 Node node1 = testData.createNode(14); 99 Node node2 = testData.createNode(15); 100 node2.removeAll(); 101 102 HashMap<String, String> tags = new HashMap<>(); 103 tags.put("existing", ""); 104 new ChangePropertyCommand(Arrays.<OsmPrimitive> asList(node1, node2), tags).executeCommand(); 105 assertNull(node1.get("existing")); 106 assertNull(node2.get("existing")); 107 108 assertTrue(node1.isModified()); 109 assertFalse(node2.isModified()); 110 } 111 112 /** 113 * Checks that {@link ChangePropertyCommand} adds/updates multiple properties 114 * @since xxx 115 */ 116 @Test 117 public void testUpdateMultipleProperties() { 118 Node node1 = testData.createNode(14); 119 Node node2 = testData.createNode(15); 120 node2.removeAll(); 121 node2.put("test", "xx"); 122 node2.put("remove", "xx"); 123 124 HashMap<String, String> tags = new HashMap<>(); 125 tags.put("existing", "existing"); 126 tags.put("test", "test"); 127 tags.put("remove", ""); 128 new ChangePropertyCommand(Arrays.<OsmPrimitive> asList(node1, node2), tags).executeCommand(); 129 assertEquals("existing", node1.get("existing")); 130 assertEquals("existing", node2.get("existing")); 131 assertEquals("test", node1.get("test")); 132 assertEquals("test", node2.get("test")); 133 assertNull(node1.get("remove")); 134 assertNull(node2.get("remove")); 135 136 assertTrue(node1.isModified()); 137 assertTrue(node2.isModified()); 138 } 139 140 /** 141 * Checks that {@link ChangePropertyCommand} adds/updates a property 142 * @since xxx 21 143 */ 22 @BeforeClass 23 public static void setUpBeforeClass() { 24 JOSMFixture.createUnitTestFixture().init(false); 144 @Test 145 public void testUpdateIgnoresExistingProperty() { 146 Node node1 = testData.createNode(14); 147 Node node2 = testData.createNode(15); 148 node2.removeAll(); 149 150 TagMap tags = new TagMap(); 151 tags.put("existing", "existing"); 152 new ChangePropertyCommand(Arrays.<OsmPrimitive> asList(node1, node2), tags).executeCommand(); 153 assertEquals("existing", node1.get("existing")); 154 assertEquals("existing", node2.get("existing")); 155 156 assertFalse(node1.isModified()); 157 assertTrue(node2.isModified()); 158 } 159 160 /** 161 * Tests {@link ChangePropertyCommand#fillModifiedData(java.util.Collection, java.util.Collection, java.util.Collection)} 162 * and {@link ChangePropertyCommand#getObjectsNumber()} 163 * @since xxx 164 */ 165 @Test 166 public void testFillModifiedData() { 167 Node node1 = testData.createNode(14); 168 Node node2 = testData.createNode(15); 169 node2.put("existing", "new"); 170 171 TagMap tags = new TagMap(); 172 tags.put("existing", "new"); 173 174 ArrayList<OsmPrimitive> modified = new ArrayList<>(); 175 ArrayList<OsmPrimitive> deleted = new ArrayList<>(); 176 ArrayList<OsmPrimitive> added = new ArrayList<>(); 177 new ChangePropertyCommand(Arrays.asList(node1, node2), tags).fillModifiedData(modified, deleted, added); 178 assertArrayEquals(new Object[] { node1 }, modified.toArray()); 179 assertArrayEquals(new Object[] {}, deleted.toArray()); 180 assertArrayEquals(new Object[] {}, added.toArray()); 181 182 assertEquals(1, new ChangePropertyCommand(Arrays.asList(node1, node2), tags).getObjectsNumber()); 183 184 tags.clear(); 185 assertEquals(0, new ChangePropertyCommand(Arrays.asList(node1, node2), tags).getObjectsNumber()); 186 187 tags.put("a", "b"); 188 assertEquals(2, new ChangePropertyCommand(Arrays.asList(node1, node2), tags).getObjectsNumber()); 189 } 190 191 /** 192 * Test {@link ChangePropertyCommand#getDescriptionText()} 193 * @since xxx 194 */ 195 @Test 196 public void testDescription() { 197 Node node1 = testData.createNode(14); 198 Node node2 = testData.createNode(15); 199 Node node3 = testData.createNode(16); 200 node1.put("name", "xy"); 201 node2.put("existing", "new"); 202 node3.put("existing", null); 203 204 TagMap tags = new TagMap(); 205 tags.put("existing", "new"); 206 207 HashMap<String, String> tagsRemove = new HashMap<>(); 208 tagsRemove.put("existing", ""); 209 210 Way way = new Way(); 211 way.addNode(node1); 212 way.put("name", "xy"); 213 way.put("existing", "existing"); 214 Relation relation = new Relation(); 215 relation.put("name", "xy"); 216 relation.put("existing", "existing"); 217 218 // nop 219 assertTrue(new ChangePropertyCommand(Arrays.asList(node2), tags).getDescriptionText() 220 .matches("Set.*tags for 0 objects")); 221 222 // change 1 key on 1 element. 223 assertTrue(new ChangePropertyCommand(Arrays.asList(node1, node2), tags).getDescriptionText() 224 .matches("Set existing=new for node.*xy.*")); 225 assertTrue(new ChangePropertyCommand(Arrays.asList(way, node2), tags).getDescriptionText() 226 .matches("Set existing=new for way.*xy.*")); 227 assertTrue(new ChangePropertyCommand(Arrays.asList(relation, node2), tags).getDescriptionText() 228 .matches("Set existing=new for relation.*xy.*")); 229 230 // remove 1 key on 1 element 231 assertTrue(new ChangePropertyCommand(Arrays.asList(node1, node3), tagsRemove).getDescriptionText() 232 .matches("Remove \"existing\" for node.*xy.*")); 233 assertTrue(new ChangePropertyCommand(Arrays.asList(way, node3), tagsRemove).getDescriptionText() 234 .matches("Remove \"existing\" for way.*xy.*")); 235 assertTrue(new ChangePropertyCommand(Arrays.asList(relation, node3), tagsRemove).getDescriptionText() 236 .matches("Remove \"existing\" for relation.*xy.*")); 237 238 // change 1 key on 3 elements 239 assertEquals("Set existing=new for 3 objects", 240 new ChangePropertyCommand(Arrays.asList(node1, node2, way, relation), tags).getDescriptionText()); 241 // remove 1 key on 3 elements 242 assertEquals("Remove \"existing\" for 3 objects", 243 new ChangePropertyCommand(Arrays.asList(node1, node3, way, relation), tagsRemove).getDescriptionText()); 244 245 // add 2 keys on 3 elements 246 tags.put("name", "a"); 247 node2.put("name", "a"); 248 assertEquals("Set 2 tags for 3 objects", 249 new ChangePropertyCommand(Arrays.asList(node1, node2, way, relation), tags).getDescriptionText()); 250 251 tagsRemove.put("name", ""); 252 // remove 2 key on 3 elements 253 assertEquals("Deleted 2 tags for 3 objects", 254 new ChangePropertyCommand(Arrays.asList(node1, node3, way, relation), tagsRemove).getDescriptionText()); 255 } 256 257 /** 258 * Test {@link ChangePropertyCommand#getChildren()} 259 * @since xxx 260 */ 261 @Test 262 public void testChildren() { 263 Node node1 = testData.createNode(15); 264 Node node2 = testData.createNode(16); 265 node1.put("name", "node1"); 266 node2.put("name", "node2"); 267 268 assertNull(new ChangePropertyCommand(Arrays.asList(node1), "a", "b").getChildren()); 269 270 Collection<PseudoCommand> children = new ChangePropertyCommand(Arrays.asList(node1, node2), "a", "b").getChildren(); 271 assertEquals(2, children.size()); 272 List<Node> nodesToExpect = new ArrayList<>(Arrays.asList(node1, node2)); 273 for (PseudoCommand c : children) { 274 assertNull(c.getChildren()); 275 Collection<? extends OsmPrimitive> part = c.getParticipatingPrimitives(); 276 assertEquals(1, part.size()); 277 OsmPrimitive node = part.iterator().next(); 278 assertTrue(nodesToExpect.remove(node)); 279 280 assertTrue(c.getDescriptionText().matches(".*" + node.get("name") + ".*")); 281 } 25 282 } 26 283 27 284 /** -
test/unit/org/openstreetmap/josm/command/ChangePropertyKeyCommandTest.java
diff --git a/test/unit/org/openstreetmap/josm/command/ChangePropertyKeyCommandTest.java b/test/unit/org/openstreetmap/josm/command/ChangePropertyKeyCommandTest.java index c01687e..89d4ce5 100644
a b 1 1 // License: GPL. For details, see LICENSE file. 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; 13 27 … … import nl.jqno.equalsverifier.Warning; 17 31 public class ChangePropertyKeyCommandTest { 18 32 19 33 /** 20 * Setup test. 34 * We need prefs for nodes. 35 */ 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 * @since xxx 52 */ 53 @Test 54 public void testChangeKeySingle() { 55 assertTrue(new ChangePropertyKeyCommand(testData.existingNode, "existing", "newKey").executeCommand()); 56 57 assertNull(testData.existingNode.get("existing")); 58 assertEquals("existing", testData.existingNode.get("newKey")); 59 assertTrue(testData.existingNode.isModified()); 60 } 61 62 /** 63 * Tests that a key is changed. 64 * @since xxx 65 */ 66 @Test 67 public void testChangeKey() { 68 assertTrue(new ChangePropertyKeyCommand(Arrays.asList(testData.existingNode, testData.existingWay), "existing", 69 "newKey").executeCommand()); 70 71 assertNull(testData.existingNode.get("existing")); 72 assertEquals("existing", testData.existingNode.get("newKey")); 73 assertTrue(testData.existingNode.isModified()); 74 assertNull(testData.existingWay.get("existing")); 75 assertEquals("existing", testData.existingWay.get("newKey")); 76 assertTrue(testData.existingWay.isModified()); 77 } 78 79 /** 80 * Tests that nop operations are ignored. 81 * @since xxx 21 82 */ 22 @BeforeClass 23 public static void setUpBeforeClass() { 24 JOSMFixture.createUnitTestFixture().init(false); 83 @Test 84 public void testChangeKeyIgnored() { 85 Node node1 = testData.createNode(15); 86 node1.removeAll(); 87 Node node2 = testData.createNode(16); 88 Node node3 = testData.createNode(17); 89 90 assertTrue(new ChangePropertyKeyCommand(Arrays.asList(node1, node2), "nonexisting", "newKey").executeCommand()); 91 92 assertFalse(node1.isModified()); 93 assertFalse(node2.isModified()); 94 95 assertTrue(new ChangePropertyKeyCommand(Arrays.asList(node1, node2), "existing", "newKey").executeCommand()); 96 97 assertFalse(node1.isModified()); 98 assertTrue(node2.isModified()); 99 100 // removes existing 101 assertTrue(new ChangePropertyKeyCommand(Arrays.asList(node1, node3), "newKey", "existing").executeCommand()); 102 103 assertFalse(node1.isModified()); 104 assertTrue(node3.isModified()); 105 assertNull(node3.get("newKey")); 106 assertNull(node3.get("existing")); 107 } 108 109 /** 110 * Test {@link ChangePropertyKeyCommand#getDescriptionText()} 111 * @since xxx 112 */ 113 @Test 114 public void testDescription() { 115 Node node1 = testData.createNode(15); 116 node1.put("name", "xy"); 117 118 assertTrue(new ChangePropertyKeyCommand(node1, "a", "b").getDescriptionText() 119 .matches("Replace \"a\" by \"b\" for.*xy.*")); 120 assertTrue(new ChangePropertyKeyCommand(Arrays.asList(node1, testData.existingNode), "a", "b") 121 .getDescriptionText().matches("Replace \"a\" by \"b\" for 2 objects")); 122 } 123 124 /** 125 * Test {@link ChangePropertyCommand#getChildren()} 126 * @since xxx 127 */ 128 @Test 129 public void testChildren() { 130 Node node1 = testData.createNode(15); 131 Node node2 = testData.createNode(16); 132 node1.put("name", "node1"); 133 node2.put("name", "node2"); 134 135 ArrayList<Node> nodesToExpect = new ArrayList<>(Arrays.asList(node1, node2)); 136 137 assertNull(new ChangePropertyKeyCommand(node1, "a", "b").getChildren()); 138 Collection<PseudoCommand> children = new ChangePropertyKeyCommand(Arrays.asList(node1, node2), "a", "b").getChildren(); 139 assertEquals(2, children.size()); 140 for (PseudoCommand c : children) { 141 assertNull(c.getChildren()); 142 Collection<? extends OsmPrimitive> part = c.getParticipatingPrimitives(); 143 assertEquals(1, part.size()); 144 OsmPrimitive node = part.iterator().next(); 145 assertTrue(nodesToExpect.remove(node)); 146 147 assertTrue(c.getDescriptionText().contains(node.getName())); 148 } 25 149 } 26 150 27 151 /** -
test/unit/org/openstreetmap/josm/command/ChangeRelationMemberRoleCommandTest.java
diff --git a/test/unit/org/openstreetmap/josm/command/ChangeRelationMemberRoleCommandTest.java b/test/unit/org/openstreetmap/josm/command/ChangeRelationMemberRoleCommandTest.java index 57db8a4..fba4d65 100644
a b 1 1 // License: GPL. For details, see LICENSE file. 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; 14 26 … … import nl.jqno.equalsverifier.Warning; 18 30 public class ChangeRelationMemberRoleCommandTest { 19 31 20 32 /** 21 * Setup test. 33 * We need prefs for nodes. 34 */ 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 * @since xxx 51 */ 52 @Test 53 public void testRoleChanged() { 54 assertTrue(new ChangeRelationMemberRoleCommand(testData.existingRelation, 0, "newRole").executeCommand()); 55 assertEquals("newRole", testData.existingRelation.getMember(0).getRole()); 56 assertEquals(testData.existingNode, testData.existingRelation.getMember(0).getMember()); 57 assertEquals("way", testData.existingRelation.getMember(1).getRole()); 58 59 assertTrue(testData.existingRelation.isModified()); 60 61 assertTrue(new ChangeRelationMemberRoleCommand(testData.existingRelation, 1, "newRole").executeCommand()); 62 assertEquals("newRole", testData.existingRelation.getMember(1).getRole()); 63 } 64 65 /** 66 * Wrong index should be ignored. 67 * @since xxx 68 */ 69 @Test 70 public void testWrongIndex() { 71 // should be ignored 72 ChangeRelationMemberRoleCommand command1 = new ChangeRelationMemberRoleCommand(testData.existingRelation, -1, "newRole"); 73 assertTrue(command1.executeCommand()); 74 ChangeRelationMemberRoleCommand command2 = new ChangeRelationMemberRoleCommand(testData.existingRelation, 8, "newRole"); 75 assertTrue(command2.executeCommand()); 76 assertFalse(testData.existingRelation.isModified()); 77 78 command1.undoCommand(); 79 command2.undoCommand(); 80 assertFalse(testData.existingRelation.isModified()); 81 } 82 83 84 /** 85 * Same role should be ignored. 86 * @since xxx 22 87 */ 23 @BeforeClass 24 public static void setUpBeforeClass() { 25 JOSMFixture.createUnitTestFixture().init(false); 88 @Test 89 public void testSameRole() { 90 // should be ignored 91 assertTrue(new ChangeRelationMemberRoleCommand(testData.existingRelation, 0, "node").executeCommand()); 92 assertFalse(testData.existingRelation.isModified()); 93 } 94 95 /** 96 * Test {@link ChangeRelationMemberRoleCommand#undoCommand()}. 97 * @since xxx 98 */ 99 @Test 100 public void testUndo() { 101 ChangeRelationMemberRoleCommand command = new ChangeRelationMemberRoleCommand(testData.existingRelation, 0, "newRole"); 102 command.executeCommand(); 103 assertEquals("newRole", testData.existingRelation.getMember(0).getRole()); 104 assertTrue(testData.existingRelation.isModified()); 105 106 command.undoCommand(); 107 assertEquals("node", testData.existingRelation.getMember(0).getRole()); 108 assertFalse(testData.existingRelation.isModified()); 109 110 command.executeCommand(); 111 assertEquals("newRole", testData.existingRelation.getMember(0).getRole()); 112 assertTrue(testData.existingRelation.isModified()); 113 } 114 115 /** 116 * Tests {@link ChangeCommand#fillModifiedData(java.util.Collection, java.util.Collection, java.util.Collection)} 117 * @since xxx 118 */ 119 @Test 120 public void testFillModifiedData() { 121 ArrayList<OsmPrimitive> modified = new ArrayList<>(); 122 ArrayList<OsmPrimitive> deleted = new ArrayList<>(); 123 ArrayList<OsmPrimitive> added = new ArrayList<>(); 124 new ChangeRelationMemberRoleCommand(testData.existingRelation, 0, "newRole").fillModifiedData(modified, deleted, added); 125 assertArrayEquals(new Object[] { testData.existingRelation }, modified.toArray()); 126 assertArrayEquals(new Object[] {}, deleted.toArray()); 127 assertArrayEquals(new Object[] {}, added.toArray()); 128 } 129 130 /** 131 * Test {@link ChangeRelationMemberRoleCommand#getDescriptionText()} 132 * @since xxx 133 */ 134 @Test 135 public void testDescription() { 136 testData.existingRelation.put("name", "xy"); 137 assertTrue(new ChangeRelationMemberRoleCommand(testData.existingRelation, 0, "newRole").getDescriptionText().matches("Change relation member role for relation.*xy.*")); 138 } 139 140 /** 141 * Test {@link ChangeRelationMemberRoleCommand#getChildren()} 142 * @since xxx 143 */ 144 @Test 145 public void testChildren() { 146 assertNull(new ChangeRelationMemberRoleCommand(testData.existingRelation, 0, "newRole").getChildren()); 26 147 } 27 148 28 149 /** -
test/unit/org/openstreetmap/josm/command/CommandTest.java
diff --git a/test/unit/org/openstreetmap/josm/command/CommandTest.java b/test/unit/org/openstreetmap/josm/command/CommandTest.java index 7155ca2..439a510 100644
a b 1 1 // License: GPL. For details, see LICENSE file. 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; 24 import org.openstreetmap.josm.testutils.JOSMTestRules; 10 25 26 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 11 27 import nl.jqno.equalsverifier.EqualsVerifier; 12 28 import nl.jqno.equalsverifier.Warning; 13 29 … … import nl.jqno.equalsverifier.Warning; 17 33 public class CommandTest { 18 34 19 35 /** 20 * Setup test. 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. 21 45 */ 22 @BeforeClass 23 public static void setUpBeforeClass() { 24 JOSMFixture.createUnitTestFixture().init(false); 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 * @since xxx 54 */ 55 @Test 56 public void testInvalidBecauselayerRemoved() { 57 OsmDataLayer layer2 = new OsmDataLayer(new DataSet(), "test", null); 58 59 Command command = new NopCommand(); 60 assertFalse(command.invalidBecauselayerRemoved(layer2)); 61 assertTrue(command.invalidBecauselayerRemoved(testData.layer)); 62 63 Command command2 = new NopCommand(layer2); 64 assertTrue(command2.invalidBecauselayerRemoved(layer2)); 65 assertFalse(command2.invalidBecauselayerRemoved(testData.layer)); 66 } 67 68 /** 69 * Test {@link Command#getLayer()} 70 * @since xxx 71 */ 72 @Test 73 public void testGetLayer() { 74 OsmDataLayer layer2 = new OsmDataLayer(new DataSet(), "test", null); 75 Command command = new NopCommand(); 76 Command command2 = new NopCommand(layer2); 77 assertSame(testData.layer, command.getLayer()); 78 assertSame(layer2, command2.getLayer()); 25 79 } 26 80 27 81 /** … … public class CommandTest { 39 93 .suppress(Warning.NONFINAL_FIELDS) 40 94 .verify(); 41 95 } 96 97 private static final class NopCommand extends Command { 98 public NopCommand() { 99 super(); 100 } 101 102 public NopCommand(OsmDataLayer layer) { 103 super(layer); 104 } 105 106 @Override 107 public String getDescriptionText() { 108 return ""; 109 } 110 111 @Override 112 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, 113 Collection<OsmPrimitive> added) { 114 // nop 115 } 116 } 117 118 /** 119 * A change test data consisting of two nodes and a way. 120 * @author Michael Zangl 121 * @since xxx 122 */ 123 public static class CommandTestData { 124 /** 125 * A test layer 126 */ 127 public final OsmDataLayer layer; 128 /** 129 * A test node 130 */ 131 public final Node existingNode; 132 /** 133 * A second test node 134 */ 135 public final Node existingNode2; 136 /** 137 * A test way 138 */ 139 public final Way existingWay; 140 141 /** 142 * Creates the new test data and adds {@link #layer} to the layer manager. 143 */ 144 public CommandTestData() { 145 layer = new OsmDataLayer(new DataSet(), "layer", null); 146 Main.getLayerManager().addLayer(layer); 147 148 existingNode = createNode(5); 149 existingNode2 = createNode(6); 150 151 existingWay = createWay(10, existingNode, existingNode2); 152 } 153 154 /** 155 * Create and add a new test node. 156 * @param id the id 157 * @return The node. 158 */ 159 public Node createNode(long id) { 160 Node node = new Node(); 161 node.setOsmId(id, 1); 162 node.setCoor(LatLon.ZERO); 163 node.put("existing", "existing"); 164 layer.data.addPrimitive(node); 165 return node; 166 } 167 168 /** 169 * Create and add a new test way. 170 * @param id the id 171 * @param nodes The nodes 172 * @return The way. 173 */ 174 public Way createWay(int id, Node...nodes) { 175 Way way = new Way(); 176 way.setOsmId(id, 1); 177 way.setNodes(Arrays.asList(nodes)); 178 way.put("existing", "existing"); 179 layer.data.addPrimitive(way); 180 return way; 181 } 182 183 /** 184 * Create and add a new test relation. 185 * @param id the id 186 * @param members The members 187 * @return The relation. 188 */ 189 public Relation createRelation(int id, RelationMember...members) { 190 Relation relation = new Relation(id, 1); 191 for (RelationMember member : members) { 192 relation.addMember(member); 193 } 194 relation.put("existing", "existing"); 195 layer.data.addPrimitive(relation); 196 return relation; 197 } 198 } 199 200 /** 201 * A change test data consisting of two nodes, a way and a relation. 202 * @author Michael Zangl 203 * @since xxx 204 */ 205 public static class CommandTestDataWithRelation extends CommandTestData { 206 /** 207 * A test relation 208 */ 209 public final Relation existingRelation; 210 211 /** 212 * Creates the new test data and adds {@link #layer} to the layer manager. 213 */ 214 public CommandTestDataWithRelation() { 215 existingRelation = createRelation(20, new RelationMember("node", existingNode), new RelationMember("way", existingWay)); 216 } 217 } 42 218 } -
test/unit/org/openstreetmap/josm/command/DeleteCommandTest.java
diff --git a/test/unit/org/openstreetmap/josm/command/DeleteCommandTest.java b/test/unit/org/openstreetmap/josm/command/DeleteCommandTest.java index 0b8035c..e5df8f5 100644
a b 1 1 // License: GPL. For details, see LICENSE file. 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; 26 import org.openstreetmap.josm.testutils.JOSMTestRules; 10 27 28 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 11 29 import nl.jqno.equalsverifier.EqualsVerifier; 12 30 import nl.jqno.equalsverifier.Warning; 13 31 … … import nl.jqno.equalsverifier.Warning; 17 35 public class DeleteCommandTest { 18 36 19 37 /** 20 * Setup test. 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 * @since xxx 56 */ 57 @Test 58 public void testSimpleDelete() { 59 Node node = testData.createNode(15); 60 assertTrue(testData.layer.data.allPrimitives().contains(node)); 61 62 new DeleteCommand(node).executeCommand(); 63 64 assertTrue(node.isDeleted()); 65 assertTrue(node.isModified()); 66 assertFalse(testData.layer.data.allNonDeletedPrimitives().contains(node)); 67 } 68 69 /** 70 * A delete should not delete refered objects but should should remove the reference. 71 * @since xxx 72 */ 73 @Test 74 public void testDeleteIgnoresReferences() { 75 assertTrue(testData.existingNode.getReferrers().contains(testData.existingRelation)); 76 new DeleteCommand(testData.existingRelation).executeCommand(); 77 78 assertTrue(testData.existingRelation.isDeleted()); 79 assertEquals(0, testData.existingRelation.getMembersCount()); 80 assertFalse(testData.existingNode.isDeleted()); 81 assertFalse(testData.existingWay.isDeleted()); 82 assertFalse(testData.existingNode.getReferrers().contains(testData.existingRelation)); 83 84 // same for the way 85 assertTrue(testData.existingNode.getReferrers().contains(testData.existingWay)); 86 new DeleteCommand(testData.existingWay).executeCommand(); 87 assertEquals(0, testData.existingWay.getNodesCount()); 88 assertFalse(testData.existingNode.getReferrers().contains(testData.existingWay)); 89 } 90 91 /** 92 * A delete should delete all objects with references to the deleted one 93 * @since xxx 94 */ 95 @Test(expected = IllegalArgumentException.class) 96 public void testDeleteFailsOnDelted() { 97 new DeleteCommand(testData.existingRelation).executeCommand(); 98 99 new DeleteCommand(testData.existingRelation).executeCommand(); 100 } 101 102 /** 103 * A delete should delete all objects with references to the deleted one 104 * @since xxx 105 */ 106 @Test 107 public void testReferedDelete() { 108 DeleteCommand.deleteWithReferences(testData.layer, Arrays.asList(testData.existingNode), true).executeCommand(); 109 110 assertTrue(testData.existingNode.isDeleted()); 111 assertEquals(0, testData.existingWay.getNodesCount()); 112 assertTrue(testData.existingWay.isDeleted()); 113 } 114 115 /** 116 * Delete nodes that would be without reference afterwards. 117 * @since xxx 118 */ 119 @Test 120 public void testDelteNodesInWay() { 121 testData.existingNode.removeAll(); 122 // That untagged node should be deleted. 123 testData.existingNode2.removeAll(); 124 DeleteCommand.delete(testData.layer, Arrays.asList(testData.existingWay), true, true).executeCommand(); 125 126 assertTrue(testData.existingWay.isDeleted()); 127 assertTrue(testData.existingNode2.isDeleted()); 128 assertFalse(testData.existingNode.isDeleted()); 129 assertFalse(testData.existingRelation.isDeleted()); 130 131 // Same test, now with tagged nodes 132 Node node1 = testData.createNode(15); 133 Node node2 = testData.createNode(16); 134 Node node3 = testData.createNode(17); 135 Node node4 = testData.createNode(18); 136 node2.removeAll(); 137 node4.removeAll(); 138 Way way1 = new Way(25, 1); 139 way1.setNodes(Arrays.asList(node1, node2, node3)); 140 testData.layer.data.addPrimitive(way1); 141 Way way2 = new Way(26, 1); 142 way2.setNodes(Arrays.asList(node2, node3, node4)); 143 testData.layer.data.addPrimitive(way2); 144 DeleteCommand.delete(testData.layer, Arrays.asList(way1, way2), true, true).executeCommand(); 145 146 assertTrue(way1.isDeleted()); 147 assertTrue(way2.isDeleted()); 148 assertFalse(node1.isDeleted()); 149 assertTrue(node2.isDeleted()); 150 assertFalse(node3.isDeleted()); 151 assertTrue(node4.isDeleted()); 152 } 153 154 /** 155 * Test that {@link DeleteCommand} checks for non-null. 156 * @since xxx 157 */ 158 @Test(expected = IllegalArgumentException.class) 159 public void testConsistency() { 160 new DeleteCommand(Arrays.asList(testData.existingNode, testData.existingWay, null)); 161 } 162 163 /** 164 * Test that {@link DeleteCommand} checks for the dataset 165 * @since xxx 166 */ 167 @Test(expected = IllegalArgumentException.class) 168 public void testConsistencyDataset() { 169 testData.layer.data.removePrimitive(testData.existingNode); 170 new DeleteCommand(Arrays.asList(testData.existingNode, testData.existingWay)); 171 } 172 173 /** 174 * Test that {@link DeleteCommand} checks for non-empty list 175 * @since xxx 176 */ 177 @Test(expected = IllegalArgumentException.class) 178 public void testConsistencyNonEmpty() { 179 new DeleteCommand(Arrays.<OsmPrimitive> asList()); 180 } 181 182 /** 183 * Test that {@link DeleteCommand} checks for non-null list 184 * @since xxx 185 */ 186 @Test(expected = IllegalArgumentException.class) 187 public void testConsistencyNonNull() { 188 new DeleteCommand((Collection<OsmPrimitive>) null); 189 } 190 191 /** 192 * Test {@link DeleteCommand#undoCommand()} 193 * @since xxx 194 */ 195 @Test 196 public void testUndo() { 197 DeleteCommand command = new DeleteCommand( 198 Arrays.asList(testData.existingNode, testData.existingNode2, testData.existingWay)); 199 command.executeCommand(); 200 201 assertTrue(testData.existingNode.isDeleted()); 202 assertTrue(testData.existingWay.isDeleted()); 203 204 command.undoCommand(); 205 206 assertFalse(testData.existingNode.isDeleted()); 207 assertFalse(testData.existingWay.isDeleted()); 208 assertEquals("existing", testData.existingNode.get("existing")); 209 210 command.executeCommand(); 211 212 assertTrue(testData.existingNode.isDeleted()); 213 assertTrue(testData.existingWay.isDeleted()); 214 } 215 216 /** 217 * Test {@link DeleteCommand#deleteWaySegment(OsmDataLayer, org.openstreetmap.josm.data.osm.WaySegment)} 218 * Way with only 1 segment 219 * @since xxx 220 */ 221 @Test 222 public void testDeleteWaySegment() { 223 Way way1 = testData.createWay(100, testData.createNode(101), testData.createNode(102)); 224 WaySegment ws = new WaySegment(way1, 0); 225 Command command = DeleteCommand.deleteWaySegment(testData.layer, ws); 226 command.executeCommand(); 227 228 assertTrue(way1.isDeleted()); 229 } 230 231 /** 232 * Test {@link DeleteCommand#deleteWaySegment(OsmDataLayer, org.openstreetmap.josm.data.osm.WaySegment)} 233 * Delete end of way 234 * @since xxx 21 235 */ 22 @BeforeClass 23 public static void setUpBeforeClass() { 24 JOSMFixture.createUnitTestFixture().init(false); 236 @Test 237 public void testDeleteWaySegmentEndOfWay() { 238 Way way = testData.createWay(200, testData.createNode(201), testData.createNode(202), testData.createNode(203), 239 testData.createNode(204)); 240 WaySegment ws = new WaySegment(way, 2); 241 Command command = DeleteCommand.deleteWaySegment(testData.layer, ws); 242 command.executeCommand(); 243 244 assertEquals(3, way.getNodesCount()); 245 assertEquals(201, way.getNodeId(0)); 246 assertEquals(202, way.getNodeId(1)); 247 assertEquals(203, way.getNodeId(2)); 248 } 249 250 /** 251 * Test {@link DeleteCommand#deleteWaySegment(OsmDataLayer, org.openstreetmap.josm.data.osm.WaySegment)} 252 * Delete start of way 253 * @since xxx 254 */ 255 @Test 256 public void testDeleteWaySegmentStartOfWay() { 257 Way way = testData.createWay(100, testData.createNode(101), testData.createNode(102), testData.createNode(103), 258 testData.createNode(104)); 259 WaySegment ws = new WaySegment(way, 0); 260 Command command = DeleteCommand.deleteWaySegment(testData.layer, ws); 261 command.executeCommand(); 262 263 assertEquals(3, way.getNodesCount()); 264 assertEquals(102, way.getNodeId(0)); 265 assertEquals(103, way.getNodeId(1)); 266 assertEquals(104, way.getNodeId(2)); 267 } 268 269 /** 270 * Test {@link DeleteCommand#deleteWaySegment(OsmDataLayer, org.openstreetmap.josm.data.osm.WaySegment)} 271 * Delete start of way 272 * @since xxx 273 */ 274 @Test 275 public void testDeleteWaySegmentSplit() { 276 Node node103 = testData.createNode(103); 277 Node node104 = testData.createNode(104); 278 Way way = testData.createWay(100, testData.createNode(101), testData.createNode(102), node103, node104); 279 WaySegment ws = new WaySegment(way, 1); 280 Command command = DeleteCommand.deleteWaySegment(testData.layer, ws); 281 command.executeCommand(); 282 283 assertEquals(2, way.getNodesCount()); 284 assertEquals(101, way.getNodeId(0)); 285 assertEquals(102, way.getNodeId(1)); 286 // there needs to be a new way 287 assertEquals(1, node104.getReferrers().size()); 288 Way newWay = (Way) node104.getReferrers().get(0); 289 assertEquals(2, newWay.getNodesCount()); 290 assertEquals(103, newWay.getNodeId(0)); 291 assertEquals(104, newWay.getNodeId(1)); 292 } 293 294 /** 295 * Test {@link DeleteCommand#deleteWaySegment(OsmDataLayer, org.openstreetmap.josm.data.osm.WaySegment)} 296 * Delete start of way 297 * @since xxx 298 */ 299 @Test 300 public void testDeleteWaySegmentCycle() { 301 Node n = testData.createNode(101); 302 Way way = testData.createWay(100, n, testData.createNode(102), testData.createNode(103), 303 testData.createNode(104), n); 304 WaySegment ws = new WaySegment(way, 2); 305 Command command = DeleteCommand.deleteWaySegment(testData.layer, ws); 306 command.executeCommand(); 307 308 assertEquals(4, way.getNodesCount()); 309 assertEquals(104, way.getNodeId(0)); 310 assertEquals(101, way.getNodeId(1)); 311 assertEquals(102, way.getNodeId(2)); 312 assertEquals(103, way.getNodeId(3)); 313 } 314 315 /** 316 * Tests {@link DeleteCommand#getChildren()} 317 * @since xxx 318 */ 319 @Test 320 public void testGetChildren() { 321 testData.existingNode.put("name", "xy"); 322 Collection<PseudoCommand> children = new DeleteCommand(Arrays.<OsmPrimitive> asList(testData.existingNode, testData.existingNode2)).getChildren(); 323 assertEquals(2, children.size()); 324 assertTrue(children.stream().allMatch(c -> c.getParticipatingPrimitives().size() == 1)); 325 assertTrue(children.stream().anyMatch(c -> c.getParticipatingPrimitives().iterator().next() == testData.existingNode)); 326 assertTrue(children.stream().anyMatch(c -> c.getParticipatingPrimitives().iterator().next() == testData.existingNode2)); 327 assertTrue(children.stream().anyMatch(c -> c.getDescriptionText().matches("Deleted '.*xy.*'"))); 328 } 329 330 /** 331 * Tests {@link DeleteCommand#fillModifiedData(java.util.Collection, java.util.Collection, java.util.Collection)} 332 * @since xxx 333 */ 334 @Test 335 public void testFillModifiedData() { 336 ArrayList<OsmPrimitive> modified = new ArrayList<>(); 337 ArrayList<OsmPrimitive> deleted = new ArrayList<>(); 338 ArrayList<OsmPrimitive> added = new ArrayList<>(); 339 new DeleteCommand(Arrays.<OsmPrimitive> asList(testData.existingNode)).fillModifiedData(modified, deleted, 340 added); 341 // intentionally left empty. 342 assertArrayEquals(new Object[] {}, modified.toArray()); 343 assertArrayEquals(new Object[] {}, deleted.toArray()); 344 assertArrayEquals(new Object[] {}, added.toArray()); 345 } 346 347 /** 348 * Tests {@link DeleteCommand#getParticipatingPrimitives()} 349 * @since xxx 350 */ 351 @Test 352 public void testGetParticipatingPrimitives() { 353 DeleteCommand command = new DeleteCommand(Arrays.<OsmPrimitive> asList(testData.existingNode)); 354 assertArrayEquals(new Object[] { testData.existingNode }, command.getParticipatingPrimitives().toArray()); 355 356 DeleteCommand command2 = new DeleteCommand( 357 Arrays.<OsmPrimitive> asList(testData.existingNode, testData.existingWay)); 358 assertArrayEquals(new Object[] { testData.existingNode, testData.existingWay }, 359 command2.getParticipatingPrimitives().toArray()); 360 } 361 362 /** 363 * Test {@link DeleteCommand#getDescriptionText()} 364 * @since xxx 365 */ 366 @Test 367 public void testDescription() { 368 Node node = testData.createNode(100); 369 node.put("name", "xy"); 370 Way way = testData.createWay(101); 371 way.put("name", "xy"); 372 Relation relation = testData.createRelation(102); 373 relation.put("name", "xy"); 374 375 List<OsmPrimitive> nodeList = Arrays.<OsmPrimitive> asList(node); 376 assertTrue(new DeleteCommand(nodeList).getDescriptionText().matches("Delete node .*xy.*")); 377 List<OsmPrimitive> wayList = Arrays.<OsmPrimitive> asList(way); 378 assertTrue(new DeleteCommand(wayList).getDescriptionText().matches("Delete way .*xy.*")); 379 List<OsmPrimitive> relationList = Arrays.<OsmPrimitive> asList(relation); 380 assertTrue(new DeleteCommand(relationList).getDescriptionText().matches("Delete relation .*xy.*")); 381 382 List<OsmPrimitive> nodesList = Arrays.<OsmPrimitive> asList(node, testData.createNode(110)); 383 assertTrue(new DeleteCommand(nodesList).getDescriptionText().matches("Delete 2 nodes")); 384 List<OsmPrimitive> waysList = Arrays.<OsmPrimitive> asList(way, testData.createWay(111)); 385 assertTrue(new DeleteCommand(waysList).getDescriptionText().matches("Delete 2 ways")); 386 List<OsmPrimitive> relationsList = Arrays.<OsmPrimitive> asList(relation, testData.createRelation(112)); 387 assertTrue(new DeleteCommand(relationsList).getDescriptionText().matches("Delete 2 relations")); 388 389 List<OsmPrimitive> mixed = Arrays.<OsmPrimitive> asList(node, way, relation); 390 assertTrue(new DeleteCommand(mixed).getDescriptionText().matches("Delete 3 objects")); 25 391 } 26 392 27 393 /** -
test/unit/org/openstreetmap/josm/command/MoveCommandTest.java
diff --git a/test/unit/org/openstreetmap/josm/command/MoveCommandTest.java b/test/unit/org/openstreetmap/josm/command/MoveCommandTest.java index ff4b9e7..901434f 100644
a b 1 1 // License: GPL. For details, see LICENSE file. 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; 26 import org.openstreetmap.josm.testutils.JOSMTestRules; 11 27 28 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 12 29 import nl.jqno.equalsverifier.EqualsVerifier; 13 30 import nl.jqno.equalsverifier.Warning; 14 31 … … import nl.jqno.equalsverifier.Warning; 16 33 * Unit tests of {@link MoveCommand} class. 17 34 */ 18 35 public class MoveCommandTest { 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 * @since xxx 55 */ 56 @Test 57 public void testConstructors() { 58 EastNorth offset = new EastNorth(1, 2); 59 LatLon destLatLon = Main.getProjection().eastNorth2latlon(offset); 60 EastNorth start = new EastNorth(2, 0); 61 62 Set<OsmPrimitive> nodeAsCollection = Collections.<OsmPrimitive> singleton(testData.existingNode); 63 assertEquals(1, nodeAsCollection.size()); 64 checkCommandAfterConstructor(new MoveCommand(nodeAsCollection, offset)); 65 checkCommandAfterConstructor(new MoveCommand(testData.existingNode, destLatLon)); 66 checkCommandAfterConstructor(new MoveCommand(nodeAsCollection, 1, 2)); 67 checkCommandAfterConstructor(new MoveCommand(nodeAsCollection, start, start.add(offset))); 68 checkCommandAfterConstructor(new MoveCommand(testData.existingNode, 1, 2)); 69 checkCommandAfterConstructor(new MoveCommand(testData.existingNode, start, start.add(offset))); 70 } 71 72 private void checkCommandAfterConstructor(MoveCommand moveCommand) { 73 ArrayList<OsmPrimitive> nodes = new ArrayList<>(); 74 moveCommand.fillModifiedData(nodes, null, null); 75 assertEquals(nodes, new ArrayList<>(Collections.<OsmPrimitive> singleton(testData.existingNode))); 76 77 assertEquals("east", 1, moveCommand.getOffset().east(), 0.0001); 78 assertEquals("north", 2, moveCommand.getOffset().north(), 0.0001); 79 } 19 80 20 81 /** 21 * Setup test. 82 * Test {@link MoveCommand#executeCommand()} for simple nodes. 83 * @since xxx 22 84 */ 23 @BeforeClass 24 public static void setUpBeforeClass() { 25 JOSMFixture.createUnitTestFixture().init(false); 85 @Test 86 public void testSingleMove() { 87 MoveCommand command = new MoveCommand(testData.existingNode, 1, 2); 88 testData.existingNode.setEastNorth(new EastNorth(3, 7)); 89 command.executeCommand(); 90 assertEquals("east", 4, testData.existingNode.getEastNorth().east(), 0.0001); 91 assertEquals("north", 9, testData.existingNode.getEastNorth().north(), 0.0001); 92 } 93 94 /** 95 * Test {@link MoveCommand#executeCommand()} for multiple nodes. 96 * @since xxx 97 */ 98 @Test 99 public void testMultipleMove() { 100 MoveCommand command = new MoveCommand( 101 Arrays.asList(testData.existingNode, testData.existingNode2, testData.existingWay), 102 new EastNorth(1, 2)); 103 104 testData.existingNode.setEastNorth(new EastNorth(3, 7)); 105 testData.existingNode2.setEastNorth(new EastNorth(4, 7)); 106 command.executeCommand(); 107 108 assertEquals("east", 4, testData.existingNode.getEastNorth().east(), 0.0001); 109 assertEquals("north", 9, testData.existingNode.getEastNorth().north(), 0.0001); 110 assertEquals("east", 5, testData.existingNode2.getEastNorth().east(), 0.0001); 111 assertEquals("north", 9, testData.existingNode2.getEastNorth().north(), 0.0001); 112 } 113 114 /** 115 * Test {@link MoveCommand#moveAgain(double, double)} and {@link MoveCommand#moveAgainTo(double, double)}. 116 * @since xxx 117 */ 118 @Test 119 public void testMoveAgain() { 120 MoveCommand command = new MoveCommand(testData.existingNode, 1, 2); 121 assertEquals("east", 1, command.getOffset().east(), 0.0001); 122 assertEquals("north", 2, command.getOffset().north(), 0.0001); 123 124 command.moveAgain(1, 2); 125 assertEquals("east", 2, command.getOffset().east(), 0.0001); 126 assertEquals("north", 4, command.getOffset().north(), 0.0001); 127 128 command.moveAgain(-9, -3); 129 assertEquals("east", -7, command.getOffset().east(), 0.0001); 130 assertEquals("north", 1, command.getOffset().north(), 0.0001); 131 132 command.moveAgainTo(1, 2); 133 assertEquals("east", 1, command.getOffset().east(), 0.0001); 134 assertEquals("north", 2, command.getOffset().north(), 0.0001); 135 } 136 137 /** 138 * Test {@link MoveCommand#saveCheckpoint()} and {@link MoveCommand#resetToCheckpoint()} 139 * @since xxx 140 */ 141 @Test 142 public void testCheckpoint() { 143 MoveCommand command = new MoveCommand(testData.existingNode, 2, 4); 144 assertEquals("east", 2, command.getOffset().east(), 0.0001); 145 assertEquals("north", 4, command.getOffset().north(), 0.0001); 146 147 command.saveCheckpoint(); 148 command.moveAgain(3, 7); 149 assertEquals("east", 5, command.getOffset().east(), 0.0001); 150 assertEquals("north", 11, command.getOffset().north(), 0.0001); 151 152 command.resetToCheckpoint(); 153 assertEquals("east", 2, command.getOffset().east(), 0.0001); 154 assertEquals("north", 4, command.getOffset().north(), 0.0001); 155 } 156 157 /** 158 * Test the start point mechanism. 159 * @since xxx 160 */ 161 @Test 162 public void testStartPoint() { 163 EastNorth start = new EastNorth(10, 20); 164 MoveCommand command = new MoveCommand(testData.existingNode, start, start.add(1, 2)); 165 assertEquals("east", 1, command.getOffset().east(), 0.0001); 166 assertEquals("north", 2, command.getOffset().north(), 0.0001); 167 168 command.applyVectorTo(start.add(3, 4)); 169 assertEquals("east", 3, command.getOffset().east(), 0.0001); 170 assertEquals("north", 4, command.getOffset().north(), 0.0001); 171 172 // set to 100, 200 173 command.changeStartPoint(new EastNorth(103, 204)); 174 command.applyVectorTo(new EastNorth(101, 202)); 175 assertEquals("east", 1, command.getOffset().east(), 0.0001); 176 assertEquals("north", 2, command.getOffset().north(), 0.0001); 177 } 178 179 /** 180 * Test the start point mechanism ignored. 181 * @since xxx 182 */ 183 @Test 184 public void testNoStartPoint() { 185 MoveCommand command = new MoveCommand(testData.existingNode, 1, 0); 186 // ignored 187 command.applyVectorTo(new EastNorth(3, 4)); 188 assertEquals("east", 1, command.getOffset().east(), 0.0001); 189 assertEquals("north", 0, command.getOffset().north(), 0.0001); 190 191 // set to 100, 200 192 command.changeStartPoint(new EastNorth(101, 200)); 193 // works 194 command.applyVectorTo(new EastNorth(101, 202)); 195 assertEquals("east", 1, command.getOffset().east(), 0.0001); 196 assertEquals("north", 2, command.getOffset().north(), 0.0001); 197 } 198 199 /** 200 * Test {@link MoveCommand#undoCommand()} 201 * @since xxx 202 */ 203 @Test 204 public void testUndo() { 205 testData.existingNode.setEastNorth(new EastNorth(3, 7)); 206 MoveCommand command = new MoveCommand(testData.existingNode, 1, 2); 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 command.undoCommand(); 212 assertEquals("east", 3, testData.existingNode.getEastNorth().east(), 0.0001); 213 assertEquals("north", 7, testData.existingNode.getEastNorth().north(), 0.0001); 214 215 command.executeCommand(); 216 assertEquals("east", 4, testData.existingNode.getEastNorth().east(), 0.0001); 217 assertEquals("north", 9, testData.existingNode.getEastNorth().north(), 0.0001); 218 } 219 220 /** 221 * Tests {@link MoveCommand#fillModifiedData(java.util.Collection, java.util.Collection, java.util.Collection)} 222 * @since xxx 223 */ 224 @Test 225 public void testFillModifiedData() { 226 ArrayList<OsmPrimitive> modified = new ArrayList<>(); 227 ArrayList<OsmPrimitive> deleted = new ArrayList<>(); 228 ArrayList<OsmPrimitive> added = new ArrayList<>(); 229 new MoveCommand(Arrays.<OsmPrimitive>asList(testData.existingNode), 1, 2).fillModifiedData(modified, 230 deleted, added); 231 assertArrayEquals(new Object[] { testData.existingNode }, modified.toArray()); 232 assertArrayEquals(new Object[] {}, deleted.toArray()); 233 assertArrayEquals(new Object[] {}, added.toArray()); 234 } 235 236 /** 237 * Tests {@link MoveCommand#getParticipatingPrimitives()} 238 * @since xxx 239 */ 240 @Test 241 public void testGetParticipatingPrimitives() { 242 MoveCommand command = new MoveCommand(Arrays.<OsmPrimitive> asList(testData.existingNode), 1, 2); 243 command.executeCommand(); 244 assertArrayEquals(new Object[] { testData.existingNode }, command.getParticipatingPrimitives().toArray()); 245 246 MoveCommand command2 = new MoveCommand( 247 Arrays.<OsmPrimitive> asList(testData.existingNode, testData.existingWay), 1, 2); 248 command2.executeCommand(); 249 assertArrayEquals(new Object[] { testData.existingNode, testData.existingNode2 }, 250 command2.getParticipatingPrimitives().toArray()); 251 } 252 253 /** 254 * Test {@link MoveCommand#getDescriptionText()} 255 * @since xxx 256 */ 257 @Test 258 public void testDescription() { 259 Node node = new Node(LatLon.ZERO); 260 node.put("name", "xy"); 261 262 List<OsmPrimitive> nodeList = Arrays.<OsmPrimitive>asList(node); 263 assertTrue(new MoveCommand(nodeList, 1, 2).getDescriptionText().matches("Move 1 node")); 264 List<OsmPrimitive> nodes = Arrays.<OsmPrimitive> asList(node, testData.existingNode, testData.existingNode2); 265 assertTrue(new MoveCommand(nodes, 1, 2).getDescriptionText().matches("Move 3 nodes")); 26 266 } 27 267 28 268 /** -
test/unit/org/openstreetmap/josm/command/PurgeCommandTest.java
diff --git a/test/unit/org/openstreetmap/josm/command/PurgeCommandTest.java b/test/unit/org/openstreetmap/josm/command/PurgeCommandTest.java index a23b794..eb2ddab 100644
a b 1 1 // License: GPL. For details, see LICENSE file. 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; 9 21 import org.openstreetmap.josm.data.osm.Hash; 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; 18 34 … … import nl.jqno.equalsverifier.Warning; 20 36 * Unit tests of {@link PurgeCommand} class. 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; 46 47 /** 48 * Set up the test data. 49 */ 50 @Before 51 public void createTestData() { 52 testData = new CommandTestDataWithRelation(); 53 } 23 54 24 55 /** 25 * Setup test. 56 * Test {@link PurgeCommand#executeCommand()} 57 * @since xxx 26 58 */ 27 @BeforeClass 28 public static void setUpBeforeClass() { 29 JOSMFixture.createUnitTestFixture().init(false); 59 @Test 60 public void testExecute() { 61 Relation relationParent = testData.createRelation(100, new RelationMember("child", testData.existingRelation)); 62 Relation relationParent2 = testData.createRelation(101, new RelationMember("child", testData.existingRelation)); 63 // to check that algorithm ignores it: 64 Relation relationParent3 = testData.createRelation(102, new RelationMember("child", testData.existingRelation)); 65 PurgeCommand command = new PurgeCommand(testData.layer, 66 Arrays.<OsmPrimitive> asList(testData.existingNode, testData.existingNode2, testData.existingWay, 67 testData.existingRelation, relationParent, relationParent2), 68 Arrays.<OsmPrimitive> asList(testData.existingNode2, testData.existingWay, testData.existingRelation)); 69 command.executeCommand(); 70 assertTrue(testData.existingNode2.isIncomplete()); 71 assertTrue(testData.existingWay.isIncomplete()); 72 assertTrue(testData.existingRelation.isIncomplete()); 73 assertNull(relationParent.getDataSet()); 74 assertNull(relationParent2.getDataSet()); 75 assertNotNull(relationParent3.getDataSet()); 76 assertFalse(relationParent3.isIncomplete()); 77 assertNull(testData.existingNode.getDataSet()); 78 assertFalse(testData.existingNode.isIncomplete()); 79 } 80 81 /** 82 * Test {@link PurgeCommand#undoCommand()} 83 * @since xxx 84 */ 85 @Test 86 public void testUndo() { 87 PurgeCommand command = new PurgeCommand(testData.layer, 88 Arrays.<OsmPrimitive> asList(testData.existingNode, testData.existingWay), 89 Arrays.<OsmPrimitive> asList(testData.existingWay)); 90 command.executeCommand(); 91 assertTrue(testData.existingWay.isIncomplete()); 92 assertNull(testData.existingNode.getDataSet()); 93 94 command.undoCommand(); 95 assertFalse(testData.existingWay.isIncomplete()); 96 assertSame(testData.layer.data, testData.existingNode.getDataSet()); 97 98 command.executeCommand(); 99 assertTrue(testData.existingWay.isIncomplete()); 100 assertNull(testData.existingNode.getDataSet()); 101 } 102 103 /** 104 * Tests {@link PurgeCommand#fillModifiedData(java.util.Collection, java.util.Collection, java.util.Collection)} 105 * @since xxx 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 PurgeCommand command = new PurgeCommand(testData.layer, Arrays.<OsmPrimitive> asList(testData.existingNode), 113 Arrays.<OsmPrimitive> asList(testData.existingRelation)); 114 command.fillModifiedData(modified, deleted, added); 115 // intentianally empty (?) 116 assertArrayEquals(new Object[] {}, modified.toArray()); 117 assertArrayEquals(new Object[] {}, deleted.toArray()); 118 assertArrayEquals(new Object[] {}, added.toArray()); 119 } 120 121 /** 122 * Tests {@link PurgeCommand#getParticipatingPrimitives()} 123 * @since xxx 124 */ 125 @Test 126 public void testGetParticipatingPrimitives() { 127 PurgeCommand command = new PurgeCommand(testData.layer, Arrays.<OsmPrimitive> asList(testData.existingNode), 128 Arrays.<OsmPrimitive> asList(testData.existingRelation)); 129 assertArrayEquals(new Object[] { testData.existingNode }, command.getParticipatingPrimitives().toArray()); 130 } 131 132 /** 133 * Test {@link PurgeCommand#getDescriptionText()} 134 * @since xxx 135 */ 136 @Test 137 public void testDescription() { 138 List<OsmPrimitive> shortList = Arrays.<OsmPrimitive> asList(testData.existingWay); 139 assertTrue(new PurgeCommand(testData.layer, shortList, Arrays.<OsmPrimitive> asList()).getDescriptionText() 140 .matches("Purged 1 object")); 141 List<OsmPrimitive> longList = Arrays.<OsmPrimitive> asList(testData.existingNode, testData.existingNode2, 142 testData.existingWay); 143 assertTrue(new PurgeCommand(testData.layer, longList, Arrays.<OsmPrimitive> asList()).getDescriptionText() 144 .matches("Purged 3 objects")); 30 145 } 31 146 32 147 /** -
test/unit/org/openstreetmap/josm/command/RemoveNodesCommandTest.java
diff --git a/test/unit/org/openstreetmap/josm/command/RemoveNodesCommandTest.java b/test/unit/org/openstreetmap/josm/command/RemoveNodesCommandTest.java index 1f1255a..145511b 100644
a b 1 1 // License: GPL. For details, see LICENSE file. 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; 14 25 … … import nl.jqno.equalsverifier.Warning; 18 29 public class RemoveNodesCommandTest { 19 30 20 31 /** 21 * Setup test. 32 * We need prefs for nodes. 33 */ 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 * @since xxx 50 */ 51 @Test 52 public void testExecute() { 53 RemoveNodesCommand command = new RemoveNodesCommand(testData.existingWay, 54 Collections.singletonList(testData.existingNode)); 55 56 command.executeCommand(); 57 58 assertFalse(testData.existingWay.containsNode(testData.existingNode)); 59 assertTrue(testData.existingWay.containsNode(testData.existingNode2)); 60 assertTrue(testData.existingWay.isModified()); 61 } 62 63 /** 64 * Test {@link RemoveNodesCommand#undoCommand()} 65 * @since xxx 66 */ 67 @Test 68 public void testUndo() { 69 RemoveNodesCommand command = new RemoveNodesCommand(testData.existingWay, 70 Collections.singletonList(testData.existingNode)); 71 72 command.executeCommand(); 73 74 command.undoCommand(); 75 assertTrue(testData.existingWay.containsNode(testData.existingNode)); 76 assertTrue(testData.existingWay.containsNode(testData.existingNode2)); 77 assertFalse(testData.existingWay.isModified()); 78 79 command.executeCommand(); 80 81 assertFalse(testData.existingWay.containsNode(testData.existingNode)); 82 assertTrue(testData.existingWay.containsNode(testData.existingNode2)); 83 assertTrue(testData.existingWay.isModified()); 84 } 85 86 /** 87 * Tests {@link RemoveNodesCommand#fillModifiedData(java.util.Collection, java.util.Collection, java.util.Collection)} 88 * @since xxx 89 */ 90 @Test 91 public void testFillModifiedData() { 92 ArrayList<OsmPrimitive> modified = new ArrayList<>(); 93 ArrayList<OsmPrimitive> deleted = new ArrayList<>(); 94 ArrayList<OsmPrimitive> added = new ArrayList<>(); 95 RemoveNodesCommand command = new RemoveNodesCommand(testData.existingWay, 96 Collections.singletonList(testData.existingNode)); 97 command.fillModifiedData(modified, deleted, added); 98 assertArrayEquals(new Object[] { testData.existingWay }, modified.toArray()); 99 assertArrayEquals(new Object[] {}, deleted.toArray()); 100 assertArrayEquals(new Object[] {}, added.toArray()); 101 } 102 103 /** 104 * Tests {@link RemoveNodesCommand#getParticipatingPrimitives()} 105 * @since xxx 22 106 */ 23 @BeforeClass 24 public static void setUpBeforeClass() { 25 JOSMFixture.createUnitTestFixture().init(false); 107 @Test 108 public void testGetParticipatingPrimitives() { 109 RemoveNodesCommand command = new RemoveNodesCommand(testData.existingWay, 110 Collections.singletonList(testData.existingNode)); 111 command.executeCommand(); 112 assertArrayEquals(new Object[] { testData.existingWay }, command.getParticipatingPrimitives().toArray()); 113 } 114 115 /** 116 * Test {@link RemoveNodesCommand#getDescriptionText()} 117 * @since xxx 118 */ 119 @Test 120 public void testDescription() { 121 assertTrue(new RemoveNodesCommand(testData.existingWay, Collections.singletonList(testData.existingNode)) 122 .getDescriptionText().matches("Removed nodes from .*")); 26 123 } 27 124 28 125 /** -
test/unit/org/openstreetmap/josm/command/RotateCommandTest.java
diff --git a/test/unit/org/openstreetmap/josm/command/RotateCommandTest.java b/test/unit/org/openstreetmap/josm/command/RotateCommandTest.java index 85d4bd4..6c6b007 100644
a b 1 1 // License: GPL. For details, see LICENSE file. 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; 14 26 … … import nl.jqno.equalsverifier.Warning; 18 30 public class RotateCommandTest { 19 31 20 32 /** 21 * Setup test. 33 * We need prefs for nodes. 34 */ 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 * @since xxx 51 */ 52 @Test 53 public void testRotate() { 54 // pivot needs to be at 0,0 55 Node n1 = new Node(new EastNorth(10, 10)); 56 Node n2 = new Node(new EastNorth(-1, 0)); 57 Node n3 = new Node(new EastNorth(-9, -10)); 58 RotateCommand rotate = new RotateCommand(Arrays.asList(n1, n2, n3), new EastNorth(0, 0)); 59 rotate.setRotationAngle(Math.PI / 4); 60 rotate.executeCommand(); 61 62 assertEquals(Math.sqrt(2) * 10, n1.getEastNorth().east(), 0.0001); 63 assertEquals(0, n1.getEastNorth().north(), 0.0001); 64 assertEquals(-1 / Math.sqrt(2), n2.getEastNorth().east(), 0.0001); 65 assertEquals(1 / Math.sqrt(2), n2.getEastNorth().north(), 0.0001); 66 } 67 68 /** 69 * Test {@link RotateCommand#undoCommand()} 70 * @since xxx 71 */ 72 @Test 73 public void testUndo() { 74 Node n1 = new Node(new EastNorth(10, 10)); 75 Node n2 = new Node(new EastNorth(-1, 0)); 76 Node n3 = new Node(new EastNorth(-9, -10)); 77 RotateCommand rotate = new RotateCommand(Arrays.asList(n1, n2, n3), new EastNorth(0, 0)); 78 rotate.setRotationAngle(Math.PI / 4); 79 rotate.executeCommand(); 80 rotate.undoCommand(); 81 82 assertEquals(10, n1.getEastNorth().east(), 0.0001); 83 assertEquals(10, n1.getEastNorth().north(), 0.0001); 84 assertEquals(-1, n2.getEastNorth().east(), 0.0001); 85 assertEquals(0, n2.getEastNorth().north(), 0.0001); 86 87 rotate.executeCommand(); 88 89 assertEquals(-1 / Math.sqrt(2), n2.getEastNorth().east(), 0.0001); 90 assertEquals(1 / Math.sqrt(2), n2.getEastNorth().north(), 0.0001); 91 } 92 93 /** 94 * Tests {@link RotateCommand#fillModifiedData(java.util.Collection, java.util.Collection, java.util.Collection)} 95 * @since xxx 22 96 */ 23 @BeforeClass 24 public static void setUpBeforeClass() { 25 JOSMFixture.createUnitTestFixture().init(false); 97 @Test 98 public void testFillModifiedData() { 99 ArrayList<OsmPrimitive> modified = new ArrayList<>(); 100 ArrayList<OsmPrimitive> deleted = new ArrayList<>(); 101 ArrayList<OsmPrimitive> added = new ArrayList<>(); 102 RotateCommand command = new RotateCommand(Arrays.asList(testData.existingNode), 103 new EastNorth(0, 0)); 104 // intentionally empty 105 command.fillModifiedData(modified, deleted, added); 106 assertArrayEquals(new Object[] {}, modified.toArray()); 107 assertArrayEquals(new Object[] {}, deleted.toArray()); 108 assertArrayEquals(new Object[] {}, added.toArray()); 109 } 110 111 /** 112 * Tests {@link RotateCommand#getParticipatingPrimitives()} 113 * @since xxx 114 */ 115 @Test 116 public void testGetParticipatingPrimitives() { 117 RotateCommand command = new RotateCommand(Arrays.asList(testData.existingNode), 118 new EastNorth(0, 0)); 119 command.executeCommand(); 120 assertArrayEquals(new Object[] { testData.existingNode }, command.getParticipatingPrimitives().toArray()); 121 } 122 123 /** 124 * Test {@link RotateCommand#getDescriptionText()} 125 * @since xxx 126 */ 127 @Test 128 public void testDescription() { 129 assertEquals("Rotate 1 node", 130 new RotateCommand(Arrays.asList(testData.existingNode), new EastNorth(0, 0)) 131 .getDescriptionText()); 132 assertEquals("Rotate 2 nodes", 133 new RotateCommand(Arrays.asList(testData.existingNode, testData.existingNode2), new EastNorth(0, 0)) 134 .getDescriptionText()); 26 135 } 27 136 28 137 /** … … public class RotateCommandTest { 31 140 @Test 32 141 public void equalsContract() { 33 142 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(); 143 .withPrefabValues(LatLon.class, LatLon.ZERO, new LatLon(45, 45)) 144 .withPrefabValues(DataSet.class, new DataSet(), new DataSet()) 145 .withPrefabValues(User.class, User.createOsmUser(1, "foo"), User.createOsmUser(2, "bar")) 146 .withPrefabValues(OsmDataLayer.class, new OsmDataLayer(new DataSet(), "1", null), 147 new OsmDataLayer(new DataSet(), "2", null)) 148 .suppress(Warning.NONFINAL_FIELDS).verify(); 44 149 } 45 150 } -
test/unit/org/openstreetmap/josm/command/ScaleCommandTest.java
diff --git a/test/unit/org/openstreetmap/josm/command/ScaleCommandTest.java b/test/unit/org/openstreetmap/josm/command/ScaleCommandTest.java index 84a93d1..a18eb03 100644
a b 1 1 // License: GPL. For details, see LICENSE file. 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; 14 26 … … import nl.jqno.equalsverifier.Warning; 18 30 public class ScaleCommandTest { 19 31 20 32 /** 21 * Setup test. 33 * We need prefs for nodes. 34 */ 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 * @since xxx 51 */ 52 @Test 53 public void testScale() { 54 // pivot needs to be at 0,0 55 Node n1 = new Node(new EastNorth(10, 10)); 56 Node n2 = new Node(new EastNorth(-1, 0)); 57 Node n3 = new Node(new EastNorth(-9, -10)); 58 ScaleCommand scale = new ScaleCommand(Arrays.asList(n1, n2, n3), new EastNorth(0, 0)); 59 scale.setScalingFactor(2.5); 60 scale.executeCommand(); 61 62 assertEquals(25, n1.getEastNorth().east(), 0.0001); 63 assertEquals(25, n1.getEastNorth().north(), 0.0001); 64 assertEquals(-2.5, n2.getEastNorth().east(), 0.0001); 65 assertEquals(0, n2.getEastNorth().north(), 0.0001); 66 } 67 68 /** 69 * Test {@link ScaleCommand#undoCommand()} 70 * @since xxx 71 */ 72 @Test 73 public void testUndo() { 74 Node n1 = new Node(new EastNorth(10, 10)); 75 Node n2 = new Node(new EastNorth(-1, 0)); 76 Node n3 = new Node(new EastNorth(-9, -10)); 77 ScaleCommand scale = new ScaleCommand(Arrays.asList(n1, n2, n3), new EastNorth(0, 0)); 78 scale.setScalingFactor(2.5); 79 scale.executeCommand(); 80 scale.undoCommand(); 81 82 assertEquals(10, n1.getEastNorth().east(), 0.0001); 83 assertEquals(10, n1.getEastNorth().north(), 0.0001); 84 assertEquals(-1, n2.getEastNorth().east(), 0.0001); 85 assertEquals(0, n2.getEastNorth().north(), 0.0001); 86 87 scale.executeCommand(); 88 89 assertEquals(-2.5, n2.getEastNorth().east(), 0.0001); 90 assertEquals(0, n2.getEastNorth().north(), 0.0001); 91 } 92 93 /** 94 * Tests {@link ScaleCommand#fillModifiedData(java.util.Collection, java.util.Collection, java.util.Collection)} 95 * @since xxx 22 96 */ 23 @BeforeClass 24 public static void setUpBeforeClass() { 25 JOSMFixture.createUnitTestFixture().init(false); 97 @Test 98 public void testFillModifiedData() { 99 ArrayList<OsmPrimitive> modified = new ArrayList<>(); 100 ArrayList<OsmPrimitive> deleted = new ArrayList<>(); 101 ArrayList<OsmPrimitive> added = new ArrayList<>(); 102 ScaleCommand command = new ScaleCommand(Arrays.asList(testData.existingNode), 103 new EastNorth(0, 0)); 104 // intentionally empty 105 command.fillModifiedData(modified, deleted, added); 106 assertArrayEquals(new Object[] {}, modified.toArray()); 107 assertArrayEquals(new Object[] {}, deleted.toArray()); 108 assertArrayEquals(new Object[] {}, added.toArray()); 109 } 110 111 /** 112 * Tests {@link ScaleCommand#getParticipatingPrimitives()} 113 * @since xxx 114 */ 115 @Test 116 public void testGetParticipatingPrimitives() { 117 ScaleCommand command = new ScaleCommand(Arrays.asList(testData.existingNode), 118 new EastNorth(0, 0)); 119 command.executeCommand(); 120 assertArrayEquals(new Object[] { testData.existingNode }, command.getParticipatingPrimitives().toArray()); 121 } 122 123 /** 124 * Test {@link ScaleCommand#getDescriptionText()} 125 * @since xxx 126 */ 127 @Test 128 public void testDescription() { 129 assertEquals("Scale 1 node", 130 new ScaleCommand(Arrays.asList(testData.existingNode), new EastNorth(0, 0)) 131 .getDescriptionText()); 132 assertEquals("Scale 2 nodes", 133 new ScaleCommand(Arrays.asList(testData.existingNode, testData.existingNode2), new EastNorth(0, 0)) 134 .getDescriptionText()); 26 135 } 27 136 28 137 /** -
test/unit/org/openstreetmap/josm/command/SelectCommandTest.java
diff --git a/test/unit/org/openstreetmap/josm/command/SelectCommandTest.java b/test/unit/org/openstreetmap/josm/command/SelectCommandTest.java index 37b36cf..5ac0c5c 100644
a b 1 1 // License: GPL. For details, see LICENSE file. 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; 13 25 … … import nl.jqno.equalsverifier.Warning; 17 29 public class SelectCommandTest { 18 30 19 31 /** 20 * Setup test. 32 * We need prefs for nodes. 33 */ 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 * @since xxx 50 */ 51 @Test 52 public void testExecute() { 53 SelectCommand command = new SelectCommand(Arrays.asList(testData.existingNode, testData.existingWay)); 54 55 testData.layer.data.setSelected(Arrays.asList(testData.existingNode2)); 56 57 command.executeCommand(); 58 59 assertTrue(testData.existingNode.isSelected()); 60 assertFalse(testData.existingNode2.isSelected()); 61 assertTrue(testData.existingWay.isSelected()); 62 } 63 64 /** 65 * Test {@link SelectCommand#executeCommand()} 66 * @since xxx 67 */ 68 @Test 69 public void testExecuteAfterModify() { 70 List<OsmPrimitive> list = new ArrayList<>(Arrays.asList(testData.existingNode, testData.existingWay)); 71 SelectCommand command = new SelectCommand(list); 72 73 list.remove(testData.existingNode); 74 list.add(testData.existingNode2); 75 76 command.executeCommand(); 77 78 assertTrue(testData.existingNode.isSelected()); 79 assertFalse(testData.existingNode2.isSelected()); 80 assertTrue(testData.existingWay.isSelected()); 81 } 82 83 /** 84 * Test {@link SelectCommand#undoCommand()} 85 * @since xxx 86 */ 87 @Test 88 public void testUndo() { 89 SelectCommand command = new SelectCommand(Arrays.asList(testData.existingNode, testData.existingWay)); 90 testData.layer.data.setSelected(Arrays.asList(testData.existingNode2)); 91 92 command.executeCommand(); 93 94 command.undoCommand(); 95 96 assertFalse(testData.existingNode.isSelected()); 97 assertTrue(testData.existingNode2.isSelected()); 98 assertFalse(testData.existingWay.isSelected()); 99 100 command.executeCommand(); 101 102 assertTrue(testData.existingNode.isSelected()); 103 assertFalse(testData.existingNode2.isSelected()); 104 assertTrue(testData.existingWay.isSelected()); 105 } 106 107 /** 108 * Tests {@link SelectCommand#fillModifiedData(java.util.Collection, java.util.Collection, java.util.Collection)} 109 * @since xxx 21 110 */ 22 @BeforeClass 23 public static void setUpBeforeClass() { 24 JOSMFixture.createUnitTestFixture().init(false); 111 @Test 112 public void testFillModifiedData() { 113 ArrayList<OsmPrimitive> modified = new ArrayList<>(); 114 ArrayList<OsmPrimitive> deleted = new ArrayList<>(); 115 ArrayList<OsmPrimitive> added = new ArrayList<>(); 116 SelectCommand command = new SelectCommand(Arrays.asList(testData.existingNode, testData.existingWay)); 117 command.fillModifiedData(modified, deleted, added); 118 // intentionally empty. 119 assertArrayEquals(new Object[] {}, modified.toArray()); 120 assertArrayEquals(new Object[] {}, deleted.toArray()); 121 assertArrayEquals(new Object[] {}, added.toArray()); 122 } 123 124 /** 125 * Tests {@link SelectCommand#getParticipatingPrimitives()} 126 * @since xxx 127 */ 128 @Test 129 public void testGetParticipatingPrimitives() { 130 SelectCommand command = new SelectCommand(Arrays.asList(testData.existingNode, testData.existingWay)); 131 command.executeCommand(); 132 assertArrayEquals(new Object[] {}, command.getParticipatingPrimitives().toArray()); 133 } 134 135 /** 136 * Test {@link SelectCommand#getDescriptionText()} 137 * @since xxx 138 */ 139 @Test 140 public void testDescription() { 141 assertTrue(new SelectCommand(Arrays.<OsmPrimitive>asList(testData.existingNode)) 142 .getDescriptionText().matches("Selected 1 object")); 143 assertTrue(new SelectCommand(Arrays.asList(testData.existingNode, testData.existingWay)) 144 .getDescriptionText().matches("Selected 2 objects")); 145 assertTrue(new SelectCommand(Arrays.<OsmPrimitive>asList()) 146 .getDescriptionText().matches("Selected 0 objects")); 147 assertTrue(new SelectCommand(null) 148 .getDescriptionText().matches("Selected 0 objects")); 25 149 } 26 150 27 151 /** -
test/unit/org/openstreetmap/josm/command/SequenceCommandTest.java
diff --git a/test/unit/org/openstreetmap/josm/command/SequenceCommandTest.java b/test/unit/org/openstreetmap/josm/command/SequenceCommandTest.java index 31bb385..71cd6d9 100644
a b 1 1 // License: GPL. For details, see LICENSE file. 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; 24 import org.openstreetmap.josm.testutils.JOSMTestRules; 11 25 26 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 12 27 import nl.jqno.equalsverifier.EqualsVerifier; 13 28 import nl.jqno.equalsverifier.Warning; 14 29 … … import nl.jqno.equalsverifier.Warning; 18 33 public class SequenceCommandTest { 19 34 20 35 /** 21 * Setup test. 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 * @since xxx 54 */ 55 @Test 56 public void testExecute() { 57 final TestCommand command1 = new TestCommand(Arrays.<OsmPrimitive> asList(testData.existingNode)); 58 TestCommand command2 = new TestCommand(Arrays.<OsmPrimitive> asList(testData.existingNode2)) { 59 @Override 60 public boolean executeCommand() { 61 assertTrue(command1.executed); 62 return super.executeCommand(); 63 } 64 }; 65 SequenceCommand command = new SequenceCommand("seq", Arrays.<Command> asList(command1, command2)); 66 67 command.executeCommand(); 68 69 assertTrue(command1.executed); 70 assertTrue(command2.executed); 71 } 72 73 /** 74 * Test {@link SequenceCommand#undoCommand()} 75 * @since xxx 76 */ 77 @Test 78 public void testUndo() { 79 final TestCommand command2 = new TestCommand(Arrays.<OsmPrimitive> asList(testData.existingNode2)); 80 TestCommand command1 = new TestCommand(Arrays.<OsmPrimitive> asList(testData.existingNode)) { 81 @Override 82 public void undoCommand() { 83 assertFalse(command2.executed); 84 super.undoCommand(); 85 } 86 }; 87 SequenceCommand command = new SequenceCommand("seq", Arrays.<Command> asList(command1, command2)); 88 89 command.executeCommand(); 90 91 command.undoCommand(); 92 93 assertFalse(command1.executed); 94 assertFalse(command2.executed); 95 96 command.executeCommand(); 97 98 assertTrue(command1.executed); 99 assertTrue(command2.executed); 100 } 101 102 /** 103 * Test {@link SequenceCommand#undoCommand()} 104 * @since xxx 22 105 */ 23 @BeforeClass 24 public static void setUpBeforeClass() { 25 JOSMFixture.createUnitTestFixture().init(false); 106 @Test 107 public void testGetLastCommand() { 108 final TestCommand command1 = new TestCommand(Arrays.<OsmPrimitive> asList(testData.existingNode)); 109 final TestCommand command2 = new TestCommand(Arrays.<OsmPrimitive> asList(testData.existingNode2)); 110 111 assertEquals(command2, new SequenceCommand("seq", command1, command2).getLastCommand()); 112 assertNull(new SequenceCommand("seq").getLastCommand()); 113 } 114 115 /** 116 * Tests {@link SequenceCommand#fillModifiedData(java.util.Collection, java.util.Collection, java.util.Collection)} 117 * @since xxx 118 */ 119 @Test 120 public void testFillModifiedData() { 121 Command command1 = new TestCommand(Arrays.<OsmPrimitive> asList(testData.existingNode)); 122 Command command2 = new TestCommand(Arrays.<OsmPrimitive> asList(testData.existingNode2)); 123 Command command3 = new TestCommand(Arrays.<OsmPrimitive> asList(testData.existingWay)) { 124 @Override 125 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, 126 Collection<OsmPrimitive> added) { 127 deleted.addAll(primitives); 128 } 129 }; 130 Command command4 = new TestCommand(Arrays.<OsmPrimitive> asList(testData.existingRelation)) { 131 @Override 132 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, 133 Collection<OsmPrimitive> added) { 134 added.addAll(primitives); 135 } 136 }; 137 138 ArrayList<OsmPrimitive> modified = new ArrayList<>(); 139 ArrayList<OsmPrimitive> deleted = new ArrayList<>(); 140 ArrayList<OsmPrimitive> added = new ArrayList<>(); 141 SequenceCommand command = new SequenceCommand("seq", command1, command2, command3, command4); 142 command.fillModifiedData(modified, deleted, added); 143 assertArrayEquals(new Object[] { testData.existingNode, testData.existingNode2 }, modified.toArray()); 144 assertArrayEquals(new Object[] { testData.existingWay }, deleted.toArray()); 145 assertArrayEquals(new Object[] { testData.existingRelation }, added.toArray()); 146 } 147 148 /** 149 * Tests {@link SequenceCommand#getParticipatingPrimitives()} 150 * @since xxx 151 */ 152 @Test 153 public void testGetParticipatingPrimitives() { 154 Command command1 = new TestCommand(Arrays.<OsmPrimitive> asList(testData.existingNode)); 155 Command command2 = new TestCommand(Arrays.<OsmPrimitive> asList(testData.existingNode2)); 156 157 SequenceCommand command = new SequenceCommand("seq", command1, command2); 158 command.executeCommand(); 159 Collection<? extends OsmPrimitive> primitives = command.getParticipatingPrimitives(); 160 assertEquals(2, primitives.size()); 161 assertTrue(primitives.contains(testData.existingNode)); 162 assertTrue(primitives.contains(testData.existingNode2)); 163 } 164 165 /** 166 * Test {@link SequenceCommand#getDescriptionText()} 167 * @since xxx 168 */ 169 @Test 170 public void testDescription() { 171 assertTrue(new SequenceCommand("test").getDescriptionText().matches("Sequence: test")); 26 172 } 27 173 28 174 /** … … public class SequenceCommandTest { 42 188 .suppress(Warning.NONFINAL_FIELDS) 43 189 .verify(); 44 190 } 191 192 private static class TestCommand extends Command { 193 protected final Collection<? extends OsmPrimitive> primitives; 194 protected boolean executed; 195 196 TestCommand(Collection<? extends OsmPrimitive> primitives) { 197 super(); 198 this.primitives = primitives; 199 } 200 201 @Override 202 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, 203 Collection<OsmPrimitive> added) { 204 modified.addAll(primitives); 205 } 206 207 @Override 208 public String getDescriptionText() { 209 fail("Should not be called"); 210 return ""; 211 } 212 213 @Override 214 public Collection<? extends OsmPrimitive> getParticipatingPrimitives() { 215 return primitives; 216 } 217 218 @Override 219 public boolean executeCommand() { 220 assertFalse("Cannot execute twice", executed); 221 executed = true; 222 return true; 223 } 224 225 @Override 226 public void undoCommand() { 227 assertTrue("Cannot undo without execute", executed); 228 executed = false; 229 } 230 231 @Override 232 public String toString() { 233 return "TestCommand [primitives=" + primitives + "]"; 234 } 235 236 } 45 237 }