Ignore:
Timestamp:
2018-07-26T22:01:31+02:00 (6 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
Files:
1 added
3 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();
  • trunk/test/unit/org/openstreetmap/josm/gui/preferences/plugin/PluginPreferenceTest.java

    r11974 r14052  
    1010import java.util.Collections;
    1111
    12 import org.junit.BeforeClass;
     12import org.junit.Rule;
    1313import org.junit.Test;
    14 import org.openstreetmap.josm.JOSMFixture;
    1514import org.openstreetmap.josm.TestUtils;
    1615import org.openstreetmap.josm.gui.preferences.PreferencesTestUtils;
     
    1918import org.openstreetmap.josm.plugins.PluginException;
    2019import org.openstreetmap.josm.plugins.PluginInformation;
     20import org.openstreetmap.josm.testutils.mockers.HelpAwareOptionPaneMocker;
     21import org.openstreetmap.josm.testutils.JOSMTestRules;
     22
     23import com.google.common.collect.ImmutableMap;
     24
     25import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    2126
    2227/**
     
    2429 */
    2530public class PluginPreferenceTest {
    26 
    2731    /**
    2832     * Setup test.
    2933     */
    30     @BeforeClass
    31     public static void setUpBeforeClass() {
    32         JOSMFixture.createUnitTestFixture().init();
    33     }
     34    @Rule
     35    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
     36    public JOSMTestRules test = new JOSMTestRules().preferences().assertionsInEDT().platform();
    3437
    3538    /**
     
    4851    public static PluginInformation getDummyPluginInformation() throws PluginException {
    4952        return new PluginInformation(
    50                 new File(TestUtils.getTestDataRoot() + "plugin/dummy_plugin.jar"), "dummy_plugin");
     53                new File(TestUtils.getTestDataRoot() + "__files/plugin/dummy_plugin.v31772.jar"), "dummy_plugin");
    5154    }
    5255
     
    8992    @Test
    9093    public void testNotifyDownloadResults() {
     94        new HelpAwareOptionPaneMocker(ImmutableMap.<String, Object>builder()
     95            .put("<html></html>", "OK")  // (buildDownloadSummary() output was empty)
     96            .put("<html>Please restart JOSM to activate the downloaded plugins.</html>", "OK")
     97            .build()
     98        );
     99
    91100        PluginDownloadTask task = new PluginDownloadTask(NullProgressMonitor.INSTANCE, Collections.<PluginInformation>emptyList(), "");
    92101        PluginPreference.notifyDownloadResults(null, task, false);
Note: See TracChangeset for help on using the changeset viewer.