| 1 | // License: GPL. For details, see LICENSE file. |
| 2 | package org.openstreetmap.josm.testutils.mockers; |
| 3 | |
| 4 | import static org.openstreetmap.josm.tools.I18n.tr; |
| 5 | |
| 6 | import java.net.URI; |
| 7 | import java.util.ArrayList; |
| 8 | import java.util.List; |
| 9 | |
| 10 | import org.openstreetmap.josm.tools.CheckParameterUtil; |
| 11 | import org.openstreetmap.josm.tools.Logging; |
| 12 | import org.openstreetmap.josm.tools.OpenBrowser; |
| 13 | |
| 14 | import mockit.Mock; |
| 15 | import mockit.MockUp; |
| 16 | |
| 17 | /** |
| 18 | * MockUp for {@link OpenBrowser}. |
| 19 | * |
| 20 | * @author Taylor Smock |
| 21 | * @since xxx |
| 22 | */ |
| 23 | public class OpenBrowserMocker extends MockUp<OpenBrowser> { |
| 24 | private static List<URI> calledUris = new ArrayList<>(); |
| 25 | /** |
| 26 | * A Mock for {@link OpenBrowser#displayUrl} that doesn't actually open a |
| 27 | * browser window, for use in headless environments. |
| 28 | * |
| 29 | * @param uri The URI to display (theoretically) |
| 30 | * @return <code>null</code> for success. |
| 31 | */ |
| 32 | @Mock |
| 33 | public static String displayUrl(URI uri) { |
| 34 | CheckParameterUtil.ensureParameterNotNull(uri, "uri"); |
| 35 | |
| 36 | Logging.info(tr("Opening URL: {0}", uri)); |
| 37 | calledUris.add(uri); |
| 38 | |
| 39 | return null; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Get the called URIs |
| 44 | * |
| 45 | * @return A list of called URIs |
| 46 | */ |
| 47 | public static List<URI> getCalledURIs() { |
| 48 | return calledUris; |
| 49 | } |
| 50 | } |