Ignore:
Timestamp:
2023-11-07T14:21:38+01:00 (12 months ago)
Author:
taylor.smock
Message:

Fix #23057: data layers should be selected next, not non-data layers (patch by gaben, modified)

Modifications are as follows:

  • Fix test pollution uncovered by change in non-obvious determinate order of tests
  • Fix code so that MainLayerManagerTest.testRemoveLayerUnsetsActiveLayer passes
Location:
trunk/test/unit/org/openstreetmap/josm/gui
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/gui/dialogs/layer/DeleteLayerActionTest.java

    r18839 r18895  
    1111import static org.junit.jupiter.api.Assertions.assertTrue;
    1212
     13import java.util.Collections;
    1314import java.util.Objects;
    1415import java.util.concurrent.atomic.AtomicInteger;
     
    2223import org.openstreetmap.josm.gui.layer.Layer;
    2324import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     25import org.openstreetmap.josm.gui.layer.geoimage.GeoImageLayer;
    2426import org.openstreetmap.josm.testutils.annotations.Main;
    2527import org.openstreetmap.josm.testutils.annotations.Projection;
     
    123125    }
    124126
     127    @Test
     128    void testRemoveBottomActiveWithBackgroundLayer() {
     129        GeoImageLayer geoImageLayer = new GeoImageLayer(Collections.emptyList(), null, "imageLayer");
     130        OsmDataLayer osmDataLayer1 = new OsmDataLayer(new DataSet(), "dataLayer1", null);
     131        OsmDataLayer osmDataLayer2 = new OsmDataLayer(new DataSet(), "dataLayer2", null);
     132
     133        // remove all the layers added in BeforeEach()
     134        for (Layer l : MainApplication.getLayerManager().getLayers()) {
     135            MainApplication.getLayerManager().removeLayer(l);
     136        }
     137        MainApplication.getLayerManager().addLayer(geoImageLayer);
     138        MainApplication.getLayerManager().addLayer(osmDataLayer1);
     139        MainApplication.getLayerManager().addLayer(osmDataLayer2);
     140
     141        model.getLayerManager().setActiveLayer(osmDataLayer1);
     142        model.setSelectedLayer(osmDataLayer1);
     143
     144        deleteLayerAction.actionPerformed(null);
     145
     146        assertSame(model.getLayerManager().getActiveLayer(), model.getLayer(0));
     147        assertEquals("dataLayer2", Objects.requireNonNull(model.getLayerManager().getActiveLayer().getName()));
     148        assertAll(model.getLayers().stream().map(layer -> () -> assertNotSame(osmDataLayer1, layer)));
     149    }
     150
     151    @Test
     152    void testRemoveBottomActiveAllHidden() {
     153        hideRange(0, 9);
     154        final Layer toRemove = model.getLayer(9);
     155        assertNotNull(toRemove);
     156        assertFalse(toRemove.isVisible());
     157        assertEquals(0, model.getLayers().stream().filter(Layer::isVisible).count());
     158
     159        model.getLayerManager().setActiveLayer(toRemove);
     160        model.setSelectedLayer(toRemove);
     161        deleteLayerAction.actionPerformed(null);
     162
     163        assertSame(model.getLayerManager().getActiveLayer(), model.getLayer(8));
     164        assertEquals("testActiveLayer1", Objects.requireNonNull(model.getLayer(8)).getName());
     165        assertAll(model.getLayers().stream().map(layer -> () -> assertNotSame(toRemove, layer)));
     166    }
     167
    125168    private void hideRange(int start, int end) {
    126169        model.getSelectionModel().setSelectionInterval(start, end);
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayerTest.java

    r18870 r18895  
    66import java.util.Collections;
    77
     8import org.junit.jupiter.api.AfterEach;
    89import org.junit.jupiter.api.Test;
    910import org.openstreetmap.josm.data.osm.DataSet;
     
    1920@Main
    2021class GeoImageLayerTest {
     22    @AfterEach
     23    void tearDown() {
     24        if (ImageViewerDialog.hasInstance()) {
     25            ImageViewerDialog.getInstance().destroy();
     26        }
     27    }
     28
    2129    /**
    2230     * Test that {@link GeoImageLayer#mergeFrom} throws IAE for invalid arguments
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/geoimage/ImagesLoaderTest.java

    r18870 r18895  
    1616import org.openstreetmap.josm.io.GpxReader;
    1717import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
     18import org.openstreetmap.josm.testutils.annotations.Main;
     19import org.openstreetmap.josm.testutils.annotations.Projection;
    1820
    1921/**
     
    2123 */
    2224@BasicPreferences
     25@Main
     26@Projection
    2327class ImagesLoaderTest {
    2428    /**
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/geoimage/WikimediaCommonsLoaderTest.java

    r18689 r18895  
    1111import java.util.List;
    1212
    13 import org.junit.jupiter.api.BeforeAll;
     13import org.junit.jupiter.api.AfterEach;
    1414import org.junit.jupiter.api.Test;
    1515import org.openstreetmap.josm.data.Bounds;
    1616import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
    17 import org.openstreetmap.josm.tools.Http1Client;
    18 import org.openstreetmap.josm.tools.HttpClient;
     17import org.openstreetmap.josm.testutils.annotations.HTTP;
     18import org.openstreetmap.josm.testutils.annotations.Main;
    1919
    2020import com.github.tomakehurst.wiremock.WireMockServer;
     
    2424 */
    2525@BasicPreferences
     26@HTTP
     27@Main
    2628class WikimediaCommonsLoaderTest {
    27 
    28     @BeforeAll
    29     static void beforeAll() {
    30         HttpClient.setFactory(Http1Client::new);
     29    @AfterEach
     30    void tearDown() {
     31        if (ImageViewerDialog.hasInstance()) {
     32            ImageViewerDialog.getInstance().destroy();
     33        }
    3134    }
    3235
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/markerlayer/ImageMarkerTest.java

    r18870 r18895  
    88import java.net.MalformedURLException;
    99
     10import org.junit.jupiter.api.AfterEach;
    1011import org.junit.jupiter.api.Test;
    1112import org.openstreetmap.josm.TestUtils;
     
    1314import org.openstreetmap.josm.data.gpx.GpxData;
    1415import org.openstreetmap.josm.data.gpx.WayPoint;
     16import org.openstreetmap.josm.gui.layer.geoimage.ImageViewerDialog;
    1517import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
    1618import org.openstreetmap.josm.testutils.annotations.Main;
     
    2224@Main
    2325class ImageMarkerTest {
     26    @AfterEach
     27    void tearDown() {
     28        if (ImageViewerDialog.hasInstance()) {
     29            ImageViewerDialog.getInstance().destroy();
     30        }
     31    }
     32
    2433    /**
    2534     * Unit test of {@link ImageMarker#ImageMarker}.
Note: See TracChangeset for help on using the changeset viewer.