Ignore:
Timestamp:
2018-07-26T22:01:31+02:00 (3 years ago)
Author:
Don-vip
Message:

see #16010 - use JMockit to enable more extensive test coverage (patch by ris, modified)

see https://github.com/openstreetmap/josm/pull/24/commits for details

Location:
trunk/test/unit/org/openstreetmap/josm/gui/preferences/advanced
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/gui/preferences/advanced/ExportProfileActionTest.java

    r10378 r14052  
    22package org.openstreetmap.josm.gui.preferences.advanced;
    33
    4 import org.junit.BeforeClass;
     4import javax.swing.JOptionPane;
     5
     6import org.junit.Rule;
    57import org.junit.Test;
    6 import org.openstreetmap.josm.JOSMFixture;
    78import org.openstreetmap.josm.Main;
     9import org.openstreetmap.josm.testutils.JOSMTestRules;
     10import org.openstreetmap.josm.testutils.mockers.JOptionPaneSimpleMocker;
     11
     12import com.google.common.collect.ImmutableMap;
     13
     14import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    815
    916/**
     
    1118 */
    1219public class ExportProfileActionTest {
    13 
    1420    /**
    15      * Setup test.
     21     * Setup tests
    1622     */
    17     @BeforeClass
    18     public static void setUpBeforeClass() {
    19         JOSMFixture.createUnitTestFixture().init();
    20     }
     23    @Rule
     24    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
     25    public JOSMTestRules test = new JOSMTestRules().preferences().assertionsInEDT();
    2126
    2227    /**
     
    2530    @Test
    2631    public void testAction() {
     32        new JOptionPaneSimpleMocker(ImmutableMap.of(
     33            "All the preferences of this group are default, nothing to save", JOptionPane.OK_OPTION
     34        ));
    2735        new ExportProfileAction(Main.pref, "foo", "bar").actionPerformed(null);
    2836        new ExportProfileAction(Main.pref, "expert", "expert").actionPerformed(null);
  • trunk/test/unit/org/openstreetmap/josm/gui/preferences/advanced/PreferencesTableTest.java

    r12884 r14052  
    99import java.util.Arrays;
    1010
    11 import org.junit.BeforeClass;
     11import javax.swing.JOptionPane;
     12
     13import org.junit.Rule;
    1214import org.junit.Test;
    13 import org.openstreetmap.josm.JOSMFixture;
     15import org.openstreetmap.josm.gui.ExtendedDialog;
     16import org.openstreetmap.josm.gui.preferences.advanced.PreferencesTable.AllSettingsTableModel;
    1417import org.openstreetmap.josm.spi.preferences.StringSetting;
    15 import org.openstreetmap.josm.gui.preferences.advanced.PreferencesTable.AllSettingsTableModel;
     18import org.openstreetmap.josm.testutils.JOSMTestRules;
     19import org.openstreetmap.josm.testutils.mockers.ExtendedDialogMocker;
     20import org.openstreetmap.josm.testutils.mockers.JOptionPaneSimpleMocker;
     21
     22import com.google.common.collect.ImmutableMap;
     23
     24import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    1625
    1726/**
     
    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) {
     
    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            @Override
     58            protected int getMockResult(final ExtendedDialog instance) {
     59                if (instance.getTitle().equals("Add setting")) {
     60                    return 1 + this.getButtonPositionFromLabel(instance, "Cancel");
     61                } else {
     62                    return super.getMockResult(instance);
     63                }
     64            }
     65        };
    4566        PreferencesTable t = newTable();
    4667        t.fireDataChanged();
Note: See TracChangeset for help on using the changeset viewer.