Ticket #16010: v2-0011-PreferencesTableTest-convert-to-use-of-JOSMTestRu.patch

File v2-0011-PreferencesTableTest-convert-to-use-of-JOSMTestRu.patch, 3.0 KB (added by ris, 11 months ago)
  • test/unit/org/openstreetmap/josm/gui/preferences/advanced/PreferencesTableTest.java

    From 904df3e690814695f6b67f76c217d779047871e5 Mon Sep 17 00:00:00 2001
    From: Robert Scott <code@humanleg.org.uk>
    Date: Mon, 19 Mar 2018 00:08:30 +0000
    Subject: [PATCH v2 11/28] PreferencesTableTest: convert to use of
     JOSMTestRules, ExtendedDialogMocker & JOptionPaneSimpleMocker
    
    won't yet have an effect until some internal isHeadless() checks are removed
    ---
     .../preferences/advanced/PreferencesTableTest.java | 36 +++++++++++++++++-----
     1 file changed, 28 insertions(+), 8 deletions(-)
    
    diff --git a/test/unit/org/openstreetmap/josm/gui/preferences/advanced/PreferencesTableTest.java b/test/unit/org/openstreetmap/josm/gui/preferences/advanced/PreferencesTableTest.java
    index 4790d806d..cfa51654a 100644
    a b import static org.junit.Assert.assertNull; 
    77import static org.junit.Assert.assertTrue;
    88
    99import java.util.Arrays;
     10import javax.swing.JOptionPane;
    1011
    11 import org.junit.BeforeClass;
     12import org.junit.Rule;
    1213import org.junit.Test;
    13 import org.openstreetmap.josm.JOSMFixture;
    1414import org.openstreetmap.josm.spi.preferences.StringSetting;
     15import org.openstreetmap.josm.gui.ExtendedDialog;
    1516import org.openstreetmap.josm.gui.preferences.advanced.PreferencesTable.AllSettingsTableModel;
    1617
     18import org.openstreetmap.josm.testutils.JOSMTestRules;
     19import org.openstreetmap.josm.testutils.JOptionPaneSimpleMocker;
     20import org.openstreetmap.josm.testutils.ExtendedDialogMocker;
     21
     22import com.google.common.collect.ImmutableMap;
     23
     24import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     25
    1726/**
    1827 * Unit tests of {@link PreferencesTable} class.
    1928 */
    2029public class PreferencesTableTest {
    21 
    2230    /**
    23      * Setup test.
     31     * Setup tests
    2432     */
    25     @BeforeClass
    26     public static void setUpBeforeClass() {
    27         JOSMFixture.createUnitTestFixture().init();
    28     }
     33    @Rule
     34    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
     35    public JOSMTestRules test = new JOSMTestRules().preferences().assertionsInEDT();
    2936
    3037    private static PrefEntry newPrefEntry(String value) {
    3138        StringSetting val = new StringSetting(value);
    public class PreferencesTableTest { 
    4249     */
    4350    @Test
    4451    public void testPreferencesTable() {
     52        new JOptionPaneSimpleMocker(ImmutableMap.of(
     53            "Please select the row to edit.", JOptionPane.OK_OPTION,
     54            "Please select the row to delete.", JOptionPane.OK_OPTION
     55        ));
     56        new ExtendedDialogMocker() {
     57            protected int getMockResult(final ExtendedDialog instance) {
     58                if (instance.getTitle().equals("Add setting")) {
     59                    return 1 + this.getButtonPositionFromLabel(instance, "Cancel");
     60                } else {
     61                    return super.getMockResult(instance);
     62                }
     63            }
     64        };
    4565        PreferencesTable t = newTable();
    4666        t.fireDataChanged();
    4767        assertTrue(t.getSelectedItems().isEmpty());