Ticket #18200: 18200.HelpBrowserTest.patch

File 18200.HelpBrowserTest.patch, 6.3 KB (added by taylor.smock, 6 months ago)

Fix for HelpBrowserTest

  • test/unit/org/openstreetmap/josm/gui/help/HelpBrowserTest.java

     
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.gui.help;
    33
    4 import static org.junit.Assert.assertEquals;
    5 import static org.junit.Assert.assertNull;
     4import static org.junit.jupiter.api.Assertions.assertEquals;
     5import static org.junit.jupiter.api.Assertions.assertNull;
    66
    77import java.util.Collections;
    88
    99import javax.swing.JOptionPane;
    1010
    11 import org.junit.Rule;
    12 import org.junit.Test;
     11import org.junit.jupiter.api.Test;
     12import org.junit.jupiter.api.extension.RegisterExtension;
    1313import org.openstreetmap.josm.TestUtils;
    1414import org.openstreetmap.josm.testutils.JOSMTestRules;
    1515import org.openstreetmap.josm.testutils.mockers.JOptionPaneSimpleMocker;
     
    2020import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    2121import mockit.Expectations;
    2222import mockit.Injectable;
     23import mockit.Mocked;
    2324
    2425/**
    2526 * Unit tests of {@link HelpBrowser} class.
    2627 */
    27 public class HelpBrowserTest {
     28class HelpBrowserTest {
    2829
    2930    static final String URL_1 = "https://josm.openstreetmap.de/wiki/Help";
    3031    static final String URL_2 = "https://josm.openstreetmap.de/wiki/Introduction";
     
    3334    /**
    3435     * Setup tests
    3536     */
    36     @Rule
     37    @RegisterExtension
    3738    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    38     public JOSMTestRules test = new JOSMTestRules().preferences().https();
     39    static JOSMTestRules test = new JOSMTestRules().preferences().https();
    3940
    4041    static IHelpBrowser newHelpBrowser() {
    4142        return new IHelpBrowser() {
     
    7576     * Unit test of {@link HelpBrowser.BackAction} and {@link HelpBrowser.ForwardAction} classes.
    7677     */
    7778    @Test
    78     public void testBackAndForwardActions() {
     79    void testBackAndForwardActions() {
    7980        IHelpBrowser browser = newHelpBrowser();
    8081        browser.openUrl(URL_1);
    8182        assertEquals(URL_1, browser.getUrl());
     
    9192     * Unit test of {@link HelpBrowser.HomeAction} class.
    9293     */
    9394    @Test
    94     public void testHomeAction() {
     95    void testHomeAction() {
    9596        IHelpBrowser browser = newHelpBrowser();
    9697        assertNull(browser.getUrl());
    9798        new HelpBrowser.HomeAction(browser).actionPerformed(null);
     
    101102    /**
    102103     * Unit test of {@link HelpBrowser.EditAction} class handling a null url.
    103104     * @param mockPlatformHook platform hook mock
     105     * @param platformManager {@link PlatformManager} mock
    104106     * @throws Exception  in case of error
    105107     */
    106108    @Test
    107     public void testEditActionNull(@Injectable final PlatformHook mockPlatformHook) throws Exception {
     109    void testEditActionNull(@Injectable final PlatformHook mockPlatformHook, @Mocked final PlatformManager platformManager) throws Exception {
    108110        TestUtils.assumeWorkingJMockit();
    109         new Expectations(PlatformManager.class) {{
     111        new Expectations() {{
    110112            PlatformManager.getPlatform(); result = mockPlatformHook; minTimes = 0;
    111         }};
    112         new Expectations() {{
    113113            // should not be called
    114114            mockPlatformHook.openUrl((String) any); times = 0;
    115115        }};
     
    122122    /**
    123123     * Unit test of {@link HelpBrowser.EditAction} class handling an "internal" url.
    124124     * @param mockPlatformHook platform hook mock
     125     * @param platformManager {@link PlatformManager} mock
    125126     * @throws Exception  in case of error
    126127     */
    127128    @Test
    128     public void testEditActionInternal(@Injectable final PlatformHook mockPlatformHook) throws Exception {
     129    void testEditActionInternal(@Injectable final PlatformHook mockPlatformHook, @Mocked final PlatformManager platformManager) throws Exception {
    129130        TestUtils.assumeWorkingJMockit();
    130         new Expectations(PlatformManager.class) {{
     131        new Expectations() {{
    131132            PlatformManager.getPlatform(); result = mockPlatformHook;
    132         }};
    133         new Expectations() {{
    134133            mockPlatformHook.openUrl(URL_2 + "?action=edit"); result = null; times = 1;
    135134        }};
    136135
     
    143142    /**
    144143     * Unit test of {@link HelpBrowser.EditAction} class handling an "external" url.
    145144     * @param mockPlatformHook platform hook mock
     145     * @param platformManager {@link PlatformManager} mock
    146146     * @throws Exception  in case of error
    147147     */
    148148    @Test
    149     public void testEditActionExternal(@Injectable final PlatformHook mockPlatformHook) throws Exception {
     149    void testEditActionExternal(@Injectable final PlatformHook mockPlatformHook, @Mocked final PlatformManager platformManager) throws Exception {
    150150        TestUtils.assumeWorkingJMockit();
    151         new Expectations(PlatformManager.class) {{
     151        new Expectations() {{
    152152            PlatformManager.getPlatform(); result = mockPlatformHook; minTimes = 0;
    153         }};
    154         new Expectations() {{
    155153            // should not be called
    156154            mockPlatformHook.openUrl((String) any); times = 0;
    157155        }};
     
    177175
    178176    /**
    179177     * Unit test of {@link HelpBrowser.OpenInBrowserAction} class.
    180      * @param mockPlatformHook platform hook mock
     178     * @param mockPlatformHook platform hook moc
     179     * @param platformManager {@link PlatformManager} mock
    181180     * @throws Exception  in case of error
    182181     */
    183182    @Test
    184     public void testOpenInBrowserAction(@Injectable final PlatformHook mockPlatformHook) throws Exception {
     183    void testOpenInBrowserAction(@Injectable final PlatformHook mockPlatformHook, @Mocked final PlatformManager platformManager) throws Exception {
    185184        TestUtils.assumeWorkingJMockit();
    186         new Expectations(PlatformManager.class) {{
     185        new Expectations() {{
    187186            PlatformManager.getPlatform(); result = mockPlatformHook;
    188         }};
    189         new Expectations() {{
    190187            mockPlatformHook.openUrl(URL_1); result = null; times = 1;
    191188        }};
    192189
     
    200197     * Unit test of {@link HelpBrowser.ReloadAction} class.
    201198     */
    202199    @Test
    203     public void testReloadAction() {
     200    void testReloadAction() {
    204201        IHelpBrowser browser = newHelpBrowser();
    205202        browser.openUrl(URL_1);
    206203        assertEquals(URL_1, browser.getUrl());