1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.tools;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 | import static org.junit.Assert.assertFalse;
|
---|
6 | import static org.junit.Assert.assertNotNull;
|
---|
7 | import static org.junit.Assert.assertNull;
|
---|
8 | import static org.junit.Assert.assertTrue;
|
---|
9 | import static org.junit.Assert.fail;
|
---|
10 |
|
---|
11 | import java.io.File;
|
---|
12 | import java.io.IOException;
|
---|
13 | import java.security.KeyStore;
|
---|
14 | import java.security.KeyStore.TrustedCertificateEntry;
|
---|
15 | import java.security.KeyStoreException;
|
---|
16 | import java.util.Collection;
|
---|
17 |
|
---|
18 | import org.junit.BeforeClass;
|
---|
19 | import org.junit.Test;
|
---|
20 | import org.openstreetmap.josm.JOSMFixture;
|
---|
21 | import org.openstreetmap.josm.Main;
|
---|
22 | import org.openstreetmap.josm.io.remotecontrol.RemoteControlHttpsServer;
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * Unit tests of {@link PlatformHookWindows} class.
|
---|
26 | */
|
---|
27 | public class PlatformHookWindowsTest {
|
---|
28 |
|
---|
29 | static PlatformHookWindows hook;
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Setup test.
|
---|
33 | */
|
---|
34 | @BeforeClass
|
---|
35 | public static void setUp() {
|
---|
36 | JOSMFixture.createUnitTestFixture().init();
|
---|
37 | hook = new PlatformHookWindows();
|
---|
38 | }
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * Test method for {@code PlatformHookWindows#startupHook}
|
---|
42 | */
|
---|
43 | @Test
|
---|
44 | public void testStartupHook() {
|
---|
45 | hook.startupHook();
|
---|
46 | }
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * Test method for {@code PlatformHookWindows#getRootKeystore}
|
---|
50 | * @throws Exception if an error occurs
|
---|
51 | */
|
---|
52 | @Test
|
---|
53 | public void testGetRootKeystore() throws Exception {
|
---|
54 | if (Main.isPlatformWindows()) {
|
---|
55 | assertNotNull(PlatformHookWindows.getRootKeystore());
|
---|
56 | } else {
|
---|
57 | try {
|
---|
58 | PlatformHookWindows.getRootKeystore();
|
---|
59 | fail("Expected KeyStoreException");
|
---|
60 | } catch (KeyStoreException e) {
|
---|
61 | Main.info(e.getMessage());
|
---|
62 | }
|
---|
63 | }
|
---|
64 | }
|
---|
65 |
|
---|
66 | /**
|
---|
67 | * Test method for {@code PlatformHookWindows#removeInsecureCertificates}
|
---|
68 | * @throws Exception if an error occurs
|
---|
69 | */
|
---|
70 | @Test
|
---|
71 | public void testRemoveInsecureCertificates() throws Exception {
|
---|
72 | if (Main.isPlatformWindows()) {
|
---|
73 | PlatformHookWindows.removeInsecureCertificates();
|
---|
74 | } else {
|
---|
75 | try {
|
---|
76 | PlatformHookWindows.removeInsecureCertificates();
|
---|
77 | fail("Expected KeyStoreException");
|
---|
78 | } catch (KeyStoreException e) {
|
---|
79 | Main.info(e.getMessage());
|
---|
80 | }
|
---|
81 | }
|
---|
82 | }
|
---|
83 |
|
---|
84 | /**
|
---|
85 | * Test method for {@code PlatformHookWindows#setupHttpsCertificate}
|
---|
86 | * @throws Exception if an error occurs
|
---|
87 | */
|
---|
88 | @Test
|
---|
89 | public void testSetupHttpsCertificate() throws Exception {
|
---|
90 | KeyStore ks = RemoteControlHttpsServer.loadJosmKeystore();
|
---|
91 | TrustedCertificateEntry trustedCert = new KeyStore.TrustedCertificateEntry(ks.getCertificate(ks.aliases().nextElement()));
|
---|
92 | if (Main.isPlatformWindows()) {
|
---|
93 | hook.setupHttpsCertificate(RemoteControlHttpsServer.ENTRY_ALIAS, trustedCert);
|
---|
94 | } else {
|
---|
95 | try {
|
---|
96 | hook.setupHttpsCertificate(RemoteControlHttpsServer.ENTRY_ALIAS, trustedCert);
|
---|
97 | fail("Expected KeyStoreException");
|
---|
98 | } catch (KeyStoreException e) {
|
---|
99 | Main.info(e.getMessage());
|
---|
100 | }
|
---|
101 | }
|
---|
102 | }
|
---|
103 |
|
---|
104 | /**
|
---|
105 | * Test method for {@code PlatformHookWindows#afterPrefStartupHook}
|
---|
106 | */
|
---|
107 | @Test
|
---|
108 | public void testAfterPrefStartupHook() {
|
---|
109 | hook.afterPrefStartupHook();
|
---|
110 | }
|
---|
111 |
|
---|
112 | /**
|
---|
113 | * Test method for {@code PlatformHookWindows#openUrl}
|
---|
114 | * @throws IOException if an error occurs
|
---|
115 | */
|
---|
116 | @Test
|
---|
117 | public void testOpenUrl() throws IOException {
|
---|
118 | if (Main.isPlatformWindows()) {
|
---|
119 | hook.openUrl(Main.getJOSMWebsite());
|
---|
120 | } else {
|
---|
121 | try {
|
---|
122 | hook.openUrl(Main.getJOSMWebsite());
|
---|
123 | fail("Expected IOException");
|
---|
124 | } catch (IOException e) {
|
---|
125 | Main.info(e.getMessage());
|
---|
126 | }
|
---|
127 | }
|
---|
128 | }
|
---|
129 |
|
---|
130 | /**
|
---|
131 | * Test method for {@code PlatformHookWindows#getAdditionalFonts}
|
---|
132 | */
|
---|
133 | @Test
|
---|
134 | public void testGetAdditionalFonts() {
|
---|
135 | assertFalse(hook.getAdditionalFonts().isEmpty());
|
---|
136 | }
|
---|
137 |
|
---|
138 | /**
|
---|
139 | * Test method for {@code PlatformHookWindows#getDefaultCacheDirectory}
|
---|
140 | */
|
---|
141 | @Test
|
---|
142 | public void testGetDefaultCacheDirectory() {
|
---|
143 | File cache = hook.getDefaultCacheDirectory();
|
---|
144 | assertNotNull(cache);
|
---|
145 | if (Main.isPlatformWindows()) {
|
---|
146 | assertTrue(cache.toString().contains(":"));
|
---|
147 | }
|
---|
148 | }
|
---|
149 |
|
---|
150 | /**
|
---|
151 | * Test method for {@code PlatformHookWindows#getDefaultPrefDirectory}
|
---|
152 | */
|
---|
153 | @Test
|
---|
154 | public void testGetDefaultPrefDirectory() {
|
---|
155 | File cache = hook.getDefaultPrefDirectory();
|
---|
156 | assertNotNull(cache);
|
---|
157 | if (Main.isPlatformWindows()) {
|
---|
158 | assertTrue(cache.toString().contains(":"));
|
---|
159 | }
|
---|
160 | }
|
---|
161 |
|
---|
162 | /**
|
---|
163 | * Test method for {@code PlatformHookWindows#getDefaultStyle}
|
---|
164 | */
|
---|
165 | @Test
|
---|
166 | public void testGetDefaultStyle() {
|
---|
167 | assertEquals("com.sun.java.swing.plaf.windows.WindowsLookAndFeel", hook.getDefaultStyle());
|
---|
168 | }
|
---|
169 |
|
---|
170 | /**
|
---|
171 | * Test method for {@code PlatformHookWindows#getInstalledFonts}
|
---|
172 | */
|
---|
173 | @Test
|
---|
174 | public void testGetInstalledFonts() {
|
---|
175 | Collection<String> fonts = hook.getInstalledFonts();
|
---|
176 | if (Main.isPlatformWindows()) {
|
---|
177 | assertFalse(fonts.isEmpty());
|
---|
178 | } else {
|
---|
179 | assertNull(fonts);
|
---|
180 | }
|
---|
181 | }
|
---|
182 |
|
---|
183 | /**
|
---|
184 | * Test method for {@code PlatformHookWindows#getOSDescription}
|
---|
185 | */
|
---|
186 | @Test
|
---|
187 | public void testGetOSDescription() {
|
---|
188 | String os = hook.getOSDescription();
|
---|
189 | if (Main.isPlatformWindows()) {
|
---|
190 | assertTrue(os.contains("Windows"));
|
---|
191 | } else {
|
---|
192 | assertFalse(os.contains("Windows"));
|
---|
193 | }
|
---|
194 | }
|
---|
195 |
|
---|
196 | /**
|
---|
197 | * Test method for {@code PlatformHookWindows#initSystemShortcuts}
|
---|
198 | */
|
---|
199 | @Test
|
---|
200 | public void testInitSystemShortcuts() {
|
---|
201 | hook.initSystemShortcuts();
|
---|
202 | }
|
---|
203 | }
|
---|