Changeset 17126 in josm
- Timestamp:
- 2020-10-08T22:32:54+02:00 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/tools/PlatformHookWindowsTest.java
r15469 r17126 2 2 package org.openstreetmap.josm.tools; 3 3 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;4 import static org.junit.jupiter.api.Assertions.assertEquals; 5 import static org.junit.jupiter.api.Assertions.assertFalse; 6 import static org.junit.jupiter.api.Assertions.assertNotNull; 7 import static org.junit.jupiter.api.Assertions.assertNull; 8 import static org.junit.jupiter.api.Assertions.assertTrue; 9 import static org.junit.jupiter.api.Assertions.fail; 10 10 11 11 import java.awt.Desktop; … … 15 15 import java.util.Collection; 16 16 17 import org.junit. BeforeClass;18 import org.junit. Test;19 import org. openstreetmap.josm.JOSMFixture;17 import org.junit.jupiter.api.Test; 18 import org.junit.jupiter.api.BeforeAll; 19 import org.junit.jupiter.api.extension.RegisterExtension; 20 20 import org.openstreetmap.josm.TestUtils; 21 21 import org.openstreetmap.josm.spi.preferences.Config; 22 import org.openstreetmap.josm.testutils.JOSMTestRules; 23 24 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 22 25 23 26 import mockit.Expectations; 24 import mockit. Injectable;27 import mockit.Mocked; 25 28 26 29 /** … … 29 32 public class PlatformHookWindowsTest { 30 33 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 31 41 static PlatformHookWindows hook; 32 42 … … 34 44 * Setup test. 35 45 */ 36 @Before Class46 @BeforeAll 37 47 public static void setUp() { 38 JOSMFixture.createUnitTestFixture().init();39 48 hook = new PlatformHookWindows(); 40 49 } … … 80 89 */ 81 90 @Test 82 public void testOpenUrlSuccess(@ Injectablefinal Desktop mockDesktop) throws IOException {91 public void testOpenUrlSuccess(@Mocked final Desktop mockDesktop) throws IOException { 83 92 TestUtils.assumeWorkingJMockit(); 84 new Expectations( Desktop.class) {{93 new Expectations() {{ 85 94 // real implementation would raise HeadlessException 86 95 Desktop.getDesktop(); result = mockDesktop; times = 1; 87 }};88 new Expectations() {{89 96 mockDesktop.browse(withNotNull()); times = 1; 90 97 }}; … … 96 103 * Test method for {@code PlatformHookWindows#openUrl} when Desktop fails 97 104 * @param mockDesktop desktop mock 105 * @param anyRuntime runtime mock 98 106 * @throws IOException if an error occurs 99 107 */ 100 108 @Test 101 public void testOpenUrlFallback(@ Injectable final Desktop mockDesktop) throws IOException {109 public void testOpenUrlFallback(@Mocked final Desktop mockDesktop, @Mocked Runtime anyRuntime) throws IOException { 102 110 TestUtils.assumeWorkingJMockit(); 103 new Expectations( Desktop.class) {{111 new Expectations() {{ 104 112 // real implementation would raise HeadlessException 105 113 Desktop.getDesktop(); result = mockDesktop; times = 1; 106 }};107 new Expectations() {{108 114 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; 112 118 anyRuntime.exec(new String[] {"rundll32", "url.dll,FileProtocolHandler", Config.getUrls().getJOSMWebsite()}); 113 119 result = null;
Note:
See TracChangeset
for help on using the changeset viewer.