Ignore:
Timestamp:
2018-11-05T01:16:59+01:00 (5 years ago)
Author:
Don-vip
Message:

fix #16946, fix #16947 - unit test fixes for non-headless mode (patch by ris)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/gui/help/HelpBrowserTest.java

    r14369 r14412  
    1313import org.openstreetmap.josm.testutils.mockers.JOptionPaneSimpleMocker;
    1414import org.openstreetmap.josm.tools.LanguageInfo.LocaleType;
     15import org.openstreetmap.josm.tools.PlatformHook;
     16import org.openstreetmap.josm.tools.PlatformManager;
    1517
    1618import com.google.common.collect.ImmutableMap;
    1719
    1820import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     21import mockit.Expectations;
     22import mockit.Injectable;
    1923
    2024/**
     
    9195
    9296    /**
    93      * Unit test of {@link HelpBrowser.EditAction} class.
    94      */
    95     @Test
    96     public void testEditAction() {
    97         TestUtils.assumeWorkingJMockit();
     97     * Unit test of {@link HelpBrowser.EditAction} class handling a null url.
     98     * @param mockPlatformHook platform hook mock
     99     * @throws Exception  in case of error
     100     */
     101    @Test
     102    public void testEditActionNull(@Injectable final PlatformHook mockPlatformHook) throws Exception {
     103        TestUtils.assumeWorkingJMockit();
     104        new Expectations(PlatformManager.class) {{
     105            PlatformManager.getPlatform(); result = mockPlatformHook; minTimes = 0;
     106        }};
     107        new Expectations() {{
     108            // should not be called
     109            mockPlatformHook.openUrl((String) any); times = 0;
     110        }};
     111
    98112        IHelpBrowser browser = newHelpBrowser();
    99113        assertNull(browser.getUrl());
    100114        new HelpBrowser.EditAction(browser).actionPerformed(null);
    101 
     115    }
     116
     117    /**
     118     * Unit test of {@link HelpBrowser.EditAction} class handling an "internal" url.
     119     * @param mockPlatformHook platform hook mock
     120     * @throws Exception  in case of error
     121     */
     122    @Test
     123    public void testEditActionInternal(@Injectable final PlatformHook mockPlatformHook) throws Exception {
     124        TestUtils.assumeWorkingJMockit();
     125        new Expectations(PlatformManager.class) {{
     126            PlatformManager.getPlatform(); result = mockPlatformHook;
     127        }};
     128        new Expectations() {{
     129            mockPlatformHook.openUrl(URL_2 + "?action=edit"); result = null; times = 1;
     130        }};
     131
     132        IHelpBrowser browser = newHelpBrowser();
    102133        browser.openUrl(URL_2);
    103134        assertEquals(URL_2, browser.getUrl());
    104135        new HelpBrowser.EditAction(browser).actionPerformed(null);
    105 
     136    }
     137
     138    /**
     139     * Unit test of {@link HelpBrowser.EditAction} class handling an "external" url.
     140     * @param mockPlatformHook platform hook mock
     141     * @throws Exception  in case of error
     142     */
     143    @Test
     144    public void testEditActionExternal(@Injectable final PlatformHook mockPlatformHook) throws Exception {
     145        TestUtils.assumeWorkingJMockit();
     146        new Expectations(PlatformManager.class) {{
     147            PlatformManager.getPlatform(); result = mockPlatformHook; minTimes = 0;
     148        }};
     149        new Expectations() {{
     150            // should not be called
     151            mockPlatformHook.openUrl((String) any); times = 0;
     152        }};
    106153        final JOptionPaneSimpleMocker jopsMocker = new JOptionPaneSimpleMocker(
    107154            ImmutableMap.<String, Object>of(
     
    113160        );
    114161
     162        IHelpBrowser browser = newHelpBrowser();
    115163        browser.openUrl(URL_3);
    116164        assertEquals(URL_3, browser.getUrl());
     
    125173    /**
    126174     * Unit test of {@link HelpBrowser.OpenInBrowserAction} class.
    127      */
    128     @Test
    129     public void testOpenInBrowserAction() {
     175     * @param mockPlatformHook platform hook mock
     176     * @throws Exception  in case of error
     177     */
     178    @Test
     179    public void testOpenInBrowserAction(@Injectable final PlatformHook mockPlatformHook) throws Exception {
     180        TestUtils.assumeWorkingJMockit();
     181        new Expectations(PlatformManager.class) {{
     182            PlatformManager.getPlatform(); result = mockPlatformHook;
     183        }};
     184        new Expectations() {{
     185            mockPlatformHook.openUrl(URL_1); result = null; times = 1;
     186        }};
     187
    130188        IHelpBrowser browser = newHelpBrowser();
    131189        browser.openUrl(URL_1);
Note: See TracChangeset for help on using the changeset viewer.