Changeset 10663 in josm for trunk/test/unit/org/openstreetmap/josm/command/ChangePropertyKeyCommandTest.java
- Timestamp:
- 2016-07-28T01:24:39+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/command/ChangePropertyKeyCommandTest.java
r9943 r10663 2 2 package org.openstreetmap.josm.command; 3 3 4 import org.junit.BeforeClass; 4 import static org.junit.Assert.assertEquals; 5 import static org.junit.Assert.assertFalse; 6 import static org.junit.Assert.assertNull; 7 import static org.junit.Assert.assertTrue; 8 9 import java.util.ArrayList; 10 import java.util.Arrays; 11 import java.util.Collection; 12 13 import org.junit.Before; 14 import org.junit.Rule; 5 15 import org.junit.Test; 6 import org.openstreetmap.josm. JOSMFixture;16 import org.openstreetmap.josm.command.CommandTest.CommandTestData; 7 17 import org.openstreetmap.josm.data.osm.DataSet; 18 import org.openstreetmap.josm.data.osm.Node; 19 import org.openstreetmap.josm.data.osm.OsmPrimitive; 8 20 import org.openstreetmap.josm.data.osm.User; 9 21 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 22 import org.openstreetmap.josm.testutils.JOSMTestRules; 10 23 24 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 11 25 import nl.jqno.equalsverifier.EqualsVerifier; 12 26 import nl.jqno.equalsverifier.Warning; … … 18 32 19 33 /** 20 * Setup test.34 * We need prefs for nodes. 21 35 */ 22 @BeforeClass 23 public static void setUpBeforeClass() { 24 JOSMFixture.createUnitTestFixture().init(false); 36 @Rule 37 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 38 public JOSMTestRules test = new JOSMTestRules().preferences().i18n(); 39 private CommandTestData testData; 40 41 /** 42 * Set up the test data. 43 */ 44 @Before 45 public void createTestData() { 46 testData = new CommandTestData(); 47 } 48 49 /** 50 * Tests that a key is changed. 51 */ 52 @Test 53 public void testChangeKeySingle() { 54 assertTrue(new ChangePropertyKeyCommand(testData.existingNode, "existing", "newKey").executeCommand()); 55 56 assertNull(testData.existingNode.get("existing")); 57 assertEquals("existing", testData.existingNode.get("newKey")); 58 assertTrue(testData.existingNode.isModified()); 59 } 60 61 /** 62 * Tests that a key is changed. 63 */ 64 @Test 65 public void testChangeKey() { 66 assertTrue(new ChangePropertyKeyCommand(Arrays.asList(testData.existingNode, testData.existingWay), "existing", 67 "newKey").executeCommand()); 68 69 assertNull(testData.existingNode.get("existing")); 70 assertEquals("existing", testData.existingNode.get("newKey")); 71 assertTrue(testData.existingNode.isModified()); 72 assertNull(testData.existingWay.get("existing")); 73 assertEquals("existing", testData.existingWay.get("newKey")); 74 assertTrue(testData.existingWay.isModified()); 75 } 76 77 /** 78 * Tests that nop operations are ignored. 79 */ 80 @Test 81 public void testChangeKeyIgnored() { 82 Node node1 = testData.createNode(15); 83 node1.removeAll(); 84 Node node2 = testData.createNode(16); 85 Node node3 = testData.createNode(17); 86 87 assertTrue(new ChangePropertyKeyCommand(Arrays.asList(node1, node2), "nonexisting", "newKey").executeCommand()); 88 89 assertFalse(node1.isModified()); 90 assertFalse(node2.isModified()); 91 92 assertTrue(new ChangePropertyKeyCommand(Arrays.asList(node1, node2), "existing", "newKey").executeCommand()); 93 94 assertFalse(node1.isModified()); 95 assertTrue(node2.isModified()); 96 97 // removes existing 98 assertTrue(new ChangePropertyKeyCommand(Arrays.asList(node1, node3), "newKey", "existing").executeCommand()); 99 100 assertFalse(node1.isModified()); 101 assertTrue(node3.isModified()); 102 assertNull(node3.get("newKey")); 103 assertNull(node3.get("existing")); 104 } 105 106 /** 107 * Test {@link ChangePropertyKeyCommand#getDescriptionText()} 108 */ 109 @Test 110 public void testDescription() { 111 Node node1 = testData.createNode(15); 112 node1.put("name", "xy"); 113 114 assertTrue(new ChangePropertyKeyCommand(node1, "a", "b").getDescriptionText() 115 .matches("Replace \"a\" by \"b\" for.*xy.*")); 116 assertTrue(new ChangePropertyKeyCommand(Arrays.asList(node1, testData.existingNode), "a", "b") 117 .getDescriptionText().matches("Replace \"a\" by \"b\" for 2 objects")); 118 } 119 120 /** 121 * Test {@link ChangePropertyCommand#getChildren()} 122 */ 123 @Test 124 public void testChildren() { 125 Node node1 = testData.createNode(15); 126 Node node2 = testData.createNode(16); 127 node1.put("name", "node1"); 128 node2.put("name", "node2"); 129 130 ArrayList<Node> nodesToExpect = new ArrayList<>(Arrays.asList(node1, node2)); 131 132 assertNull(new ChangePropertyKeyCommand(node1, "a", "b").getChildren()); 133 Collection<PseudoCommand> children = new ChangePropertyKeyCommand(Arrays.asList(node1, node2), "a", "b").getChildren(); 134 assertEquals(2, children.size()); 135 for (PseudoCommand c : children) { 136 assertNull(c.getChildren()); 137 Collection<? extends OsmPrimitive> part = c.getParticipatingPrimitives(); 138 assertEquals(1, part.size()); 139 OsmPrimitive node = part.iterator().next(); 140 assertTrue(nodesToExpect.remove(node)); 141 142 assertTrue(c.getDescriptionText().contains(node.getName())); 143 } 25 144 } 26 145
Note:
See TracChangeset
for help on using the changeset viewer.