- Timestamp:
- 2016-09-14T12:44:42+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/gui/layer/LayerManagerTest.java
r10744 r11000 17 17 import java.util.ArrayList; 18 18 import java.util.Arrays; 19 import java.util.Collections; 19 20 20 21 import javax.swing.Action; … … 41 42 */ 42 43 public class LayerManagerTest { 43 44 44 /** 45 45 * This is a layer that can be used in tests. It does not do anything and provides a simple, fake implementation. … … 120 120 */ 121 121 protected class CapturingLayerChangeListener implements LayerChangeListener { 122 pr ivateLayerAddEvent layerAdded;123 pr ivateLayerRemoveEvent layerRemoved;124 pr ivateLayerOrderChangeEvent layerOrderChanged;122 protected LayerAddEvent layerAdded; 123 protected LayerRemoveEvent layerRemoved; 124 protected LayerOrderChangeEvent layerOrderChanged; 125 125 126 126 @Override … … 149 149 } 150 150 151 private final class ResetStateChangeListener extends CapturingLayerChangeListener { 152 int removed = 0; 153 154 @Override 155 public void layerRemoving(LayerRemoveEvent e) { 156 // count only 157 removed++; 158 } 159 } 160 151 161 protected LayerManager layerManager; 152 162 … … 473 483 } 474 484 485 /** 486 * Test {@link LayerRemoveEvent#scheduleRemoval(java.util.Collection)} 487 */ 488 @Test 489 public void testLayerRemoveScheduleRemoval() { 490 TestLayer layer1 = new TestLayer(); 491 TestLayer layer2 = new TestLayer(); 492 layerManager.addLayer(layer1); 493 layerManager.addLayer(layer2); 494 495 layerManager.addLayerChangeListener(new LayerChangeListener() { 496 @Override 497 public void layerRemoving(LayerRemoveEvent e) { 498 if (e.getRemovedLayer() == layer1) { 499 e.scheduleRemoval(Collections.singleton(layer2)); 500 } 501 } 502 503 @Override 504 public void layerOrderChanged(LayerOrderChangeEvent e) { 505 fail(); 506 } 507 508 @Override 509 public void layerAdded(LayerAddEvent e) { 510 fail(); 511 } 512 }); 513 514 layerManager.removeLayer(layer1); 515 assertEquals(0, layerManager.getLayers().size()); 516 } 517 518 /** 519 * Test {@link LayerManager#resetState()} 520 */ 521 @Test 522 public void testResetState() { 523 ResetStateChangeListener changeListener = new ResetStateChangeListener(); 524 layerManager.addLayer(new TestLayer()); 525 layerManager.addLayerChangeListener(changeListener); 526 layerManager.addLayer(new TestLayer()); 527 assertEquals(2, layerManager.getLayers().size()); 528 assertNotNull(changeListener.layerAdded); 529 530 layerManager.resetState(); 531 changeListener.layerAdded = null; 532 533 assertEquals(2, changeListener.removed); 534 assertEquals(0, layerManager.getLayers().size()); 535 layerManager.addLayer(new TestLayer()); 536 assertNull(changeListener.layerAdded); 537 } 538 475 539 }
Note:
See TracChangeset
for help on using the changeset viewer.