source: josm/trunk/test/unit/org/openstreetmap/josm/command/ScaleCommandTest.java@ 13079

Last change on this file since 13079 was 13079, checked in by Don-vip, 6 years ago

see #15560 - EqualsVerifier does not work with newer Java versions -> disable tests automatically in this case
Workaround to https://github.com/jqno/equalsverifier/issues/177 / https://github.com/raphw/byte-buddy/issues/370
Inspired by https://issues.apache.org/jira/browse/SOLR-11606

File size: 5.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.command;
3
4import static org.junit.Assert.assertArrayEquals;
5import static org.junit.Assert.assertEquals;
6
7import java.util.ArrayList;
8import java.util.Arrays;
9
10import org.junit.Before;
11import org.junit.Rule;
12import org.junit.Test;
13import org.openstreetmap.josm.TestUtils;
14import org.openstreetmap.josm.command.CommandTest.CommandTestData;
15import org.openstreetmap.josm.data.coor.EastNorth;
16import org.openstreetmap.josm.data.coor.LatLon;
17import org.openstreetmap.josm.data.osm.DataSet;
18import org.openstreetmap.josm.data.osm.Node;
19import org.openstreetmap.josm.data.osm.OsmPrimitive;
20import org.openstreetmap.josm.data.osm.User;
21import org.openstreetmap.josm.gui.layer.OsmDataLayer;
22import org.openstreetmap.josm.testutils.JOSMTestRules;
23
24import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
25import nl.jqno.equalsverifier.EqualsVerifier;
26import nl.jqno.equalsverifier.Warning;
27
28/**
29 * Unit tests of {@link ScaleCommand} class.
30 */
31public class ScaleCommandTest {
32
33 /**
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().projection();
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 * Test a simple 2.5 scale. Tests {@link ScaleCommand#executeCommand()}
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 new DataSet(n1, n2, n3);
59 ScaleCommand scale = new ScaleCommand(Arrays.asList(n1, n2, n3), new EastNorth(0, 0));
60 scale.setScalingFactor(2.5);
61 scale.executeCommand();
62
63 assertEquals(25, n1.getEastNorth().east(), 0.0001);
64 assertEquals(25, n1.getEastNorth().north(), 0.0001);
65 assertEquals(-2.5, n2.getEastNorth().east(), 0.0001);
66 assertEquals(0, n2.getEastNorth().north(), 0.0001);
67 }
68
69 /**
70 * Test {@link ScaleCommand#undoCommand()}
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 new DataSet(n1, n2, n3);
78 ScaleCommand scale = new ScaleCommand(Arrays.asList(n1, n2, n3), new EastNorth(0, 0));
79 scale.setScalingFactor(2.5);
80 scale.executeCommand();
81 scale.undoCommand();
82
83 assertEquals(10, n1.getEastNorth().east(), 0.0001);
84 assertEquals(10, n1.getEastNorth().north(), 0.0001);
85 assertEquals(-1, n2.getEastNorth().east(), 0.0001);
86 assertEquals(0, n2.getEastNorth().north(), 0.0001);
87
88 scale.executeCommand();
89
90 assertEquals(-2.5, n2.getEastNorth().east(), 0.0001);
91 assertEquals(0, n2.getEastNorth().north(), 0.0001);
92 }
93
94 /**
95 * Tests {@link ScaleCommand#fillModifiedData(java.util.Collection, java.util.Collection, java.util.Collection)}
96 */
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 */
114 @Test
115 public void testGetParticipatingPrimitives() {
116 ScaleCommand command = new ScaleCommand(Arrays.asList(testData.existingNode), new EastNorth(0, 0));
117 command.executeCommand();
118 assertArrayEquals(new Object[] {testData.existingNode }, command.getParticipatingPrimitives().toArray());
119 }
120
121 /**
122 * Test {@link ScaleCommand#getDescriptionText()}
123 */
124 @Test
125 public void testDescription() {
126 assertEquals("Scale 1 node",
127 new ScaleCommand(Arrays.asList(testData.existingNode), new EastNorth(0, 0))
128 .getDescriptionText());
129 assertEquals("Scale 2 nodes",
130 new ScaleCommand(Arrays.asList(testData.existingNode, testData.existingNode2), new EastNorth(0, 0))
131 .getDescriptionText());
132 }
133
134 /**
135 * Unit test of methods {@link ScaleCommand#equals} and {@link ScaleCommand#hashCode}.
136 */
137 @Test
138 public void testEqualsContract() {
139 TestUtils.assumeWorkingEqualsVerifier();
140 EqualsVerifier.forClass(ScaleCommand.class).usingGetClass()
141 .withPrefabValues(LatLon.class,
142 LatLon.ZERO, new LatLon(45, 45))
143 .withPrefabValues(DataSet.class,
144 new DataSet(), new DataSet())
145 .withPrefabValues(User.class,
146 User.createOsmUser(1, "foo"), User.createOsmUser(2, "bar"))
147 .withPrefabValues(OsmDataLayer.class,
148 new OsmDataLayer(new DataSet(), "1", null), new OsmDataLayer(new DataSet(), "2", null))
149 .suppress(Warning.NONFINAL_FIELDS)
150 .verify();
151 }
152}
Note: See TracBrowser for help on using the repository browser.