source: josm/trunk/test/unit/org/openstreetmap/josm/tools/PlatformHookWindowsTest.java@ 11241

Last change on this file since 11241 was 10378, checked in by Don-vip, 8 years ago

Checkstyle 6.19: enable SingleSpaceSeparator and fix violations

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