Changeset 17126 in josm for trunk/test/unit/org


Ignore:
Timestamp:
2020-10-08T22:32:54+02:00 (4 years ago)
Author:
simon04
Message:

see #18200 - Fix PlatformHookWindowsTest after JMockit update

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/tools/PlatformHookWindowsTest.java

    r15469 r17126  
    22package org.openstreetmap.josm.tools;
    33
    4 import static org.junit.Assert.assertEquals;
    5 import static org.junit.Assert.assertFalse;
    6 import static org.junit.Assert.assertNotNull;
    7 import static org.junit.Assert.assertNull;
    8 import static org.junit.Assert.assertTrue;
    9 import static org.junit.Assert.fail;
     4import static org.junit.jupiter.api.Assertions.assertEquals;
     5import static org.junit.jupiter.api.Assertions.assertFalse;
     6import static org.junit.jupiter.api.Assertions.assertNotNull;
     7import static org.junit.jupiter.api.Assertions.assertNull;
     8import static org.junit.jupiter.api.Assertions.assertTrue;
     9import static org.junit.jupiter.api.Assertions.fail;
    1010
    1111import java.awt.Desktop;
     
    1515import java.util.Collection;
    1616
    17 import org.junit.BeforeClass;
    18 import org.junit.Test;
    19 import org.openstreetmap.josm.JOSMFixture;
     17import org.junit.jupiter.api.Test;
     18import org.junit.jupiter.api.BeforeAll;
     19import org.junit.jupiter.api.extension.RegisterExtension;
    2020import org.openstreetmap.josm.TestUtils;
    2121import org.openstreetmap.josm.spi.preferences.Config;
     22import org.openstreetmap.josm.testutils.JOSMTestRules;
     23
     24import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    2225
    2326import mockit.Expectations;
    24 import mockit.Injectable;
     27import mockit.Mocked;
    2528
    2629/**
     
    2932public class PlatformHookWindowsTest {
    3033
     34    /**
     35     * Setup tests
     36     */
     37    @RegisterExtension
     38    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
     39    public JOSMTestRules test = new JOSMTestRules().preferences().https();
     40
    3141    static PlatformHookWindows hook;
    3242
     
    3444     * Setup test.
    3545     */
    36     @BeforeClass
     46    @BeforeAll
    3747    public static void setUp() {
    38         JOSMFixture.createUnitTestFixture().init();
    3948        hook = new PlatformHookWindows();
    4049    }
     
    8089     */
    8190    @Test
    82     public void testOpenUrlSuccess(@Injectable final Desktop mockDesktop) throws IOException {
     91    public void testOpenUrlSuccess(@Mocked final Desktop mockDesktop) throws IOException {
    8392        TestUtils.assumeWorkingJMockit();
    84         new Expectations(Desktop.class) {{
     93        new Expectations() {{
    8594            // real implementation would raise HeadlessException
    8695            Desktop.getDesktop(); result = mockDesktop; times = 1;
    87         }};
    88         new Expectations() {{
    8996            mockDesktop.browse(withNotNull()); times = 1;
    9097        }};
     
    96103     * Test method for {@code PlatformHookWindows#openUrl} when Desktop fails
    97104     * @param mockDesktop desktop mock
     105     * @param anyRuntime runtime mock
    98106     * @throws IOException if an error occurs
    99107     */
    100108    @Test
    101     public void testOpenUrlFallback(@Injectable final Desktop mockDesktop) throws IOException {
     109    public void testOpenUrlFallback(@Mocked final Desktop mockDesktop, @Mocked Runtime anyRuntime) throws IOException {
    102110        TestUtils.assumeWorkingJMockit();
    103         new Expectations(Desktop.class) {{
     111        new Expectations() {{
    104112            // real implementation would raise HeadlessException
    105113            Desktop.getDesktop(); result = mockDesktop; times = 1;
    106         }};
    107         new Expectations() {{
    108114            mockDesktop.browse(withNotNull()); result = new IOException(); times = 1;
    109         }};
    110         final Runtime anyRuntime = Runtime.getRuntime();
    111         new Expectations(Runtime.class) {{
     115
     116            // mock rundll32 in Runtime
     117            Runtime.getRuntime(); result = anyRuntime; times = 1;
    112118            anyRuntime.exec(new String[] {"rundll32", "url.dll,FileProtocolHandler", Config.getUrls().getJOSMWebsite()});
    113119            result = null;
Note: See TracChangeset for help on using the changeset viewer.