Ticket #18200: 18200.HelpBrowserTest.patch
| File 18200.HelpBrowserTest.patch, 6.3 KB (added by , 5 years ago) |
|---|
-
test/unit/org/openstreetmap/josm/gui/help/HelpBrowserTest.java
1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.help; 3 3 4 import static org.junit. Assert.assertEquals;5 import static org.junit. Assert.assertNull;4 import static org.junit.jupiter.api.Assertions.assertEquals; 5 import static org.junit.jupiter.api.Assertions.assertNull; 6 6 7 7 import java.util.Collections; 8 8 9 9 import javax.swing.JOptionPane; 10 10 11 import org.junit. Rule;12 import org.junit. Test;11 import org.junit.jupiter.api.Test; 12 import org.junit.jupiter.api.extension.RegisterExtension; 13 13 import org.openstreetmap.josm.TestUtils; 14 14 import org.openstreetmap.josm.testutils.JOSMTestRules; 15 15 import org.openstreetmap.josm.testutils.mockers.JOptionPaneSimpleMocker; … … 20 20 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 21 21 import mockit.Expectations; 22 22 import mockit.Injectable; 23 import mockit.Mocked; 23 24 24 25 /** 25 26 * Unit tests of {@link HelpBrowser} class. 26 27 */ 27 publicclass HelpBrowserTest {28 class HelpBrowserTest { 28 29 29 30 static final String URL_1 = "https://josm.openstreetmap.de/wiki/Help"; 30 31 static final String URL_2 = "https://josm.openstreetmap.de/wiki/Introduction"; … … 33 34 /** 34 35 * Setup tests 35 36 */ 36 @R ule37 @RegisterExtension 37 38 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 38 public JOSMTestRules test = new JOSMTestRules().preferences().https();39 static JOSMTestRules test = new JOSMTestRules().preferences().https(); 39 40 40 41 static IHelpBrowser newHelpBrowser() { 41 42 return new IHelpBrowser() { … … 75 76 * Unit test of {@link HelpBrowser.BackAction} and {@link HelpBrowser.ForwardAction} classes. 76 77 */ 77 78 @Test 78 publicvoid testBackAndForwardActions() {79 void testBackAndForwardActions() { 79 80 IHelpBrowser browser = newHelpBrowser(); 80 81 browser.openUrl(URL_1); 81 82 assertEquals(URL_1, browser.getUrl()); … … 91 92 * Unit test of {@link HelpBrowser.HomeAction} class. 92 93 */ 93 94 @Test 94 publicvoid testHomeAction() {95 void testHomeAction() { 95 96 IHelpBrowser browser = newHelpBrowser(); 96 97 assertNull(browser.getUrl()); 97 98 new HelpBrowser.HomeAction(browser).actionPerformed(null); … … 101 102 /** 102 103 * Unit test of {@link HelpBrowser.EditAction} class handling a null url. 103 104 * @param mockPlatformHook platform hook mock 105 * @param platformManager {@link PlatformManager} mock 104 106 * @throws Exception in case of error 105 107 */ 106 108 @Test 107 public void testEditActionNull(@Injectable final PlatformHook mockPlatformHook) throws Exception {109 void testEditActionNull(@Injectable final PlatformHook mockPlatformHook, @Mocked final PlatformManager platformManager) throws Exception { 108 110 TestUtils.assumeWorkingJMockit(); 109 new Expectations( PlatformManager.class) {{111 new Expectations() {{ 110 112 PlatformManager.getPlatform(); result = mockPlatformHook; minTimes = 0; 111 }};112 new Expectations() {{113 113 // should not be called 114 114 mockPlatformHook.openUrl((String) any); times = 0; 115 115 }}; … … 122 122 /** 123 123 * Unit test of {@link HelpBrowser.EditAction} class handling an "internal" url. 124 124 * @param mockPlatformHook platform hook mock 125 * @param platformManager {@link PlatformManager} mock 125 126 * @throws Exception in case of error 126 127 */ 127 128 @Test 128 public void testEditActionInternal(@Injectable final PlatformHook mockPlatformHook) throws Exception {129 void testEditActionInternal(@Injectable final PlatformHook mockPlatformHook, @Mocked final PlatformManager platformManager) throws Exception { 129 130 TestUtils.assumeWorkingJMockit(); 130 new Expectations( PlatformManager.class) {{131 new Expectations() {{ 131 132 PlatformManager.getPlatform(); result = mockPlatformHook; 132 }};133 new Expectations() {{134 133 mockPlatformHook.openUrl(URL_2 + "?action=edit"); result = null; times = 1; 135 134 }}; 136 135 … … 143 142 /** 144 143 * Unit test of {@link HelpBrowser.EditAction} class handling an "external" url. 145 144 * @param mockPlatformHook platform hook mock 145 * @param platformManager {@link PlatformManager} mock 146 146 * @throws Exception in case of error 147 147 */ 148 148 @Test 149 public void testEditActionExternal(@Injectable final PlatformHook mockPlatformHook) throws Exception {149 void testEditActionExternal(@Injectable final PlatformHook mockPlatformHook, @Mocked final PlatformManager platformManager) throws Exception { 150 150 TestUtils.assumeWorkingJMockit(); 151 new Expectations( PlatformManager.class) {{151 new Expectations() {{ 152 152 PlatformManager.getPlatform(); result = mockPlatformHook; minTimes = 0; 153 }};154 new Expectations() {{155 153 // should not be called 156 154 mockPlatformHook.openUrl((String) any); times = 0; 157 155 }}; … … 177 175 178 176 /** 179 177 * 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 181 180 * @throws Exception in case of error 182 181 */ 183 182 @Test 184 public void testOpenInBrowserAction(@Injectable final PlatformHook mockPlatformHook) throws Exception {183 void testOpenInBrowserAction(@Injectable final PlatformHook mockPlatformHook, @Mocked final PlatformManager platformManager) throws Exception { 185 184 TestUtils.assumeWorkingJMockit(); 186 new Expectations( PlatformManager.class) {{185 new Expectations() {{ 187 186 PlatformManager.getPlatform(); result = mockPlatformHook; 188 }};189 new Expectations() {{190 187 mockPlatformHook.openUrl(URL_1); result = null; times = 1; 191 188 }}; 192 189 … … 200 197 * Unit test of {@link HelpBrowser.ReloadAction} class. 201 198 */ 202 199 @Test 203 publicvoid testReloadAction() {200 void testReloadAction() { 204 201 IHelpBrowser browser = newHelpBrowser(); 205 202 browser.openUrl(URL_1); 206 203 assertEquals(URL_1, browser.getUrl());
