Ignore:
Timestamp:
2021-07-12T23:45:16+02:00 (3 years ago)
Author:
Don-vip
Message:

fix #21105 - see #17184 - make sure that most operations of GpxLayer are harmless after call to destroy()

File:
1 edited

Legend:

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

    r17845 r18008  
    22package org.openstreetmap.josm.gui.layer;
    33
     4import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
    45import static org.junit.jupiter.api.Assertions.assertEquals;
    56import static org.junit.jupiter.api.Assertions.assertFalse;
    67import static org.junit.jupiter.api.Assertions.assertNull;
     8import static org.junit.jupiter.api.Assertions.assertThrows;
    79import static org.junit.jupiter.api.Assertions.assertTrue;
    8 import static org.junit.jupiter.api.Assertions.assertThrows;
    910
    1011import java.awt.Color;
     12import java.awt.Component;
    1113import java.io.IOException;
    1214import java.util.ArrayList;
     
    2729import org.openstreetmap.josm.data.gpx.WayPoint;
    2830import org.openstreetmap.josm.data.osm.DataSet;
     31import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
     32import org.openstreetmap.josm.data.projection.CustomProjection;
    2933import org.openstreetmap.josm.data.projection.Projections;
    3034import org.openstreetmap.josm.gui.MainApplication;
     
    261265        assertNull(new GpxLayer(new GpxData(), "", false).getChangesetSourceTag());
    262266    }
     267
     268    /**
     269     * Checks that potential operations that could be called after destroy() are harmless
     270     */
     271    @Test
     272    void testRobustnessAfterDestroy() {
     273        GpxData data = new GpxData();
     274        GpxLayer layer = new GpxLayer(data, "1", false);
     275        GpxLayer otherLayer = new GpxLayer(new GpxData(), "2", false);
     276        assertEquals(data, layer.getData());
     277        assertTrue(layer.isMergable(otherLayer));
     278        assertTrue(layer.hasColor());
     279        assertTrue(layer.isSavable());
     280        assertTrue(layer.checkSaveConditions());
     281        assertFalse(layer.isModified());
     282        assertFalse(layer.requiresSaveToFile());
     283        assertNull(layer.getChangesetSourceTag());
     284        assertNull(layer.getAssociatedFile());
     285
     286        layer.destroy();
     287
     288        assertNull(layer.getData());
     289        assertNull(layer.getColor());
     290        assertFalse(layer.hasColor());
     291        assertFalse(layer.isMergable(otherLayer));
     292        assertFalse(layer.isSavable());
     293        assertFalse(layer.checkSaveConditions());
     294        assertFalse(layer.isModified());
     295        assertFalse(layer.requiresSaveToFile());
     296        assertNull(layer.getChangesetSourceTag());
     297        assertNull(layer.getAssociatedFile());
     298        Object infoComponent = layer.getInfoComponent();
     299        assertTrue(infoComponent instanceof JScrollPane);
     300        Component view = ((JScrollPane) infoComponent).getViewport().getView();
     301        assertTrue(view instanceof HtmlPanel);
     302        String text = ((HtmlPanel) view).getEditorPane().getText().trim();
     303        assertTrue(text.startsWith("<html>"), text);
     304        assertTrue(text.endsWith("</html>"), text);
     305        assertEquals("<html><br></html>", layer.getToolTipText());
     306        assertDoesNotThrow(() -> layer.jumpToNextMarker());
     307        assertDoesNotThrow(() -> layer.jumpToPreviousMarker());
     308        assertDoesNotThrow(() -> layer.visitBoundingBox(new BoundingXYVisitor()));
     309        assertDoesNotThrow(() -> layer.filterTracksByDate(null, null, false));
     310        assertDoesNotThrow(() -> layer.projectionChanged(new CustomProjection(), new CustomProjection()));
     311    }
    263312}
Note: See TracChangeset for help on using the changeset viewer.