Changeset 18683 in josm for trunk/test


Ignore:
Timestamp:
2023-03-06T23:28:55+01:00 (2 years ago)
Author:
taylor.smock
Message:

Fix #22783: Presets menu should not sort the first action block

The specific problem was that when the preset menu was sorted, the order of
the Preset menu (prior to the first separator) was Search preset...,
Preset preferences..., Search for objects by preset... instead of
Search preset..., Search for objects by preset..., Preset Preferences...

The fix for this was changing the TaggingPresetMenu.PresetTextComparator.compare
method to have the same behavior for the ordered presets. A non-regression
test was also added.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetsTest.java

    r17275 r18683  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.gui.tagging.presets;
     3
     4import static org.junit.jupiter.api.Assertions.assertAll;
     5import static org.junit.jupiter.api.Assertions.assertSame;
     6import static org.junit.jupiter.api.Assertions.assertTrue;
    37
    48import java.util.Collection;
     
    812import java.util.concurrent.TimeoutException;
    913
    10 import org.junit.jupiter.api.Test;
    11 import org.junit.jupiter.api.extension.RegisterExtension;
    12 import org.openstreetmap.josm.testutils.JOSMTestRules;
    13 import org.openstreetmap.josm.tools.Logging;
     14import javax.swing.JMenu;
     15import javax.swing.JSeparator;
    1416
    1517import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    1618import net.trajano.commons.testing.UtilityClassTestUtil;
     19import org.junit.jupiter.api.Test;
     20import org.junit.jupiter.api.extension.RegisterExtension;
     21import org.junit.jupiter.params.ParameterizedTest;
     22import org.junit.jupiter.params.provider.ValueSource;
     23import org.openstreetmap.josm.actions.PreferencesAction;
     24import org.openstreetmap.josm.gui.MainApplication;
     25import org.openstreetmap.josm.gui.MainMenu;
     26import org.openstreetmap.josm.testutils.JOSMTestRules;
     27import org.openstreetmap.josm.tools.Logging;
    1728
    1829/**
     
    2637    @RegisterExtension
    2738    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    28     public JOSMTestRules test = new JOSMTestRules();
     39    public JOSMTestRules test = new JOSMTestRules().main();
    2940
    3041    /**
     
    3546    void testUtilityClass() throws ReflectiveOperationException {
    3647        UtilityClassTestUtil.assertUtilityClassWellDefined(TaggingPresets.class);
     48    }
     49
     50    /**
     51     * Ensure that sorting the menu does <em>not</em> change the order of the first 3 actions.
     52     * See {@link TaggingPresetMenu.PresetTextComparator} for the comparator to fix if this test
     53     * fails <i>after</i> adding a new menu item.
     54     */
     55    @ParameterizedTest
     56    @ValueSource(booleans = {true, false})
     57    void testNonRegression22783(boolean sort) {
     58        final MainMenu menu = MainApplication.getMenu();
     59        TaggingPresets.SORT_MENU.put(sort);
     60        TaggingPresets.initialize();
     61        final JMenu presetsMenu = menu.presetsMenu;
     62        assertAll(() -> assertSame(menu.presetSearchAction, presetsMenu.getItem(0).getAction()),
     63                () -> assertSame(menu.presetSearchPrimitiveAction, presetsMenu.getItem(1).getAction()),
     64                () -> assertTrue(presetsMenu.getItem(2).getAction() instanceof PreferencesAction),
     65                () -> assertTrue(presetsMenu.getMenuComponent(3) instanceof JSeparator));
    3766    }
    3867
Note: See TracChangeset for help on using the changeset viewer.