Last change
on this file since 17360 was 15932, checked in by Don-vip, 4 years ago |
fix #18766 - Add mocker for OpenBrowser.displayUrl (patch by taylor.smock)
|
-
Property svn:eol-style
set to
native
|
File size:
1.2 KB
|
Line | |
---|
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 | */
|
---|
22 | public class OpenBrowserMocker extends MockUp<OpenBrowser> {
|
---|
23 | private static final List<URI> calledUris = new ArrayList<>();
|
---|
24 |
|
---|
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 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.