Changeset 36194 in osm for applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/history/StreetsideRecordTest.java
- Timestamp:
- 2023-11-14T23:40:50+01:00 (18 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/history/StreetsideRecordTest.java
r36064 r36194 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.streetside.history; 3 4 3 5 4 import static org.junit.jupiter.api.Assertions.assertEquals; … … 35 34 class StreetsideRecordTest { 36 35 37 private StreetsideRecord record; 38 private StreetsideImage img1; 39 private StreetsideImage img2; 40 private StreetsideImage img3; 41 42 /** 43 * Creates a new {@link StreetsideRecord} object and 3 {@link StreetsideImage} 44 * objects. 45 */ 46 @BeforeEach 47 public void setUp() { 48 record = new StreetsideRecord(); 49 img1 = new StreetsideImage("key1__________________", new LatLon(0.1, 0.1), 0.1); 50 img2 = new StreetsideImage("key2__________________", new LatLon(0.2, 0.2), 0.2); 51 img3 = new StreetsideImage("key3__________________", new LatLon(0.3, 0.3), 0.3); 52 if (StreetsideLayer.hasInstance() && StreetsideLayer.getInstance().getData().getImages().size() >= 1) { 53 StreetsideLayer.getInstance().getData().getImages().clear(); 54 } 55 } 56 57 /** 58 * Test commands in general. 59 */ 60 @Test 61 void testCommand() { 62 StreetsideCommand cmd12 = new CommandMove( 63 new ConcurrentSkipListSet<>(Arrays.asList(img1, img2)), 64 0.1, 0.1); 65 StreetsideCommand cmd23 = new CommandMove( 66 new ConcurrentSkipListSet<>(Arrays.asList(img2, img3)), 67 0.1, 0.1); 68 StreetsideCommand cmd13 = new CommandMove( 69 new ConcurrentSkipListSet<>(Arrays.asList(img1, img3)), 70 0.1, 0.1); 71 StreetsideCommand cmd1 = new CommandMove( 72 new ConcurrentSkipListSet<>(Collections.singletonList(img1)), 0.1, 0.1); 73 StreetsideCommand cmd31 = new CommandMove( 74 new ConcurrentSkipListSet<>(Arrays.asList(img3, img1)), 75 0.2, 0.2); 76 record.addCommand(cmd12); 77 record.addCommand(cmd23); 78 79 assertEquals(1, record.position); 80 assertEquals(2, record.commandList.size()); 81 82 record.undo(); 83 84 assertEquals(0, record.position); 85 assertEquals(2, record.commandList.size()); 86 87 record.addCommand(cmd1); 88 89 assertEquals(1, record.position); 90 91 record.addCommand(cmd13); 92 93 assertEquals(2, record.position); 94 assertEquals(3, record.commandList.size()); 95 96 record.undo(); 97 record.redo(); 98 99 assertEquals(2, record.position); 100 assertEquals(3, record.commandList.size()); 101 102 record.addCommand(cmd31); 103 104 assertEquals(2, record.position); 105 assertEquals(3, record.commandList.size()); 106 107 record.addCommand(cmd1); 108 109 assertEquals(3, record.position); 110 assertEquals(4, record.commandList.size()); 111 } 112 113 /** 114 * Tests {@link CommandMove} class. 115 */ 116 @Test 117 void testCommandMove() { 118 CommandMove cmd1 = new CommandMove( 119 new ConcurrentSkipListSet<>(Arrays.asList(img1, img2)), 120 0.1, 0.1); 121 CommandMove cmd2 = new CommandMove( 122 new ConcurrentSkipListSet<>(Arrays.asList(img1, img2)), 123 0.1, 0.1); 124 125 record.addCommand(cmd1); 126 127 assertEquals(0.1, img1.getMovingLatLon().lat(), 0.01); 128 129 record.undo(); 130 131 assertEquals(0.0, img1.getMovingLatLon().lat(), 0.01); 132 133 record.redo(); 134 135 assertEquals(0.1, img1.getMovingLatLon().lat(), 0.01); 136 137 record.addCommand(cmd2); 138 record.undo(); 139 140 assertEquals(-0.1, img1.getMovingLatLon().lat(), 0.01); 141 142 record.redo(); 143 144 assertEquals(0.1, img1.getMovingLatLon().lat(), 0.01); 145 } 146 147 /** 148 * Tests {@link CommandTurn} class. 149 */ 150 @Test 151 void testCommandTurn() { 152 CommandTurn cmd1 = new CommandTurn( 153 new ConcurrentSkipListSet<>(Arrays.asList(img1, img2)), 154 0.2); 155 CommandTurn cmd2 = new CommandTurn( 156 new ConcurrentSkipListSet<>(Arrays.asList(img1, img2)), 157 0.1); 158 159 record.addCommand(cmd1); 160 record.undo(); 161 162 assertEquals(-0.1, img1.getMovingHe(), 0.01); 163 164 record.redo(); 165 166 assertEquals(0.1, img1.getMovingHe(), 0.01); 167 168 record.addCommand(cmd2); 169 record.undo(); 170 171 assertEquals(-0.2, img1.getMovingHe(), 0.01); 172 173 record.redo(); 174 175 assertEquals(0.1, img1.getMovingHe(), 0.01); 176 } 177 178 /** 179 * Tests {@link CommandJoin} class. 180 */ 181 @Test 182 void testCommandJoinClass() { 183 CommandJoin cmd1 = new CommandJoin(img1, img2); 184 CommandJoin cmd2 = new CommandJoin(img2, img3); 185 186 record.addCommand(cmd1); 187 assertEquals(2, img1.getSequence().getImages().size()); 188 assertEquals(img2, img1.next()); 189 record.undo(); 190 assertEquals(1, img1.getSequence().getImages().size()); 191 record.redo(); 192 record.addCommand(cmd2); 193 assertEquals(3, img1.getSequence().getImages().size()); 194 assertEquals(img3, img1.next().next()); 195 } 196 197 @Test 198 void testCommandJoinNull1() { 199 assertThrows(NullPointerException.class, () -> new CommandJoin(img1, null)); 200 } 201 202 @Test 203 void commandJoinNull2() { 204 assertThrows(NullPointerException.class, () -> new CommandJoin(null, img1)); 205 } 206 207 /** 208 * Tests {@link CommandUnjoin} class. 209 */ 210 @Test 211 void testCommandUnjoinClass() { 212 CommandJoin join1 = new CommandJoin(img1, img2); 213 CommandJoin join2 = new CommandJoin(img2, img3); 214 215 CommandUnjoin cmd1 = new CommandUnjoin( 216 Arrays.asList(new StreetsideAbstractImage[]{img1, img2})); 217 CommandUnjoin cmd2 = new CommandUnjoin( 218 Arrays.asList(new StreetsideAbstractImage[]{img2, img3})); 219 220 record.addCommand(join1); 221 record.addCommand(join2); 222 223 record.addCommand(cmd1); 224 assertEquals(1, img1.getSequence().getImages().size()); 225 record.undo(); 226 assertEquals(3, img1.getSequence().getImages().size()); 227 record.redo(); 228 record.addCommand(cmd2); 229 assertEquals(1, img1.getSequence().getImages().size()); 230 assertEquals(1, img2.getSequence().getImages().size()); 231 232 CommandUnjoin command = new CommandUnjoin(Arrays.asList(new StreetsideAbstractImage[]{img1, img2, img3})); 233 assertThrows(IllegalArgumentException.class, () -> record.addCommand(command)); 234 } 36 private StreetsideRecord record; 37 private StreetsideImage img1; 38 private StreetsideImage img2; 39 private StreetsideImage img3; 40 41 /** 42 * Creates a new {@link StreetsideRecord} object and 3 {@link StreetsideImage} 43 * objects. 44 */ 45 @BeforeEach 46 public void setUp() { 47 record = new StreetsideRecord(); 48 img1 = new StreetsideImage("key1__________________", new LatLon(0.1, 0.1), 0.1); 49 img2 = new StreetsideImage("key2__________________", new LatLon(0.2, 0.2), 0.2); 50 img3 = new StreetsideImage("key3__________________", new LatLon(0.3, 0.3), 0.3); 51 if (StreetsideLayer.hasInstance() && StreetsideLayer.getInstance().getData().getImages().size() >= 1) { 52 StreetsideLayer.getInstance().getData().getImages().clear(); 53 } 54 } 55 56 /** 57 * Test commands in general. 58 */ 59 @Test 60 void testCommand() { 61 StreetsideCommand cmd12 = new CommandMove(new ConcurrentSkipListSet<>(Arrays.asList(img1, img2)), 0.1, 0.1); 62 StreetsideCommand cmd23 = new CommandMove(new ConcurrentSkipListSet<>(Arrays.asList(img2, img3)), 0.1, 0.1); 63 StreetsideCommand cmd13 = new CommandMove(new ConcurrentSkipListSet<>(Arrays.asList(img1, img3)), 0.1, 0.1); 64 StreetsideCommand cmd1 = new CommandMove(new ConcurrentSkipListSet<>(Collections.singletonList(img1)), 0.1, 65 0.1); 66 StreetsideCommand cmd31 = new CommandMove(new ConcurrentSkipListSet<>(Arrays.asList(img3, img1)), 0.2, 0.2); 67 record.addCommand(cmd12); 68 record.addCommand(cmd23); 69 70 assertEquals(1, record.position); 71 assertEquals(2, record.commandList.size()); 72 73 record.undo(); 74 75 assertEquals(0, record.position); 76 assertEquals(2, record.commandList.size()); 77 78 record.addCommand(cmd1); 79 80 assertEquals(1, record.position); 81 82 record.addCommand(cmd13); 83 84 assertEquals(2, record.position); 85 assertEquals(3, record.commandList.size()); 86 87 record.undo(); 88 record.redo(); 89 90 assertEquals(2, record.position); 91 assertEquals(3, record.commandList.size()); 92 93 record.addCommand(cmd31); 94 95 assertEquals(2, record.position); 96 assertEquals(3, record.commandList.size()); 97 98 record.addCommand(cmd1); 99 100 assertEquals(3, record.position); 101 assertEquals(4, record.commandList.size()); 102 } 103 104 /** 105 * Tests {@link CommandMove} class. 106 */ 107 @Test 108 void testCommandMove() { 109 CommandMove cmd1 = new CommandMove(new ConcurrentSkipListSet<>(Arrays.asList(img1, img2)), 0.1, 0.1); 110 CommandMove cmd2 = new CommandMove(new ConcurrentSkipListSet<>(Arrays.asList(img1, img2)), 0.1, 0.1); 111 112 record.addCommand(cmd1); 113 114 assertEquals(0.1, img1.getMovingLatLon().lat(), 0.01); 115 116 record.undo(); 117 118 assertEquals(0.0, img1.getMovingLatLon().lat(), 0.01); 119 120 record.redo(); 121 122 assertEquals(0.1, img1.getMovingLatLon().lat(), 0.01); 123 124 record.addCommand(cmd2); 125 record.undo(); 126 127 assertEquals(-0.1, img1.getMovingLatLon().lat(), 0.01); 128 129 record.redo(); 130 131 assertEquals(0.1, img1.getMovingLatLon().lat(), 0.01); 132 } 133 134 /** 135 * Tests {@link CommandTurn} class. 136 */ 137 @Test 138 void testCommandTurn() { 139 CommandTurn cmd1 = new CommandTurn(new ConcurrentSkipListSet<>(Arrays.asList(img1, img2)), 0.2); 140 CommandTurn cmd2 = new CommandTurn(new ConcurrentSkipListSet<>(Arrays.asList(img1, img2)), 0.1); 141 142 record.addCommand(cmd1); 143 record.undo(); 144 145 assertEquals(-0.1, img1.getMovingHe(), 0.01); 146 147 record.redo(); 148 149 assertEquals(0.1, img1.getMovingHe(), 0.01); 150 151 record.addCommand(cmd2); 152 record.undo(); 153 154 assertEquals(-0.2, img1.getMovingHe(), 0.01); 155 156 record.redo(); 157 158 assertEquals(0.1, img1.getMovingHe(), 0.01); 159 } 160 161 /** 162 * Tests {@link CommandJoin} class. 163 */ 164 @Test 165 void testCommandJoinClass() { 166 CommandJoin cmd1 = new CommandJoin(img1, img2); 167 CommandJoin cmd2 = new CommandJoin(img2, img3); 168 169 record.addCommand(cmd1); 170 assertEquals(2, img1.getSequence().getImages().size()); 171 assertEquals(img2, img1.next()); 172 record.undo(); 173 assertEquals(1, img1.getSequence().getImages().size()); 174 record.redo(); 175 record.addCommand(cmd2); 176 assertEquals(3, img1.getSequence().getImages().size()); 177 assertEquals(img3, img1.next().next()); 178 } 179 180 @Test 181 void testCommandJoinNull1() { 182 assertThrows(NullPointerException.class, () -> new CommandJoin(img1, null)); 183 } 184 185 @Test 186 void commandJoinNull2() { 187 assertThrows(NullPointerException.class, () -> new CommandJoin(null, img1)); 188 } 189 190 /** 191 * Tests {@link CommandUnjoin} class. 192 */ 193 @Test 194 void testCommandUnjoinClass() { 195 CommandJoin join1 = new CommandJoin(img1, img2); 196 CommandJoin join2 = new CommandJoin(img2, img3); 197 198 CommandUnjoin cmd1 = new CommandUnjoin(Arrays.asList(new StreetsideAbstractImage[] { img1, img2 })); 199 CommandUnjoin cmd2 = new CommandUnjoin(Arrays.asList(new StreetsideAbstractImage[] { img2, img3 })); 200 201 record.addCommand(join1); 202 record.addCommand(join2); 203 204 record.addCommand(cmd1); 205 assertEquals(1, img1.getSequence().getImages().size()); 206 record.undo(); 207 assertEquals(3, img1.getSequence().getImages().size()); 208 record.redo(); 209 record.addCommand(cmd2); 210 assertEquals(1, img1.getSequence().getImages().size()); 211 assertEquals(1, img2.getSequence().getImages().size()); 212 213 CommandUnjoin command = new CommandUnjoin(Arrays.asList(new StreetsideAbstractImage[] { img1, img2, img3 })); 214 assertThrows(IllegalArgumentException.class, () -> record.addCommand(command)); 215 } 235 216 }
Note:
See TracChangeset
for help on using the changeset viewer.