Changeset 18686 in josm


Ignore:
Timestamp:
2023-03-08T20:00:36+01:00 (21 months ago)
Author:
taylor.smock
Message:

See #22767, fix failing unit tests

The fix for #22767 included a new unit test, which caused a cascading failure.
The first step of the fix included removing the destroyed dialog from the
MapFrame. Unfortunately, MapFrame#removeToggleDialog did not properly
remove the ToggleDialog -- it called DialogsPanel#remove(Component) with
the ToggleDialog as an argument. Since the DialogsPanel never adds the
ToggleDialog as a direct subcomponent, this was effectively a no-op.

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/DialogsPanel.java

    r17374 r18686  
    105105        } else {
    106106            dlg.hideDialog();
     107        }
     108    }
     109
     110    /**
     111     * Remove a {@link ToggleDialog} from the list of known dialogs and trigger reconstruct.
     112     * @param toggleDialog The dialog to remove
     113     * @since 18686
     114     */
     115    public void remove(ToggleDialog toggleDialog) {
     116        remove(toggleDialog, true);
     117    }
     118
     119    /**
     120     * Remove a {@link ToggleDialog} from the list of known dialogs.
     121     * @param toggleDialog The dialog to remove
     122     * @param doReconstruct <code>true</code> if reconstruction should be triggered.
     123     * @since 18686
     124     */
     125    public void remove(ToggleDialog toggleDialog, boolean doReconstruct) {
     126        toggleDialog.setDialogsPanel(null);
     127        final JPanel oldPanel = panels.get(allDialogs.indexOf(toggleDialog));
     128        allDialogs.remove(toggleDialog);
     129        panels.remove(oldPanel);
     130        mSpltPane.remove(oldPanel);
     131        if (doReconstruct && !allDialogs.isEmpty()) {
     132            reconstruct(Action.ELEMENT_SHRINKS, toggleDialog);
    107133        }
    108134    }
     
    326352    @Override
    327353    public void destroy() {
    328         for (ToggleDialog t : allDialogs) {
     354        for (ToggleDialog t : new ArrayList<>(allDialogs)) {
    329355            try {
    330356                t.destroy();
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java

    r18216 r18686  
    478478    @Override
    479479    public void destroy() {
    480         dialogsPanel = null;
     480        if (dialogsPanel != null) {
     481            dialogsPanel.remove(this);
     482            dialogsPanel = null;
     483        }
    481484        rememberHeight();
    482485        closeDetachedDialog();
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java

    r18685 r18686  
    145145     */
    146146    private static void destroyInstance() {
     147        MapFrame map = MainApplication.getMap();
     148        synchronized (ImageViewerDialog.class) {
     149            if (dialog != null && map != null && map.getToggleDialog(ImageViewerDialog.class) != null) {
     150                map.removeToggleDialog(dialog);
     151            }
     152        }
    147153        dialog = null;
    148154    }
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialogTest.java

    r18685 r18686  
    2121import javax.swing.JPanel;
    2222
     23import org.junit.jupiter.api.AfterEach;
    2324import org.junit.jupiter.api.BeforeEach;
    2425import org.junit.jupiter.api.extension.RegisterExtension;
     
    4445
    4546    private ImageViewerDialog dialog;
     47
    4648    @BeforeEach
    4749    void setup() {
    4850        this.dialog = ImageViewerDialog.getInstance();
    4951        this.dialog.displayImages(null);
     52    }
     53
     54    @AfterEach
     55    void tearDown() {
     56        this.dialog.destroy();
    5057    }
    5158
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/geoimage/ImagesLoaderTest.java

    r18035 r18686  
    1010import java.util.List;
    1111
     12import org.junit.jupiter.api.AfterEach;
    1213import org.junit.jupiter.api.Test;
    13 import org.junit.jupiter.api.extension.RegisterExtension;
    1414import org.openstreetmap.josm.TestUtils;
    1515import org.openstreetmap.josm.gui.MainApplication;
    1616import org.openstreetmap.josm.gui.layer.GpxLayer;
    1717import org.openstreetmap.josm.io.GpxReader;
    18 import org.openstreetmap.josm.testutils.JOSMTestRules;
    19 
    20 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     18import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
    2119
    2220/**
    2321 * Unit tests of {@link ImagesLoader} class.
    2422 */
     23@BasicPreferences
    2524class ImagesLoaderTest {
    2625
    27     /**
    28      * We need prefs for this.
    29      */
    30     @RegisterExtension
    31     @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    32     public JOSMTestRules test = new JOSMTestRules().preferences();
     26    @AfterEach
     27    void tearDown() {
     28        if (ImageViewerDialog.hasInstance()) {
     29            ImageViewerDialog.getInstance().destroy();
     30        }
     31    }
    3332
    3433    /**
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/geoimage/WikimediaCommonsLoaderTest.java

    r18050 r18686  
    1111import java.util.List;
    1212
     13import org.junit.jupiter.api.AfterEach;
    1314import org.junit.jupiter.api.BeforeAll;
    1415import org.junit.jupiter.api.Test;
     
    2930    static void beforeAll() {
    3031        HttpClient.setFactory(Http1Client::new);
     32    }
     33
     34    @AfterEach
     35    void tearDown() {
     36        if (ImageViewerDialog.hasInstance()) {
     37            ImageViewerDialog.getInstance().destroy();
     38        }
    3139    }
    3240
Note: See TracChangeset for help on using the changeset viewer.