Changeset 1631 in josm for trunk/test
- Timestamp:
- 2009-06-01T22:20:03+02:00 (16 years ago)
- Location:
- trunk/test/unit/org/openstreetmap/josm/gui/conflict
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/gui/conflict/nodes/NodeListMergeModelTest.java
r1622 r1631 2 2 package org.openstreetmap.josm.gui.conflict.nodes; 3 3 4 import static org.fest.reflect.core.Reflection.field; 4 5 import static org.junit.Assert.assertEquals; 5 6 import static org.junit.Assert.assertTrue; … … 8 9 import java.beans.PropertyChangeEvent; 9 10 import java.beans.PropertyChangeListener; 10 import java.lang.reflect.Field;11 11 import java.util.ArrayList; 12 12 import java.util.List; … … 17 17 import org.openstreetmap.josm.data.osm.Node; 18 18 import org.openstreetmap.josm.data.osm.Way; 19 import static org.fest.reflect.core.Reflection.field;20 19 21 20 public class NodeListMergeModelTest { 22 23 protected List<Node> inspectNodeList(NodeListMergeModel model, String name) throws NoSuchFieldException, IllegalAccessException{ 24 Field f = NodeListMergeModel.class.getDeclaredField(name); 25 f.setAccessible(true); 26 Object o = f.get(model); 27 return (List<Node>)o; 28 } 29 21 22 protected List<Node> inspectNodeList(NodeListMergeModel model, String name) { 23 return field(name).ofType(ArrayList.class) 24 .in(model) 25 .get(); 26 } 27 30 28 protected DefaultListSelectionModel inspectListSelectionModel(NodeListMergeModel model, String name) throws NoSuchFieldException, IllegalAccessException { 31 Field f = NodeListMergeModel.class.getDeclaredField(name); 32 f.setAccessible(true); 33 Object o = f.get(model); 34 return (DefaultListSelectionModel)o; 35 36 } 37 29 return field(name).ofType(DefaultListSelectionModel.class) 30 .in(model) 31 .get(); 32 } 33 38 34 protected void ensureSelected(DefaultListSelectionModel model, Object... idx) { 39 35 if (idx == null) return; … … 43 39 assertTrue("expected row " + j + " to be selected", model.isSelectedIndex(j)); 44 40 break; 45 } 41 } 46 42 try { 47 int rows[] = (int[])idx[i];48 if (rows == null || rows.length != 2) {49 fail("illegal selection range. Either null or not length 2: " + rows);50 }51 if (rows[0] > rows[1]) {52 fail("illegal selection range. lower bound > upper bound ");53 }54 for (int j = rows[0]; j <= rows[1]; j++) {55 assertTrue("expected row " + j + " to be selected", model.isSelectedIndex(j));56 }43 int rows[] = (int[])idx[i]; 44 if (rows == null || rows.length != 2) { 45 fail("illegal selection range. Either null or not length 2: " + rows); 46 } 47 if (rows[0] > rows[1]) { 48 fail("illegal selection range. lower bound > upper bound "); 49 } 50 for (int j = rows[0]; j <= rows[1]; j++) { 51 assertTrue("expected row " + j + " to be selected", model.isSelectedIndex(j)); 52 } 57 53 } catch(ClassCastException e) { 58 54 fail("illegal selection range:" + idx[i]); 59 } 55 } 60 56 } 61 57 } 62 58 63 59 @Test 64 60 public void test_copyMyNodesToTop_1() throws IllegalAccessException, NoSuchFieldException { 65 61 NodeListMergeModel model = new NodeListMergeModel(); 66 67 Way myWay = new Way(1); 68 myWay.nodes.add(new Node(2)); 69 myWay.nodes.add(new Node(3)); 70 Way theirWay = new Way(1); 71 72 model.populate(myWay, theirWay); 73 model.copyMy NodesToTop(new int[]{0});74 75 List<Node> mergedNodes = inspectNodeList(model, "merged Nodes");76 62 63 Way myWay = new Way(1); 64 myWay.nodes.add(new Node(2)); 65 myWay.nodes.add(new Node(3)); 66 Way theirWay = new Way(1); 67 68 model.populate(myWay, theirWay); 69 model.copyMyToTop(new int[]{0}); 70 71 List<Node> mergedNodes = inspectNodeList(model, "mergedEntries"); 72 77 73 assertEquals(1, mergedNodes.size()); 78 74 assertEquals(2, mergedNodes.get(0).id); 79 80 DefaultListSelectionModel mergedSelection = inspectListSelectionModel(model, "merged NodesSelectionModel");81 ensureSelected(mergedSelection, 0); 82 83 } 84 85 75 76 DefaultListSelectionModel mergedSelection = inspectListSelectionModel(model, "mergedEntriesSelectionModel"); 77 ensureSelected(mergedSelection, 0); 78 79 } 80 81 86 82 @Test 87 83 public void test_copyMyNodesToTop_2() throws IllegalAccessException, NoSuchFieldException { 88 84 NodeListMergeModel model = new NodeListMergeModel(); 89 85 90 91 Way myWay = new Way(1); 92 myWay.nodes.add(new Node(2)); 93 myWay.nodes.add(new Node(3)); 94 Way theirWay = new Way(1); 95 96 model.populate(myWay, theirWay); 97 98 List<Node> mergedNodes = inspectNodeList(model, "merged Nodes");86 87 Way myWay = new Way(1); 88 myWay.nodes.add(new Node(2)); 89 myWay.nodes.add(new Node(3)); 90 Way theirWay = new Way(1); 91 92 model.populate(myWay, theirWay); 93 94 List<Node> mergedNodes = inspectNodeList(model, "mergedEntries"); 99 95 mergedNodes.add(new Node(1)); 100 96 101 model.copyMy NodesToTop(new int[]{0});102 103 mergedNodes = inspectNodeList(model, "merged Nodes");97 model.copyMyToTop(new int[]{0}); 98 99 mergedNodes = inspectNodeList(model, "mergedEntries"); 104 100 assertEquals(2, mergedNodes.size()); 105 101 assertEquals(2, mergedNodes.get(0).id); 106 102 assertEquals(1, mergedNodes.get(1).id); 107 108 DefaultListSelectionModel mergedSelection = inspectListSelectionModel(model, "merged NodesSelectionModel");109 ensureSelected(mergedSelection, 0); 110 111 } 112 113 114 115 116 103 104 DefaultListSelectionModel mergedSelection = inspectListSelectionModel(model, "mergedEntriesSelectionModel"); 105 ensureSelected(mergedSelection, 0); 106 107 } 108 109 110 111 112 117 113 @Test 118 114 public void test_copyMyNodesToTop_3() throws IllegalAccessException, NoSuchFieldException { 119 115 NodeListMergeModel model = new NodeListMergeModel(); 120 116 121 122 Way myWay = new Way(1); 123 myWay.nodes.add(new Node(2)); 124 myWay.nodes.add(new Node(3)); 125 Way theirWay = new Way(1); 126 127 model.populate(myWay, theirWay); 128 129 List<Node> mergedNodes = inspectNodeList(model, "merged Nodes");117 118 Way myWay = new Way(1); 119 myWay.nodes.add(new Node(2)); 120 myWay.nodes.add(new Node(3)); 121 Way theirWay = new Way(1); 122 123 model.populate(myWay, theirWay); 124 125 List<Node> mergedNodes = inspectNodeList(model, "mergedEntries"); 130 126 mergedNodes.add(new Node(1)); 131 127 132 model.copyMy NodesToTop(new int[]{1}); // copy node 3133 134 mergedNodes = inspectNodeList(model, "merged Nodes");128 model.copyMyToTop(new int[]{1}); // copy node 3 129 130 mergedNodes = inspectNodeList(model, "mergedEntries"); 135 131 assertEquals(2, mergedNodes.size()); 136 132 assertEquals(3, mergedNodes.get(0).id); // my node 3 at position 0 137 133 assertEquals(1, mergedNodes.get(1).id); // already merged node 1 at position 1 138 139 DefaultListSelectionModel mergedSelection = inspectListSelectionModel(model, "merged NodesSelectionModel");140 ensureSelected(mergedSelection, 0); 141 } 142 134 135 DefaultListSelectionModel mergedSelection = inspectListSelectionModel(model, "mergedEntriesSelectionModel"); 136 ensureSelected(mergedSelection, 0); 137 } 138 143 139 @Test 144 140 public void test_copyMyNodesToTop_4() throws IllegalAccessException, NoSuchFieldException { 145 141 NodeListMergeModel model = new NodeListMergeModel(); 146 142 147 143 148 144 Way myWay = new Way(1); 149 145 myWay.nodes.add(new Node(2)); … … 154 150 model.populate(myWay, theirWay); 155 151 156 List<Node> mergedNodes = inspectNodeList(model, "merged Nodes");152 List<Node> mergedNodes = inspectNodeList(model, "mergedEntries"); 157 153 mergedNodes.add(new Node(1)); 158 154 159 model.copyMy NodesToTop(new int[]{1,2}); // copy node 3 and 4160 161 mergedNodes = inspectNodeList(model, "merged Nodes");155 model.copyMyToTop(new int[]{1,2}); // copy node 3 and 4 156 157 mergedNodes = inspectNodeList(model, "mergedEntries"); 162 158 assertEquals(3, mergedNodes.size()); 163 159 assertEquals(3, mergedNodes.get(0).id); // my node 3 at position 0 164 160 assertEquals(4, mergedNodes.get(1).id); // my node 4 at position 1 165 161 assertEquals(1, mergedNodes.get(2).id); // already merged node 1 at position 2 166 167 DefaultListSelectionModel mergedSelection = inspectListSelectionModel(model, "merged NodesSelectionModel");168 ensureSelected(mergedSelection, 0,1); // first two rows selected 169 } 170 171 162 163 DefaultListSelectionModel mergedSelection = inspectListSelectionModel(model, "mergedEntriesSelectionModel"); 164 ensureSelected(mergedSelection, 0,1); // first two rows selected 165 } 166 167 172 168 @Test 173 169 public void test_copyMyNodesToEnd_1() throws IllegalAccessException, NoSuchFieldException { 174 170 NodeListMergeModel model = new NodeListMergeModel(); 175 176 Way myWay = new Way(1); 177 myWay.nodes.add(new Node(2)); 178 myWay.nodes.add(new Node(3)); 179 Way theirWay = new Way(1); 180 181 model.populate(myWay, theirWay); 182 model.copyMy NodesToEnd(new int[]{0});183 184 List<Node> mergedNodes = inspectNodeList(model, "merged Nodes");185 171 172 Way myWay = new Way(1); 173 myWay.nodes.add(new Node(2)); 174 myWay.nodes.add(new Node(3)); 175 Way theirWay = new Way(1); 176 177 model.populate(myWay, theirWay); 178 model.copyMyToEnd(new int[]{0}); 179 180 List<Node> mergedNodes = inspectNodeList(model, "mergedEntries"); 181 186 182 assertEquals(1, mergedNodes.size()); 187 183 assertEquals(2, mergedNodes.get(0).id); 188 189 DefaultListSelectionModel mergedSelection = inspectListSelectionModel(model, "merged NodesSelectionModel");190 ensureSelected(mergedSelection, 0); 191 } 192 184 185 DefaultListSelectionModel mergedSelection = inspectListSelectionModel(model, "mergedEntriesSelectionModel"); 186 ensureSelected(mergedSelection, 0); 187 } 188 193 189 @Test 194 190 public void test_copyMyNodesToEnd_2() throws IllegalAccessException, NoSuchFieldException { 195 191 NodeListMergeModel model = new NodeListMergeModel(); 196 197 Way myWay = new Way(1); 198 myWay.nodes.add(new Node(2)); 199 myWay.nodes.add(new Node(3)); 200 Way theirWay = new Way(1); 201 202 model.populate(myWay, theirWay); 203 204 List<Node> mergedNodes = inspectNodeList(model, "merged Nodes");192 193 Way myWay = new Way(1); 194 myWay.nodes.add(new Node(2)); 195 myWay.nodes.add(new Node(3)); 196 Way theirWay = new Way(1); 197 198 model.populate(myWay, theirWay); 199 200 List<Node> mergedNodes = inspectNodeList(model, "mergedEntries"); 205 201 mergedNodes.add(new Node(1)); 206 202 207 model.copyMy NodesToEnd(new int[]{0});208 209 mergedNodes = inspectNodeList(model, "merged Nodes");203 model.copyMyToEnd(new int[]{0}); 204 205 mergedNodes = inspectNodeList(model, "mergedEntries"); 210 206 assertEquals(2, mergedNodes.size()); 211 207 assertEquals(1, mergedNodes.get(0).id); // already merged node 1 at position 0 212 208 assertEquals(2, mergedNodes.get(1).id); // copied node 2 at position 1 213 214 DefaultListSelectionModel mergedSelection = inspectListSelectionModel(model, "merged NodesSelectionModel");215 ensureSelected(mergedSelection, 1); 216 } 217 209 210 DefaultListSelectionModel mergedSelection = inspectListSelectionModel(model, "mergedEntriesSelectionModel"); 211 ensureSelected(mergedSelection, 1); 212 } 213 218 214 @Test 219 215 public void test_copyMyNodesToEnd_3() throws IllegalAccessException, NoSuchFieldException { 220 216 NodeListMergeModel model = new NodeListMergeModel(); 221 217 222 223 Way myWay = new Way(1); 224 myWay.nodes.add(new Node(2)); 225 myWay.nodes.add(new Node(3)); 226 Way theirWay = new Way(1); 227 228 model.populate(myWay, theirWay); 229 230 List<Node> mergedNodes = inspectNodeList(model, "merged Nodes");218 219 Way myWay = new Way(1); 220 myWay.nodes.add(new Node(2)); 221 myWay.nodes.add(new Node(3)); 222 Way theirWay = new Way(1); 223 224 model.populate(myWay, theirWay); 225 226 List<Node> mergedNodes = inspectNodeList(model, "mergedEntries"); 231 227 mergedNodes.add(new Node(1)); 232 228 233 model.copyMy NodesToEnd(new int[]{1}); // copy node 3234 235 mergedNodes = inspectNodeList(model, "merged Nodes");229 model.copyMyToEnd(new int[]{1}); // copy node 3 230 231 mergedNodes = inspectNodeList(model, "mergedEntries"); 236 232 assertEquals(2, mergedNodes.size()); 237 233 assertEquals(1, mergedNodes.get(0).id); // already merged node 1 at position 0 238 234 assertEquals(3, mergedNodes.get(1).id); // my node 3 at position 1 239 240 241 DefaultListSelectionModel mergedSelection = inspectListSelectionModel(model, "merged NodesSelectionModel");242 ensureSelected(mergedSelection, 1); 243 } 244 235 236 237 DefaultListSelectionModel mergedSelection = inspectListSelectionModel(model, "mergedEntriesSelectionModel"); 238 ensureSelected(mergedSelection, 1); 239 } 240 245 241 @Test 246 242 public void test_copyMyNodesToEnd_4() throws IllegalAccessException, NoSuchFieldException { 247 243 NodeListMergeModel model = new NodeListMergeModel(); 248 244 249 245 250 246 Way myWay = new Way(1); 251 247 myWay.nodes.add(new Node(2)); … … 256 252 model.populate(myWay, theirWay); 257 253 258 List<Node> mergedNodes = inspectNodeList(model, "merged Nodes");254 List<Node> mergedNodes = inspectNodeList(model, "mergedEntries"); 259 255 mergedNodes.add(new Node(1)); 260 256 261 model.copyMy NodesToEnd(new int[]{1,2}); // copy node 3 and 4262 263 mergedNodes = inspectNodeList(model, "merged Nodes");257 model.copyMyToEnd(new int[]{1,2}); // copy node 3 and 4 258 259 mergedNodes = inspectNodeList(model, "mergedEntries"); 264 260 assertEquals(3, mergedNodes.size()); 265 261 assertEquals(1, mergedNodes.get(0).id); // already merged node 1 at position 0 … … 267 263 assertEquals(4, mergedNodes.get(2).id); // my node 4 at position 2 268 264 269 270 DefaultListSelectionModel mergedSelection = inspectListSelectionModel(model, "merged NodesSelectionModel");271 ensureSelected(mergedSelection, 1,2); // last two rows selected 272 } 273 265 266 DefaultListSelectionModel mergedSelection = inspectListSelectionModel(model, "mergedEntriesSelectionModel"); 267 ensureSelected(mergedSelection, 1,2); // last two rows selected 268 } 269 274 270 /* ----------------------------------------------------------------------------- */ 275 271 /* copyMyNodesBeforeCurrent */ 276 272 /* ----------------------------------------------------------------------------- */ 277 273 278 274 @Test 279 275 public void test_copyMyNodesBeforeCurrent_1() throws IllegalAccessException, NoSuchFieldException { 280 276 NodeListMergeModel model = new NodeListMergeModel(); 281 282 Way myWay = new Way(1); 283 myWay.nodes.add(new Node(1)); 284 myWay.nodes.add(new Node(2)); 285 Way theirWay = new Way(1); 286 287 model.populate(myWay, theirWay); 288 List<Node> mergedNodes = inspectNodeList(model, "merged Nodes");289 mergedNodes.add(new Node(10)); 290 mergedNodes.add(new Node(11)); 291 mergedNodes.add(new Node(12)); 292 293 model.copyMy NodesBeforeCurrent(new int[]{0}, 1);294 277 278 Way myWay = new Way(1); 279 myWay.nodes.add(new Node(1)); 280 myWay.nodes.add(new Node(2)); 281 Way theirWay = new Way(1); 282 283 model.populate(myWay, theirWay); 284 List<Node> mergedNodes = inspectNodeList(model, "mergedEntries"); 285 mergedNodes.add(new Node(10)); 286 mergedNodes.add(new Node(11)); 287 mergedNodes.add(new Node(12)); 288 289 model.copyMyBeforeCurrent(new int[]{0}, 1); 290 295 291 assertEquals(4, mergedNodes.size()); 296 assertEquals(10, mergedNodes.get(0).id); // already merged node 292 assertEquals(10, mergedNodes.get(0).id); // already merged node 297 293 assertEquals(1, mergedNodes.get(1).id); // copied node 1 at position 1 298 assertEquals(11, mergedNodes.get(2).id); // already merged node 299 assertEquals(12, mergedNodes.get(3).id); // already merged node 300 301 DefaultListSelectionModel mergedSelection = inspectListSelectionModel(model, "merged NodesSelectionModel");302 ensureSelected(mergedSelection, 1); // position 1 selected 303 } 304 305 294 assertEquals(11, mergedNodes.get(2).id); // already merged node 295 assertEquals(12, mergedNodes.get(3).id); // already merged node 296 297 DefaultListSelectionModel mergedSelection = inspectListSelectionModel(model, "mergedEntriesSelectionModel"); 298 ensureSelected(mergedSelection, 1); // position 1 selected 299 } 300 301 306 302 @Test 307 303 public void test_copyMyNodesBeforeCurrent_2() throws IllegalAccessException, NoSuchFieldException { 308 304 NodeListMergeModel model = new NodeListMergeModel(); 309 310 Way myWay = new Way(1); 311 myWay.nodes.add(new Node(1)); 312 myWay.nodes.add(new Node(2)); 313 Way theirWay = new Way(1); 314 315 model.populate(myWay, theirWay); 316 List<Node> mergedNodes = inspectNodeList(model, "merged Nodes");317 mergedNodes.add(new Node(10)); 318 mergedNodes.add(new Node(11)); 319 mergedNodes.add(new Node(12)); 320 321 model.copyMy NodesBeforeCurrent(new int[]{0,1}, 0);322 305 306 Way myWay = new Way(1); 307 myWay.nodes.add(new Node(1)); 308 myWay.nodes.add(new Node(2)); 309 Way theirWay = new Way(1); 310 311 model.populate(myWay, theirWay); 312 List<Node> mergedNodes = inspectNodeList(model, "mergedEntries"); 313 mergedNodes.add(new Node(10)); 314 mergedNodes.add(new Node(11)); 315 mergedNodes.add(new Node(12)); 316 317 model.copyMyBeforeCurrent(new int[]{0,1}, 0); 318 323 319 assertEquals(5, mergedNodes.size()); 324 320 assertEquals(1, mergedNodes.get(0).id); // copied node 1 at position 0 325 321 assertEquals(2, mergedNodes.get(1).id); // copied node 2 at position 1 326 assertEquals(10, mergedNodes.get(2).id); // already merged node 327 assertEquals(11, mergedNodes.get(3).id); // already merged node 328 assertEquals(12, mergedNodes.get(4).id); // already merged node 329 330 DefaultListSelectionModel mergedSelection = inspectListSelectionModel(model, "merged NodesSelectionModel");331 ensureSelected(mergedSelection, 0,1); // position 0 and 1 selected 332 } 333 322 assertEquals(10, mergedNodes.get(2).id); // already merged node 323 assertEquals(11, mergedNodes.get(3).id); // already merged node 324 assertEquals(12, mergedNodes.get(4).id); // already merged node 325 326 DefaultListSelectionModel mergedSelection = inspectListSelectionModel(model, "mergedEntriesSelectionModel"); 327 ensureSelected(mergedSelection, 0,1); // position 0 and 1 selected 328 } 329 334 330 @Test 335 331 public void test_copyMyNodesBeforeCurrent_3() throws IllegalAccessException, NoSuchFieldException { 336 332 NodeListMergeModel model = new NodeListMergeModel(); 337 338 Way myWay = new Way(1); 339 myWay.nodes.add(new Node(1)); 340 myWay.nodes.add(new Node(2)); 341 Way theirWay = new Way(1); 342 343 model.populate(myWay, theirWay); 344 List<Node> mergedNodes = inspectNodeList(model, "merged Nodes");345 mergedNodes.add(new Node(10)); 346 mergedNodes.add(new Node(11)); 347 mergedNodes.add(new Node(12)); 348 349 try { 350 model.copyMy NodesBeforeCurrent(new int[]{0,1}, -1);333 334 Way myWay = new Way(1); 335 myWay.nodes.add(new Node(1)); 336 myWay.nodes.add(new Node(2)); 337 Way theirWay = new Way(1); 338 339 model.populate(myWay, theirWay); 340 List<Node> mergedNodes = inspectNodeList(model, "mergedEntries"); 341 mergedNodes.add(new Node(10)); 342 mergedNodes.add(new Node(11)); 343 mergedNodes.add(new Node(12)); 344 345 try { 346 model.copyMyBeforeCurrent(new int[]{0,1}, -1); 351 347 fail("expected IllegalArgumentException"); 352 348 } catch(IllegalArgumentException e) { 353 349 // OK 354 350 } 355 356 try { 357 model.copyMy NodesBeforeCurrent(new int[]{0,1}, 3);351 352 try { 353 model.copyMyBeforeCurrent(new int[]{0,1}, 3); 358 354 fail("expected IllegalArgumentException"); 359 355 } catch(IllegalArgumentException e) { 360 356 // OK 361 } 362 } 363 357 } 358 } 359 364 360 /* ----------------------------------------------------------------------------- */ 365 361 /* copyMyNodesAfterCurrent */ … … 368 364 public void test_copyMyNodesAfterCurrent_1() throws IllegalAccessException, NoSuchFieldException { 369 365 NodeListMergeModel model = new NodeListMergeModel(); 370 371 Way myWay = new Way(1); 372 myWay.nodes.add(new Node(1)); 373 myWay.nodes.add(new Node(2)); 374 Way theirWay = new Way(1); 375 376 model.populate(myWay, theirWay); 377 List<Node> mergedNodes = inspectNodeList(model, "merged Nodes");378 mergedNodes.add(new Node(10)); 379 mergedNodes.add(new Node(11)); 380 mergedNodes.add(new Node(12)); 381 382 model.copyMy NodesAfterCurrent(new int[]{0}, 1);383 366 367 Way myWay = new Way(1); 368 myWay.nodes.add(new Node(1)); 369 myWay.nodes.add(new Node(2)); 370 Way theirWay = new Way(1); 371 372 model.populate(myWay, theirWay); 373 List<Node> mergedNodes = inspectNodeList(model, "mergedEntries"); 374 mergedNodes.add(new Node(10)); 375 mergedNodes.add(new Node(11)); 376 mergedNodes.add(new Node(12)); 377 378 model.copyMyAfterCurrent(new int[]{0}, 1); 379 384 380 assertEquals(4, mergedNodes.size()); 385 assertEquals(10, mergedNodes.get(0).id); // already merged node 386 assertEquals(11, mergedNodes.get(1).id); // already merged node 381 assertEquals(10, mergedNodes.get(0).id); // already merged node 382 assertEquals(11, mergedNodes.get(1).id); // already merged node 387 383 assertEquals(1, mergedNodes.get(2).id); // copied node 1 at position 2 388 assertEquals(12, mergedNodes.get(3).id); // already merged node 389 390 DefaultListSelectionModel mergedSelection = inspectListSelectionModel(model, "merged NodesSelectionModel");391 ensureSelected(mergedSelection, 2); // position 1 selected 392 } 393 394 384 assertEquals(12, mergedNodes.get(3).id); // already merged node 385 386 DefaultListSelectionModel mergedSelection = inspectListSelectionModel(model, "mergedEntriesSelectionModel"); 387 ensureSelected(mergedSelection, 2); // position 1 selected 388 } 389 390 395 391 @Test 396 392 public void test_copyMyNodesAfterCurrent_2() throws IllegalAccessException, NoSuchFieldException { 397 393 NodeListMergeModel model = new NodeListMergeModel(); 398 399 Way myWay = new Way(1); 400 myWay.nodes.add(new Node(1)); 401 myWay.nodes.add(new Node(2)); 402 myWay.nodes.add(new Node(3)); 403 Way theirWay = new Way(1); 404 405 model.populate(myWay, theirWay); 406 List<Node> mergedNodes = inspectNodeList(model, "merged Nodes");407 mergedNodes.add(new Node(10)); 408 mergedNodes.add(new Node(11)); 409 mergedNodes.add(new Node(12)); 410 411 model.copyMy NodesAfterCurrent(new int[]{0,1}, 2);412 394 395 Way myWay = new Way(1); 396 myWay.nodes.add(new Node(1)); 397 myWay.nodes.add(new Node(2)); 398 myWay.nodes.add(new Node(3)); 399 Way theirWay = new Way(1); 400 401 model.populate(myWay, theirWay); 402 List<Node> mergedNodes = inspectNodeList(model, "mergedEntries"); 403 mergedNodes.add(new Node(10)); 404 mergedNodes.add(new Node(11)); 405 mergedNodes.add(new Node(12)); 406 407 model.copyMyAfterCurrent(new int[]{0,1}, 2); 408 413 409 assertEquals(5, mergedNodes.size()); 414 assertEquals(10, mergedNodes.get(0).id); // already merged node 410 assertEquals(10, mergedNodes.get(0).id); // already merged node 415 411 assertEquals(11, mergedNodes.get(1).id); // already merged node 416 412 assertEquals(12, mergedNodes.get(2).id); // already merged node 417 413 assertEquals(1, mergedNodes.get(3).id); // copied node 1 at position 3 418 414 assertEquals(2, mergedNodes.get(4).id); // copied node 2 at position 4 419 420 421 DefaultListSelectionModel mergedSelection = inspectListSelectionModel(model, "merged NodesSelectionModel");422 ensureSelected(mergedSelection, 3,4); // position 3,4 selected 423 } 424 415 416 417 DefaultListSelectionModel mergedSelection = inspectListSelectionModel(model, "mergedEntriesSelectionModel"); 418 ensureSelected(mergedSelection, 3,4); // position 3,4 selected 419 } 420 425 421 @Test 426 422 public void test_copyMyNodesAfterCurrent_3() throws IllegalAccessException, NoSuchFieldException { 427 423 NodeListMergeModel model = new NodeListMergeModel(); 428 429 Way myWay = new Way(1); 430 myWay.nodes.add(new Node(1)); 431 myWay.nodes.add(new Node(2)); 432 myWay.nodes.add(new Node(3)); 433 Way theirWay = new Way(1); 434 435 model.populate(myWay, theirWay); 436 List<Node> mergedNodes = inspectNodeList(model, "merged Nodes");437 mergedNodes.add(new Node(10)); 438 mergedNodes.add(new Node(11)); 439 mergedNodes.add(new Node(12)); 440 441 model.copyMy NodesAfterCurrent(new int[]{0,2}, 0);442 424 425 Way myWay = new Way(1); 426 myWay.nodes.add(new Node(1)); 427 myWay.nodes.add(new Node(2)); 428 myWay.nodes.add(new Node(3)); 429 Way theirWay = new Way(1); 430 431 model.populate(myWay, theirWay); 432 List<Node> mergedNodes = inspectNodeList(model, "mergedEntries"); 433 mergedNodes.add(new Node(10)); 434 mergedNodes.add(new Node(11)); 435 mergedNodes.add(new Node(12)); 436 437 model.copyMyAfterCurrent(new int[]{0,2}, 0); 438 443 439 assertEquals(5, mergedNodes.size()); 444 assertEquals(10, mergedNodes.get(0).id); // already merged node 440 assertEquals(10, mergedNodes.get(0).id); // already merged node 445 441 assertEquals(1, mergedNodes.get(1).id); // copied node 1 at position 1 446 442 assertEquals(3, mergedNodes.get(2).id); // copied node 3 at position 2 447 443 assertEquals(11, mergedNodes.get(3).id); // already merged node 448 444 assertEquals(12, mergedNodes.get(4).id); // already merged node 449 450 DefaultListSelectionModel mergedSelection = inspectListSelectionModel(model, "merged NodesSelectionModel");451 ensureSelected(mergedSelection, 1,2); // position 1,2 selected 452 } 453 445 446 DefaultListSelectionModel mergedSelection = inspectListSelectionModel(model, "mergedEntriesSelectionModel"); 447 ensureSelected(mergedSelection, 1,2); // position 1,2 selected 448 } 449 454 450 @Test 455 451 public void test_copyMyNodesAfterCurrent_4() throws IllegalAccessException, NoSuchFieldException { 456 452 NodeListMergeModel model = new NodeListMergeModel(); 457 458 Way myWay = new Way(1); 459 myWay.nodes.add(new Node(1)); 460 myWay.nodes.add(new Node(2)); 461 Way theirWay = new Way(1); 462 463 model.populate(myWay, theirWay); 464 List<Node> mergedNodes = inspectNodeList(model, "merged Nodes");465 mergedNodes.add(new Node(10)); 466 mergedNodes.add(new Node(11)); 467 mergedNodes.add(new Node(12)); 468 469 try { 470 model.copyMy NodesAfterCurrent(new int[]{0,1}, -1);453 454 Way myWay = new Way(1); 455 myWay.nodes.add(new Node(1)); 456 myWay.nodes.add(new Node(2)); 457 Way theirWay = new Way(1); 458 459 model.populate(myWay, theirWay); 460 List<Node> mergedNodes = inspectNodeList(model, "mergedEntries"); 461 mergedNodes.add(new Node(10)); 462 mergedNodes.add(new Node(11)); 463 mergedNodes.add(new Node(12)); 464 465 try { 466 model.copyMyAfterCurrent(new int[]{0,1}, -1); 471 467 fail("expected IllegalArgumentException"); 472 468 } catch(IllegalArgumentException e) { 473 469 // OK 474 470 } 475 476 try { 477 model.copyMy NodesAfterCurrent(new int[]{0,1}, 3);471 472 try { 473 model.copyMyAfterCurrent(new int[]{0,1}, 3); 478 474 fail("expected IllegalArgumentException"); 479 475 } catch(IllegalArgumentException e) { 480 476 // OK 481 } 482 } 483 477 } 478 } 479 484 480 /* ----------------------------------------------------------------------------- */ 485 481 /* moveUpMergedNodes */ … … 488 484 public void test_moveUpMergedNodes_1() throws IllegalAccessException, NoSuchFieldException { 489 485 NodeListMergeModel model = new NodeListMergeModel(); 490 491 Way myWay = new Way(1); 492 myWay.nodes.add(new Node(1)); 493 myWay.nodes.add(new Node(2)); 494 Way theirWay = new Way(1); 495 496 model.populate(myWay, theirWay); 497 List<Node> mergedNodes = inspectNodeList(model, "merged Nodes");498 mergedNodes.add(new Node(10)); 499 mergedNodes.add(new Node(11)); 500 mergedNodes.add(new Node(12)); 501 502 model.moveUpMerged Nodes(new int[]{1});503 486 487 Way myWay = new Way(1); 488 myWay.nodes.add(new Node(1)); 489 myWay.nodes.add(new Node(2)); 490 Way theirWay = new Way(1); 491 492 model.populate(myWay, theirWay); 493 List<Node> mergedNodes = inspectNodeList(model, "mergedEntries"); 494 mergedNodes.add(new Node(10)); 495 mergedNodes.add(new Node(11)); 496 mergedNodes.add(new Node(12)); 497 498 model.moveUpMerged(new int[]{1}); 499 504 500 assertEquals(3, mergedNodes.size()); 505 assertEquals(11, mergedNodes.get(0).id); 506 assertEquals(10, mergedNodes.get(1).id); 507 assertEquals(12, mergedNodes.get(2).id); 508 509 DefaultListSelectionModel mergedSelection = inspectListSelectionModel(model, "merged NodesSelectionModel");510 ensureSelected(mergedSelection, 0); // position 1 selecte0 511 } 512 501 assertEquals(11, mergedNodes.get(0).id); 502 assertEquals(10, mergedNodes.get(1).id); 503 assertEquals(12, mergedNodes.get(2).id); 504 505 DefaultListSelectionModel mergedSelection = inspectListSelectionModel(model, "mergedEntriesSelectionModel"); 506 ensureSelected(mergedSelection, 0); // position 1 selecte0 507 } 508 513 509 @Test 514 510 public void test_moveUpMergedNodes_2() throws IllegalAccessException, NoSuchFieldException { 515 511 NodeListMergeModel model = new NodeListMergeModel(); 516 517 Way myWay = new Way(1); 518 myWay.nodes.add(new Node(1)); 519 myWay.nodes.add(new Node(2)); 520 Way theirWay = new Way(1); 521 522 model.populate(myWay, theirWay); 523 List<Node> mergedNodes = inspectNodeList(model, "merged Nodes");512 513 Way myWay = new Way(1); 514 myWay.nodes.add(new Node(1)); 515 myWay.nodes.add(new Node(2)); 516 Way theirWay = new Way(1); 517 518 model.populate(myWay, theirWay); 519 List<Node> mergedNodes = inspectNodeList(model, "mergedEntries"); 524 520 mergedNodes.add(new Node(10)); 525 521 mergedNodes.add(new Node(11)); … … 527 523 mergedNodes.add(new Node(13)); 528 524 mergedNodes.add(new Node(14)); 529 530 model.moveUpMerged Nodes(new int[]{1,4});531 525 526 model.moveUpMerged(new int[]{1,4}); 527 532 528 assertEquals(5, mergedNodes.size()); 533 assertEquals(11, mergedNodes.get(0).id); 534 assertEquals(10, mergedNodes.get(1).id); 535 assertEquals(12, mergedNodes.get(2).id); 529 assertEquals(11, mergedNodes.get(0).id); 530 assertEquals(10, mergedNodes.get(1).id); 531 assertEquals(12, mergedNodes.get(2).id); 536 532 assertEquals(14, mergedNodes.get(3).id); 537 533 assertEquals(13, mergedNodes.get(4).id); 538 539 DefaultListSelectionModel mergedSelection = inspectListSelectionModel(model, "merged NodesSelectionModel");540 ensureSelected(mergedSelection, 0,3); // position 0 and 3 selecte0 541 } 542 534 535 DefaultListSelectionModel mergedSelection = inspectListSelectionModel(model, "mergedEntriesSelectionModel"); 536 ensureSelected(mergedSelection, 0,3); // position 0 and 3 selecte0 537 } 538 543 539 @Test 544 540 public void test_moveUpMergedNodes_3() throws IllegalAccessException, NoSuchFieldException { 545 541 NodeListMergeModel model = new NodeListMergeModel(); 546 547 Way myWay = new Way(1); 548 myWay.nodes.add(new Node(1)); 549 myWay.nodes.add(new Node(2)); 550 Way theirWay = new Way(1); 551 552 model.populate(myWay, theirWay); 553 List<Node> mergedNodes = inspectNodeList(model, "merged Nodes");542 543 Way myWay = new Way(1); 544 myWay.nodes.add(new Node(1)); 545 myWay.nodes.add(new Node(2)); 546 Way theirWay = new Way(1); 547 548 model.populate(myWay, theirWay); 549 List<Node> mergedNodes = inspectNodeList(model, "mergedEntries"); 554 550 mergedNodes.add(new Node(10)); 555 551 mergedNodes.add(new Node(11)); … … 557 553 mergedNodes.add(new Node(13)); 558 554 mergedNodes.add(new Node(14)); 559 560 model.moveUpMerged Nodes(new int[]{1,2,3,4});561 555 556 model.moveUpMerged(new int[]{1,2,3,4}); 557 562 558 assertEquals(5, mergedNodes.size()); 563 assertEquals(11, mergedNodes.get(0).id); 564 assertEquals(12, mergedNodes.get(1).id); 559 assertEquals(11, mergedNodes.get(0).id); 560 assertEquals(12, mergedNodes.get(1).id); 565 561 assertEquals(13, mergedNodes.get(2).id); 566 562 assertEquals(14, mergedNodes.get(3).id); 567 assertEquals(10, mergedNodes.get(4).id); 568 569 DefaultListSelectionModel mergedSelection = inspectListSelectionModel(model, "merged NodesSelectionModel");570 ensureSelected(mergedSelection, 0,1,2,3); 571 } 572 563 assertEquals(10, mergedNodes.get(4).id); 564 565 DefaultListSelectionModel mergedSelection = inspectListSelectionModel(model, "mergedEntriesSelectionModel"); 566 ensureSelected(mergedSelection, 0,1,2,3); 567 } 568 573 569 /* ----------------------------------------------------------------------------- */ 574 570 /* moveDownMergedNodes */ … … 577 573 public void test_moveDownMergedNodes_1() throws IllegalAccessException, NoSuchFieldException { 578 574 NodeListMergeModel model = new NodeListMergeModel(); 579 580 Way myWay = new Way(1); 581 myWay.nodes.add(new Node(1)); 582 myWay.nodes.add(new Node(2)); 583 Way theirWay = new Way(1); 584 585 model.populate(myWay, theirWay); 586 List<Node> mergedNodes = inspectNodeList(model, "merged Nodes");587 mergedNodes.add(new Node(10)); 588 mergedNodes.add(new Node(11)); 589 mergedNodes.add(new Node(12)); 590 591 model.moveDownMerged Nodes(new int[]{1});592 575 576 Way myWay = new Way(1); 577 myWay.nodes.add(new Node(1)); 578 myWay.nodes.add(new Node(2)); 579 Way theirWay = new Way(1); 580 581 model.populate(myWay, theirWay); 582 List<Node> mergedNodes = inspectNodeList(model, "mergedEntries"); 583 mergedNodes.add(new Node(10)); 584 mergedNodes.add(new Node(11)); 585 mergedNodes.add(new Node(12)); 586 587 model.moveDownMerged(new int[]{1}); 588 593 589 assertEquals(3, mergedNodes.size()); 594 assertEquals(10, mergedNodes.get(0).id); 595 assertEquals(12, mergedNodes.get(1).id); 596 assertEquals(11, mergedNodes.get(2).id); 597 598 DefaultListSelectionModel mergedSelection = inspectListSelectionModel(model, "merged NodesSelectionModel");599 ensureSelected(mergedSelection, 2); 600 } 601 590 assertEquals(10, mergedNodes.get(0).id); 591 assertEquals(12, mergedNodes.get(1).id); 592 assertEquals(11, mergedNodes.get(2).id); 593 594 DefaultListSelectionModel mergedSelection = inspectListSelectionModel(model, "mergedEntriesSelectionModel"); 595 ensureSelected(mergedSelection, 2); 596 } 597 602 598 @Test 603 599 public void test_moveDownMergedNodes_2() throws IllegalAccessException, NoSuchFieldException { 604 600 NodeListMergeModel model = new NodeListMergeModel(); 605 606 Way myWay = new Way(1); 607 myWay.nodes.add(new Node(1)); 608 myWay.nodes.add(new Node(2)); 609 Way theirWay = new Way(1); 610 611 model.populate(myWay, theirWay); 612 List<Node> mergedNodes = inspectNodeList(model, "merged Nodes");601 602 Way myWay = new Way(1); 603 myWay.nodes.add(new Node(1)); 604 myWay.nodes.add(new Node(2)); 605 Way theirWay = new Way(1); 606 607 model.populate(myWay, theirWay); 608 List<Node> mergedNodes = inspectNodeList(model, "mergedEntries"); 613 609 mergedNodes.add(new Node(10)); 614 610 mergedNodes.add(new Node(11)); … … 616 612 mergedNodes.add(new Node(13)); 617 613 mergedNodes.add(new Node(14)); 618 619 model.moveDownMerged Nodes(new int[]{1,3});620 614 615 model.moveDownMerged(new int[]{1,3}); 616 621 617 assertEquals(5, mergedNodes.size()); 622 assertEquals(10, mergedNodes.get(0).id); 623 assertEquals(12, mergedNodes.get(1).id); 624 assertEquals(11, mergedNodes.get(2).id); 618 assertEquals(10, mergedNodes.get(0).id); 619 assertEquals(12, mergedNodes.get(1).id); 620 assertEquals(11, mergedNodes.get(2).id); 625 621 assertEquals(14, mergedNodes.get(3).id); 626 622 assertEquals(13, mergedNodes.get(4).id); 627 628 DefaultListSelectionModel mergedSelection = inspectListSelectionModel(model, "merged NodesSelectionModel");629 ensureSelected(mergedSelection, 2,4); 630 } 631 623 624 DefaultListSelectionModel mergedSelection = inspectListSelectionModel(model, "mergedEntriesSelectionModel"); 625 ensureSelected(mergedSelection, 2,4); 626 } 627 632 628 @Test 633 629 public void test_moveDownMergedNodes_3() throws IllegalAccessException, NoSuchFieldException { 634 630 NodeListMergeModel model = new NodeListMergeModel(); 635 636 Way myWay = new Way(1); 637 myWay.nodes.add(new Node(1)); 638 myWay.nodes.add(new Node(2)); 639 Way theirWay = new Way(1); 640 641 model.populate(myWay, theirWay); 642 List<Node> mergedNodes = inspectNodeList(model, "merged Nodes");631 632 Way myWay = new Way(1); 633 myWay.nodes.add(new Node(1)); 634 myWay.nodes.add(new Node(2)); 635 Way theirWay = new Way(1); 636 637 model.populate(myWay, theirWay); 638 List<Node> mergedNodes = inspectNodeList(model, "mergedEntries"); 643 639 mergedNodes.add(new Node(10)); 644 640 mergedNodes.add(new Node(11)); … … 646 642 mergedNodes.add(new Node(13)); 647 643 mergedNodes.add(new Node(14)); 648 649 model.moveDownMerged Nodes(new int[]{1,2,3});650 644 645 model.moveDownMerged(new int[]{1,2,3}); 646 651 647 assertEquals(5, mergedNodes.size()); 652 assertEquals(10, mergedNodes.get(0).id); 653 assertEquals(14, mergedNodes.get(1).id); 648 assertEquals(10, mergedNodes.get(0).id); 649 assertEquals(14, mergedNodes.get(1).id); 654 650 assertEquals(11, mergedNodes.get(2).id); 655 651 assertEquals(12, mergedNodes.get(3).id); 656 assertEquals(13, mergedNodes.get(4).id); 657 658 DefaultListSelectionModel mergedSelection = inspectListSelectionModel(model, "merged NodesSelectionModel");659 ensureSelected(mergedSelection, 2,3,4); 660 } 661 652 assertEquals(13, mergedNodes.get(4).id); 653 654 DefaultListSelectionModel mergedSelection = inspectListSelectionModel(model, "mergedEntriesSelectionModel"); 655 ensureSelected(mergedSelection, 2,3,4); 656 } 657 662 658 /* ----------------------------------------------------------------------------- */ 663 659 /* PropertyChangeListener */ … … 666 662 public void addPropertyChangeListener() { 667 663 NodeListMergeModel model = new NodeListMergeModel(); 668 664 669 665 PropertyChangeListener listener = new PropertyChangeListener() { 670 @Override 666 671 667 public void propertyChange(PropertyChangeEvent evt) { 672 668 } 673 669 }; 674 670 675 671 model.addPropertyChangeListener(listener); 676 672 677 673 ArrayList<PropertyChangeListener> listeners = field("listeners") 678 679 680 681 674 .ofType(ArrayList.class) 675 .in(model) 676 .get(); 677 682 678 assertEquals(1, listeners.size()); 683 679 assertEquals(listener, listeners.get(0)); 684 680 } 685 681 686 682 @Test 687 683 public void removePropertyChangeListener() { 688 684 NodeListMergeModel model = new NodeListMergeModel(); 689 685 690 686 PropertyChangeListener listener = new PropertyChangeListener() { 691 @Override 687 692 688 public void propertyChange(PropertyChangeEvent evt) { 693 689 } 694 690 }; 695 691 696 692 model.addPropertyChangeListener(listener); 697 693 model.removePropertyChangeListener(listener); 698 694 699 695 ArrayList<PropertyChangeListener> listeners = field("listeners") 700 701 702 703 696 .ofType(ArrayList.class) 697 .in(model) 698 .get(); 699 704 700 assertEquals(0, listeners.size()); 705 701 } 706 702 707 703 /* ----------------------------------------------------------------------------- */ 708 704 /* property frozen */ … … 721 717 public void setFrozenWithPropertyChangeNotification() { 722 718 NodeListMergeModel model = new NodeListMergeModel(); 723 719 724 720 class MyListener implements PropertyChangeListener { 725 721 public ArrayList<PropertyChangeEvent> events = new ArrayList<PropertyChangeEvent>(); 726 @Override 722 727 723 public void propertyChange(PropertyChangeEvent evt) { 728 724 events.add(evt); … … 734 730 model.setFrozen(!oldValue); 735 731 assertEquals(!oldValue, model.isFrozen()); 736 732 737 733 assertEquals(1, listener.events.size()); 738 734 assertEquals(oldValue, listener.events.get(0).getOldValue()); -
trunk/test/unit/org/openstreetmap/josm/gui/conflict/tags/TagMergeModelTest.java
r1622 r1631 19 19 TagMergeModel model = new TagMergeModel(); 20 20 } 21 21 22 22 @Test 23 23 public void addPropertyChangeListener() { 24 24 TagMergeModel model = new TagMergeModel(); 25 25 PropertyChangeListener listener = new PropertyChangeListener() { 26 @Override 26 27 27 public void propertyChange(PropertyChangeEvent evt) { 28 28 } 29 29 }; 30 30 model.addPropertyChangeListener(listener); 31 31 32 32 ArrayList list = field("listeners").ofType(ArrayList.class) 33 34 35 36 assertEquals(1, list.size()); 37 assertEquals(listener, list.get(0)); 38 } 39 33 .in(model) 34 .get(); 35 36 assertEquals(1, list.size()); 37 assertEquals(listener, list.get(0)); 38 } 39 40 40 @Test 41 41 public void removePropertyChangeListener() { 42 42 TagMergeModel model = new TagMergeModel(); 43 43 PropertyChangeListener listener = new PropertyChangeListener() { 44 @Override 44 45 45 public void propertyChange(PropertyChangeEvent evt) { 46 46 } … … 48 48 model.addPropertyChangeListener(listener); 49 49 model.removePropertyChangeListener(listener); 50 50 51 51 ArrayList list = field("listeners") 52 53 54 55 56 assertEquals(0, list.size());57 } 58 52 .ofType(ArrayList.class) 53 .in(model) 54 .get(); 55 56 assertEquals(0, list.size()); 57 } 58 59 59 @Test 60 60 public void populateNoConflichts() { … … 63 63 TagMergeModel model = new TagMergeModel(); 64 64 model.populate(my, their); 65 66 ArrayList<TagMergeItem> list = field("tagMergeItems") 67 68 69 70 65 66 ArrayList<TagMergeItem> list = field("tagMergeItems") 67 .ofType(ArrayList.class) 68 .in(model) 69 .get(); 70 71 71 assertEquals(0, list.size()); 72 72 } 73 73 74 74 @Test 75 75 public void populateNoConflicts1() { … … 80 80 TagMergeModel model = new TagMergeModel(); 81 81 model.populate(my, their); 82 83 ArrayList<TagMergeItem> list = field("tagMergeItems") 84 85 86 87 82 83 ArrayList<TagMergeItem> list = field("tagMergeItems") 84 .ofType(ArrayList.class) 85 .in(model) 86 .get(); 87 88 88 assertEquals(0, list.size()); 89 89 } 90 90 91 91 @Test 92 92 public void populateMissingKeyMine() { … … 96 96 TagMergeModel model = new TagMergeModel(); 97 97 model.populate(my, their); 98 99 ArrayList<TagMergeItem> list = field("tagMergeItems") 100 101 102 103 98 99 ArrayList<TagMergeItem> list = field("tagMergeItems") 100 .ofType(ArrayList.class) 101 .in(model) 102 .get(); 103 104 104 assertEquals(1, list.size()); 105 105 TagMergeItem item = list.get(0); … … 109 109 assertEquals("value", item.getTheirTagValue()); 110 110 } 111 111 112 112 @Test 113 113 public void populateMissingKeyTheir() { 114 114 Node my = new Node(1); 115 115 my.put("key", "value"); 116 Node their = new Node(1); 117 TagMergeModel model = new TagMergeModel(); 118 model.populate(my, their); 119 120 ArrayList<TagMergeItem> list = field("tagMergeItems") 121 122 123 124 116 Node their = new Node(1); 117 TagMergeModel model = new TagMergeModel(); 118 model.populate(my, their); 119 120 ArrayList<TagMergeItem> list = field("tagMergeItems") 121 .ofType(ArrayList.class) 122 .in(model) 123 .get(); 124 125 125 assertEquals(1, list.size()); 126 126 TagMergeItem item = list.get(0); … … 130 130 assertEquals("value", item.getMyTagValue()); 131 131 } 132 132 133 133 @Test 134 134 public void populateConflictingValues() { … … 139 139 TagMergeModel model = new TagMergeModel(); 140 140 model.populate(my, their); 141 142 ArrayList<TagMergeItem> list = field("tagMergeItems") 143 144 145 146 141 142 ArrayList<TagMergeItem> list = field("tagMergeItems") 143 .ofType(ArrayList.class) 144 .in(model) 145 .get(); 146 147 147 assertEquals(1, list.size()); 148 148 TagMergeItem item = list.get(0); … … 152 152 assertEquals("theirvalue", item.getTheirTagValue()); 153 153 } 154 154 155 155 @Test 156 156 public void addItem() { … … 158 158 TagMergeModel model = new TagMergeModel(); 159 159 model.addItem(item); 160 161 ArrayList<TagMergeItem> list = field("tagMergeItems") 162 163 164 165 160 161 ArrayList<TagMergeItem> list = field("tagMergeItems") 162 .ofType(ArrayList.class) 163 .in(model) 164 .get(); 165 166 166 assertEquals(1, list.size()); 167 167 item = list.get(0); … … 171 171 assertEquals("theirvalue", item.getTheirTagValue()); 172 172 } 173 173 174 174 @Test 175 175 public void decide() { … … 177 177 TagMergeModel model = new TagMergeModel(); 178 178 model.addItem(item); 179 180 ArrayList<TagMergeItem> list = field("tagMergeItems") 181 182 183 184 185 model.decide(0, MergeDecisionType.KEEP_MINE); 179 180 ArrayList<TagMergeItem> list = field("tagMergeItems") 181 .ofType(ArrayList.class) 182 .in(model) 183 .get(); 184 185 model.decide(0, MergeDecisionType.KEEP_MINE); 186 186 assertEquals(1, list.size()); 187 187 item = list.get(0); 188 188 assertEquals(MergeDecisionType.KEEP_MINE, item.getMergeDecision()); 189 190 model.decide(0, MergeDecisionType.KEEP_THEIR); 189 190 model.decide(0, MergeDecisionType.KEEP_THEIR); 191 191 assertEquals(1, list.size()); 192 192 item = list.get(0); 193 193 assertEquals(MergeDecisionType.KEEP_THEIR, item.getMergeDecision()); 194 195 model.decide(0, MergeDecisionType.UNDECIDED); 196 assertEquals(1, list.size()); 197 item = list.get(0); 198 assertEquals(MergeDecisionType.UNDECIDED, item.getMergeDecision()); 199 } 200 194 195 model.decide(0, MergeDecisionType.UNDECIDED); 196 assertEquals(1, list.size()); 197 item = list.get(0); 198 assertEquals(MergeDecisionType.UNDECIDED, item.getMergeDecision()); 199 } 200 201 201 @Test 202 202 public void decideMultiple() { 203 203 204 204 TagMergeItem item = new TagMergeItem("key", "myvalue", "theirvalue"); 205 205 TagMergeModel model = new TagMergeModel(); … … 207 207 model.addItem(new TagMergeItem("key-" + i, "myvalue-" + i, "theirvalue-" +i)); 208 208 } 209 210 ArrayList<TagMergeItem> list = field("tagMergeItems") 211 212 213 214 209 210 ArrayList<TagMergeItem> list = field("tagMergeItems") 211 .ofType(ArrayList.class) 212 .in(model) 213 .get(); 214 215 215 assertEquals(10, list.size()); 216 217 model.decide(new int[] {0, 3, 5}, MergeDecisionType.KEEP_MINE); 216 217 model.decide(new int[] {0, 3, 5}, MergeDecisionType.KEEP_MINE); 218 218 for (int i = 0; i< 10; i++) { 219 219 item = list.get(i);
Note:
See TracChangeset
for help on using the changeset viewer.