Changeset 10663 in josm for trunk/test/unit/org/openstreetmap/josm/command/ChangeRelationMemberRoleCommandTest.java
- Timestamp:
- 2016-07-28T01:24:39+02:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/command/ChangeRelationMemberRoleCommandTest.java
r9943 r10663 2 2 package org.openstreetmap.josm.command; 3 3 4 import org.junit.BeforeClass; 4 import static org.junit.Assert.assertArrayEquals; 5 import static org.junit.Assert.assertEquals; 6 import static org.junit.Assert.assertFalse; 7 import static org.junit.Assert.assertNull; 8 import static org.junit.Assert.assertTrue; 9 10 import java.util.ArrayList; 11 12 import org.junit.Before; 13 import org.junit.Rule; 5 14 import org.junit.Test; 6 import org.openstreetmap.josm. JOSMFixture;15 import org.openstreetmap.josm.command.CommandTest.CommandTestDataWithRelation; 7 16 import org.openstreetmap.josm.data.osm.DataSet; 17 import org.openstreetmap.josm.data.osm.OsmPrimitive; 8 18 import org.openstreetmap.josm.data.osm.Relation; 9 19 import org.openstreetmap.josm.data.osm.User; 10 20 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 21 import org.openstreetmap.josm.testutils.JOSMTestRules; 11 22 23 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 12 24 import nl.jqno.equalsverifier.EqualsVerifier; 13 25 import nl.jqno.equalsverifier.Warning; … … 19 31 20 32 /** 21 * Setup test.33 * We need prefs for nodes. 22 34 */ 23 @BeforeClass 24 public static void setUpBeforeClass() { 25 JOSMFixture.createUnitTestFixture().init(false); 35 @Rule 36 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 37 public JOSMTestRules test = new JOSMTestRules().preferences().i18n(); 38 private CommandTestDataWithRelation testData; 39 40 /** 41 * Set up the test data. 42 */ 43 @Before 44 public void createTestData() { 45 testData = new CommandTestDataWithRelation(); 46 } 47 48 /** 49 * Test if {@link ChangeRelationMemberRoleCommand} changes the role by index 50 */ 51 @Test 52 public void testRoleChanged() { 53 assertTrue(new ChangeRelationMemberRoleCommand(testData.existingRelation, 0, "newRole").executeCommand()); 54 assertEquals("newRole", testData.existingRelation.getMember(0).getRole()); 55 assertEquals(testData.existingNode, testData.existingRelation.getMember(0).getMember()); 56 assertEquals("way", testData.existingRelation.getMember(1).getRole()); 57 58 assertTrue(testData.existingRelation.isModified()); 59 60 assertTrue(new ChangeRelationMemberRoleCommand(testData.existingRelation, 1, "newRole").executeCommand()); 61 assertEquals("newRole", testData.existingRelation.getMember(1).getRole()); 62 } 63 64 /** 65 * Wrong index should be ignored. 66 */ 67 @Test 68 public void testWrongIndex() { 69 // should be ignored 70 ChangeRelationMemberRoleCommand command1 = new ChangeRelationMemberRoleCommand(testData.existingRelation, -1, "newRole"); 71 assertTrue(command1.executeCommand()); 72 ChangeRelationMemberRoleCommand command2 = new ChangeRelationMemberRoleCommand(testData.existingRelation, 8, "newRole"); 73 assertTrue(command2.executeCommand()); 74 assertFalse(testData.existingRelation.isModified()); 75 76 command1.undoCommand(); 77 command2.undoCommand(); 78 assertFalse(testData.existingRelation.isModified()); 79 } 80 81 82 /** 83 * Same role should be ignored. 84 */ 85 @Test 86 public void testSameRole() { 87 // should be ignored 88 assertTrue(new ChangeRelationMemberRoleCommand(testData.existingRelation, 0, "node").executeCommand()); 89 assertFalse(testData.existingRelation.isModified()); 90 } 91 92 /** 93 * Test {@link ChangeRelationMemberRoleCommand#undoCommand()}. 94 */ 95 @Test 96 public void testUndo() { 97 ChangeRelationMemberRoleCommand command = new ChangeRelationMemberRoleCommand(testData.existingRelation, 0, "newRole"); 98 command.executeCommand(); 99 assertEquals("newRole", testData.existingRelation.getMember(0).getRole()); 100 assertTrue(testData.existingRelation.isModified()); 101 102 command.undoCommand(); 103 assertEquals("node", testData.existingRelation.getMember(0).getRole()); 104 assertFalse(testData.existingRelation.isModified()); 105 106 command.executeCommand(); 107 assertEquals("newRole", testData.existingRelation.getMember(0).getRole()); 108 assertTrue(testData.existingRelation.isModified()); 109 } 110 111 /** 112 * Tests {@link ChangeCommand#fillModifiedData(java.util.Collection, java.util.Collection, java.util.Collection)} 113 */ 114 @Test 115 public void testFillModifiedData() { 116 ArrayList<OsmPrimitive> modified = new ArrayList<>(); 117 ArrayList<OsmPrimitive> deleted = new ArrayList<>(); 118 ArrayList<OsmPrimitive> added = new ArrayList<>(); 119 new ChangeRelationMemberRoleCommand(testData.existingRelation, 0, "newRole").fillModifiedData(modified, deleted, added); 120 assertArrayEquals(new Object[] {testData.existingRelation}, modified.toArray()); 121 assertArrayEquals(new Object[] {}, deleted.toArray()); 122 assertArrayEquals(new Object[] {}, added.toArray()); 123 } 124 125 /** 126 * Test {@link ChangeRelationMemberRoleCommand#getDescriptionText()} 127 */ 128 @Test 129 public void testDescription() { 130 testData.existingRelation.put("name", "xy"); 131 assertTrue(new ChangeRelationMemberRoleCommand(testData.existingRelation, 0, "newRole").getDescriptionText() 132 .matches("Change relation member role for relation.*xy.*")); 133 } 134 135 /** 136 * Test {@link ChangeRelationMemberRoleCommand#getChildren()} 137 */ 138 @Test 139 public void testChildren() { 140 assertNull(new ChangeRelationMemberRoleCommand(testData.existingRelation, 0, "newRole").getChildren()); 26 141 } 27 142
Note:
See TracChangeset
for help on using the changeset viewer.
