Changeset 14412 in josm for trunk/test/unit/org/openstreetmap
- Timestamp:
- 2018-11-05T01:16:59+01:00 (6 years ago)
- Location:
- trunk/test/unit/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/gui/datatransfer/ClipboardUtilsTest.java
r11921 r14412 7 7 import static org.junit.Assert.assertSame; 8 8 import static org.junit.Assert.assertTrue; 9 import static org.junit.Assume.assumeTrue; 9 10 10 11 import java.awt.GraphicsEnvironment; … … 118 119 @Test 119 120 public void testSystemSelectionDoesNotFail() { 120 ass ertTrue(GraphicsEnvironment.isHeadless());121 assumeTrue(GraphicsEnvironment.isHeadless()); 121 122 assertNull(ClipboardUtils.getSystemSelection()); 122 123 } -
trunk/test/unit/org/openstreetmap/josm/gui/help/HelpBrowserTest.java
r14369 r14412 13 13 import org.openstreetmap.josm.testutils.mockers.JOptionPaneSimpleMocker; 14 14 import org.openstreetmap.josm.tools.LanguageInfo.LocaleType; 15 import org.openstreetmap.josm.tools.PlatformHook; 16 import org.openstreetmap.josm.tools.PlatformManager; 15 17 16 18 import com.google.common.collect.ImmutableMap; 17 19 18 20 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 21 import mockit.Expectations; 22 import mockit.Injectable; 19 23 20 24 /** … … 91 95 92 96 /** 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 98 112 IHelpBrowser browser = newHelpBrowser(); 99 113 assertNull(browser.getUrl()); 100 114 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(); 102 133 browser.openUrl(URL_2); 103 134 assertEquals(URL_2, browser.getUrl()); 104 135 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 }}; 106 153 final JOptionPaneSimpleMocker jopsMocker = new JOptionPaneSimpleMocker( 107 154 ImmutableMap.<String, Object>of( … … 113 160 ); 114 161 162 IHelpBrowser browser = newHelpBrowser(); 115 163 browser.openUrl(URL_3); 116 164 assertEquals(URL_3, browser.getUrl()); … … 125 173 /** 126 174 * 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 130 188 IHelpBrowser browser = newHelpBrowser(); 131 189 browser.openUrl(URL_1); -
trunk/test/unit/org/openstreetmap/josm/gui/layer/markerlayer/WebMarkerTest.java
r13031 r14412 4 4 import static org.junit.Assert.assertEquals; 5 5 6 import java.net.MalformedURLException;7 6 import java.net.URL; 8 7 … … 10 9 import org.junit.Test; 11 10 import org.openstreetmap.josm.JOSMFixture; 11 import org.openstreetmap.josm.TestUtils; 12 12 import org.openstreetmap.josm.data.coor.LatLon; 13 13 import org.openstreetmap.josm.data.gpx.GpxData; 14 14 import org.openstreetmap.josm.data.gpx.WayPoint; 15 import org.openstreetmap.josm.tools.PlatformManager; 16 import org.openstreetmap.josm.tools.PlatformHook; 17 18 19 import mockit.Expectations; 20 import mockit.Injectable; 15 21 16 22 /** … … 29 35 /** 30 36 * Unit test of {@link WebMarker#WebMarker}. 31 * @throws MalformedURLException never 37 * @param mockPlatformHook platform hook mock 38 * @throws Exception in case of error 32 39 */ 33 40 @Test 34 public void testWebMarker() throws MalformedURLException { 41 public void testWebMarker(@Injectable final PlatformHook mockPlatformHook) throws Exception { 42 TestUtils.assumeWorkingJMockit(); 43 new Expectations(PlatformManager.class) {{ 44 PlatformManager.getPlatform(); result = mockPlatformHook; 45 }}; 46 new Expectations() {{ 47 mockPlatformHook.openUrl("http://example.com"); result = null; times = 1; 48 }}; 49 35 50 WebMarker marker = new WebMarker( 36 51 LatLon.ZERO, -
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.