Changeset 10663 in josm for trunk/test/unit/org/openstreetmap/josm/command/RotateCommandTest.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/RotateCommandTest.java
r9943 r10663 2 2 package org.openstreetmap.josm.command; 3 3 4 import org.junit.BeforeClass; 4 import static org.junit.Assert.assertArrayEquals; 5 import static org.junit.Assert.assertEquals; 6 7 import java.util.ArrayList; 8 import java.util.Arrays; 9 10 import org.junit.Before; 11 import org.junit.Rule; 5 12 import org.junit.Test; 6 import org.openstreetmap.josm.JOSMFixture; 13 import org.openstreetmap.josm.command.CommandTest.CommandTestData; 14 import org.openstreetmap.josm.data.coor.EastNorth; 7 15 import org.openstreetmap.josm.data.coor.LatLon; 8 16 import org.openstreetmap.josm.data.osm.DataSet; 17 import org.openstreetmap.josm.data.osm.Node; 18 import org.openstreetmap.josm.data.osm.OsmPrimitive; 9 19 import org.openstreetmap.josm.data.osm.User; 10 20 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 21 import org.openstreetmap.josm.testutils.JOSMTestRules; 11 22 23 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 12 24 import nl.jqno.equalsverifier.EqualsVerifier; 13 25 import nl.jqno.equalsverifier.Warning; … … 19 31 20 32 /** 21 * Setup test.33 * We need prefs for nodes. 22 34 */ 23 @BeforeClass 24 public static void setUpBeforeClass() { 25 JOSMFixture.createUnitTestFixture().init(false); 35 @Rule 36 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 37 public JOSMTestRules test = new JOSMTestRules().preferences().projection(); 38 private CommandTestData testData; 39 40 /** 41 * Set up the test data. 42 */ 43 @Before 44 public void createTestData() { 45 testData = new CommandTestData(); 46 } 47 48 /** 49 * Test a simple 45° rotation. Tests {@link RotateCommand#executeCommand()} 50 */ 51 @Test 52 public void testRotate() { 53 // pivot needs to be at 0,0 54 Node n1 = new Node(new EastNorth(10, 10)); 55 Node n2 = new Node(new EastNorth(-1, 0)); 56 Node n3 = new Node(new EastNorth(-9, -10)); 57 RotateCommand rotate = new RotateCommand(Arrays.asList(n1, n2, n3), new EastNorth(0, 0)); 58 rotate.setRotationAngle(Math.PI / 4); 59 rotate.executeCommand(); 60 61 assertEquals(Math.sqrt(2) * 10, n1.getEastNorth().east(), 0.0001); 62 assertEquals(0, n1.getEastNorth().north(), 0.0001); 63 assertEquals(-1 / Math.sqrt(2), n2.getEastNorth().east(), 0.0001); 64 assertEquals(1 / Math.sqrt(2), n2.getEastNorth().north(), 0.0001); 65 } 66 67 /** 68 * Test {@link RotateCommand#undoCommand()} 69 */ 70 @Test 71 public void testUndo() { 72 Node n1 = new Node(new EastNorth(10, 10)); 73 Node n2 = new Node(new EastNorth(-1, 0)); 74 Node n3 = new Node(new EastNorth(-9, -10)); 75 RotateCommand rotate = new RotateCommand(Arrays.asList(n1, n2, n3), new EastNorth(0, 0)); 76 rotate.setRotationAngle(Math.PI / 4); 77 rotate.executeCommand(); 78 rotate.undoCommand(); 79 80 assertEquals(10, n1.getEastNorth().east(), 0.0001); 81 assertEquals(10, n1.getEastNorth().north(), 0.0001); 82 assertEquals(-1, n2.getEastNorth().east(), 0.0001); 83 assertEquals(0, n2.getEastNorth().north(), 0.0001); 84 85 rotate.executeCommand(); 86 87 assertEquals(-1 / Math.sqrt(2), n2.getEastNorth().east(), 0.0001); 88 assertEquals(1 / Math.sqrt(2), n2.getEastNorth().north(), 0.0001); 89 } 90 91 /** 92 * Tests {@link RotateCommand#fillModifiedData(java.util.Collection, java.util.Collection, java.util.Collection)} 93 */ 94 @Test 95 public void testFillModifiedData() { 96 ArrayList<OsmPrimitive> modified = new ArrayList<>(); 97 ArrayList<OsmPrimitive> deleted = new ArrayList<>(); 98 ArrayList<OsmPrimitive> added = new ArrayList<>(); 99 RotateCommand command = new RotateCommand(Arrays.asList(testData.existingNode), 100 new EastNorth(0, 0)); 101 // intentionally empty 102 command.fillModifiedData(modified, deleted, added); 103 assertArrayEquals(new Object[] {}, modified.toArray()); 104 assertArrayEquals(new Object[] {}, deleted.toArray()); 105 assertArrayEquals(new Object[] {}, added.toArray()); 106 } 107 108 /** 109 * Tests {@link RotateCommand#getParticipatingPrimitives()} 110 */ 111 @Test 112 public void testGetParticipatingPrimitives() { 113 RotateCommand command = new RotateCommand(Arrays.asList(testData.existingNode), new EastNorth(0, 0)); 114 command.executeCommand(); 115 assertArrayEquals(new Object[] {testData.existingNode}, command.getParticipatingPrimitives().toArray()); 116 } 117 118 /** 119 * Test {@link RotateCommand#getDescriptionText()} 120 */ 121 @Test 122 public void testDescription() { 123 assertEquals("Rotate 1 node", 124 new RotateCommand(Arrays.asList(testData.existingNode), new EastNorth(0, 0)) 125 .getDescriptionText()); 126 assertEquals("Rotate 2 nodes", 127 new RotateCommand(Arrays.asList(testData.existingNode, testData.existingNode2), new EastNorth(0, 0)) 128 .getDescriptionText()); 26 129 } 27 130 … … 32 135 public void equalsContract() { 33 136 EqualsVerifier.forClass(RotateCommand.class).usingGetClass() 34 .withPrefabValues(LatLon.class, 35 LatLon.ZERO, new LatLon(45, 45)) 36 .withPrefabValues(DataSet.class, 37 new DataSet(), new DataSet()) 38 .withPrefabValues(User.class, 39 User.createOsmUser(1, "foo"), User.createOsmUser(2, "bar")) 40 .withPrefabValues(OsmDataLayer.class, 41 new OsmDataLayer(new DataSet(), "1", null), new OsmDataLayer(new DataSet(), "2", null)) 42 .suppress(Warning.NONFINAL_FIELDS) 43 .verify(); 137 .withPrefabValues(LatLon.class, LatLon.ZERO, new LatLon(45, 45)) 138 .withPrefabValues(DataSet.class, new DataSet(), new DataSet()) 139 .withPrefabValues(User.class, User.createOsmUser(1, "foo"), User.createOsmUser(2, "bar")) 140 .withPrefabValues(OsmDataLayer.class, new OsmDataLayer(new DataSet(), "1", null), 141 new OsmDataLayer(new DataSet(), "2", null)) 142 .suppress(Warning.NONFINAL_FIELDS).verify(); 44 143 } 45 144 }
Note:
See TracChangeset
for help on using the changeset viewer.
