Changeset 14412 in josm for trunk/test/unit/org/openstreetmap/josm/tools
- Timestamp:
- 2018-11-05T01:16:59+01:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/tools/PlatformHookWindowsTest.java
r14168 r14412 10 10 import static org.junit.Assert.fail; 11 11 12 import java.awt.Desktop; 12 13 import java.io.File; 13 14 import java.io.IOException; … … 20 21 import org.junit.Test; 21 22 import org.openstreetmap.josm.JOSMFixture; 23 import org.openstreetmap.josm.TestUtils; 22 24 import org.openstreetmap.josm.io.remotecontrol.RemoteControlHttpsServer; 23 25 import org.openstreetmap.josm.io.remotecontrol.RemoteControlTest; 24 26 import org.openstreetmap.josm.spi.preferences.Config; 27 28 import mockit.Expectations; 29 import mockit.Injectable; 25 30 26 31 /** … … 117 122 118 123 /** 119 * Test method for {@code PlatformHookWindows#openUrl} 124 * Test method for {@code PlatformHookWindows#openUrl} when Desktop works as expected 125 * @param mockDesktop desktop mock 120 126 * @throws IOException if an error occurs 121 127 */ 122 128 @Test 123 public void testOpenUrl() throws IOException { 124 if (PlatformManager.isPlatformWindows()) { 125 hook.openUrl(Config.getUrls().getJOSMWebsite()); 126 } else { 127 try { 128 hook.openUrl(Config.getUrls().getJOSMWebsite()); 129 fail("Expected IOException"); 130 } catch (IOException e) { 131 Logging.info(e.getMessage()); 132 } 133 } 129 public void testOpenUrlSuccess(@Injectable final Desktop mockDesktop) throws IOException { 130 TestUtils.assumeWorkingJMockit(); 131 new Expectations(Desktop.class) {{ 132 // real implementation would raise HeadlessException 133 Desktop.getDesktop(); result = mockDesktop; times = 1; 134 }}; 135 new Expectations() {{ 136 mockDesktop.browse(withNotNull()); times = 1; 137 }}; 138 139 hook.openUrl(Config.getUrls().getJOSMWebsite()); 140 } 141 142 /** 143 * Test method for {@code PlatformHookWindows#openUrl} when Desktop fails 144 * @param mockDesktop desktop mock 145 * @throws IOException if an error occurs 146 */ 147 @Test 148 public void testOpenUrlFallback(@Injectable final Desktop mockDesktop) throws IOException { 149 TestUtils.assumeWorkingJMockit(); 150 new Expectations(Desktop.class) {{ 151 // real implementation would raise HeadlessException 152 Desktop.getDesktop(); result = mockDesktop; times = 1; 153 }}; 154 new Expectations() {{ 155 mockDesktop.browse(withNotNull()); result = new IOException(); times = 1; 156 }}; 157 final Runtime anyRuntime = Runtime.getRuntime(); 158 new Expectations(Runtime.class) {{ 159 anyRuntime.exec(new String[] {"rundll32", "url.dll,FileProtocolHandler", Config.getUrls().getJOSMWebsite()}); 160 result = null; 161 times = 1; 162 // prevent a non-matching invocation being executed 163 anyRuntime.exec((String[]) withNotNull()); result = null; times = 0; 164 }}; 165 166 hook.openUrl(Config.getUrls().getJOSMWebsite()); 134 167 } 135 168
Note:
See TracChangeset
for help on using the changeset viewer.