| | 1 | // License: GPL. For details, see LICENSE file. |
| | 2 | package org.openstreetmap.josm.gui.layer; |
| | 3 | |
| | 4 | import static org.junit.Assert.assertFalse; |
| | 5 | import static org.junit.Assert.assertTrue; |
| | 6 | |
| | 7 | import java.util.concurrent.atomic.AtomicBoolean; |
| | 8 | |
| | 9 | import org.junit.Before; |
| | 10 | import org.junit.Rule; |
| | 11 | import org.junit.Test; |
| | 12 | import org.openstreetmap.josm.gui.layer.MapViewPaintable.PaintableInvalidationListener; |
| | 13 | import org.openstreetmap.josm.testutils.JOSMTestRules; |
| | 14 | |
| | 15 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; |
| | 16 | |
| | 17 | /** |
| | 18 | * Test of the base {@link AbstractMapViewPaintable} class |
| | 19 | * @author Michael Zangl |
| | 20 | * @since xxx |
| | 21 | */ |
| | 22 | public class AbstractMapViewPaintableTest { |
| | 23 | /** |
| | 24 | * No special test rules |
| | 25 | */ |
| | 26 | @Rule |
| | 27 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") |
| | 28 | public JOSMTestRules test = new JOSMTestRules(); |
| | 29 | |
| | 30 | private Layer testLayer; |
| | 31 | |
| | 32 | /** |
| | 33 | * Create test layer |
| | 34 | */ |
| | 35 | @Before |
| | 36 | public void setUp() { |
| | 37 | testLayer = new LayerManagerTest.TestLayer(); |
| | 38 | } |
| | 39 | |
| | 40 | /** |
| | 41 | * Test {@link Layer#invalidate()} |
| | 42 | */ |
| | 43 | @Test |
| | 44 | public void testInvalidate() { |
| | 45 | AtomicBoolean fired = new AtomicBoolean(); |
| | 46 | PaintableInvalidationListener listener = l -> fired.set(true); |
| | 47 | testLayer.addInvalidationListener(listener); |
| | 48 | assertFalse(fired.get()); |
| | 49 | testLayer.invalidate(); |
| | 50 | assertTrue(fired.get()); |
| | 51 | |
| | 52 | fired.set(false); |
| | 53 | testLayer.removeInvalidationListener(listener); |
| | 54 | testLayer.invalidate(); |
| | 55 | assertFalse(fired.get()); |
| | 56 | } |
| | 57 | |
| | 58 | } |