source: josm/trunk/test/unit/org/openstreetmap/josm/tools/PlatformHookOsxTest.java@ 14138

Last change on this file since 14138 was 14138, checked in by Don-vip, 6 years ago

see #15229 - deprecate Main.platform and related methods - new class PlatformManager

  • Property svn:eol-style set to native
File size: 3.4 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.assertTrue;
8import static org.junit.Assert.fail;
9
10import java.io.File;
11import java.io.IOException;
12
13import org.junit.BeforeClass;
14import org.junit.Test;
15import org.openstreetmap.josm.JOSMFixture;
16import org.openstreetmap.josm.spi.preferences.Config;
17
18/**
19 * Unit tests of {@link PlatformHookOsx} class.
20 */
21public class PlatformHookOsxTest {
22
23 static PlatformHookOsx hook;
24
25 /**
26 * Setup test.
27 */
28 @BeforeClass
29 public static void setUp() {
30 JOSMFixture.createUnitTestFixture().init();
31 hook = new PlatformHookOsx();
32 }
33
34 /**
35 * Test method for {@code PlatformHookOsx#startupHook}
36 */
37 @Test
38 public void testStartupHook() {
39 hook.startupHook((a, b, c, d) -> System.out.println("callback"));
40 }
41
42 /**
43 * Test method for {@code PlatformHookOsx#setupHttpsCertificate}
44 * @throws Exception if an error occurs
45 */
46 @Test
47 public void testSetupHttpsCertificate() throws Exception {
48 assertFalse(hook.setupHttpsCertificate(null, null));
49 }
50
51 /**
52 * Test method for {@code PlatformHookOsx#afterPrefStartupHook}
53 */
54 @Test
55 public void testAfterPrefStartupHook() {
56 hook.afterPrefStartupHook();
57 }
58
59 /**
60 * Test method for {@code PlatformHookOsx#openUrl}
61 * @throws IOException if an error occurs
62 */
63 @Test
64 public void testOpenUrl() throws IOException {
65 if (!PlatformManager.isPlatformWindows()) {
66 hook.openUrl(Config.getUrls().getJOSMWebsite());
67 } else {
68 try {
69 hook.openUrl(Config.getUrls().getJOSMWebsite());
70 fail("Expected IOException");
71 } catch (IOException e) {
72 Logging.info(e.getMessage());
73 }
74 }
75 }
76
77 /**
78 * Test method for {@code PlatformHookOsx#getDefaultCacheDirectory}
79 */
80 @Test
81 public void testGetDefaultCacheDirectory() {
82 File cache = hook.getDefaultCacheDirectory();
83 assertNotNull(cache);
84 if (PlatformManager.isPlatformOsx()) {
85 assertTrue(cache.toString().contains("/Library/"));
86 }
87 }
88
89 /**
90 * Test method for {@code PlatformHookOsx#getDefaultPrefDirectory}
91 */
92 @Test
93 public void testGetDefaultPrefDirectory() {
94 File cache = hook.getDefaultPrefDirectory();
95 assertNotNull(cache);
96 if (PlatformManager.isPlatformOsx()) {
97 assertTrue(cache.toString().contains("/Library/"));
98 }
99 }
100
101 /**
102 * Test method for {@code PlatformHookOsx#getDefaultStyle}
103 */
104 @Test
105 public void testGetDefaultStyle() {
106 assertEquals("com.apple.laf.AquaLookAndFeel", hook.getDefaultStyle());
107 }
108
109 /**
110 * Test method for {@code PlatformHookOsx#getOSDescription}
111 */
112 @Test
113 public void testGetOSDescription() {
114 String os = hook.getOSDescription();
115 if (PlatformManager.isPlatformOsx()) {
116 assertTrue(os.contains("Mac"));
117 } else {
118 assertFalse(os.contains("Mac"));
119 }
120 }
121
122 /**
123 * Test method for {@code PlatformHookOsx#initSystemShortcuts}
124 */
125 @Test
126 public void testInitSystemShortcuts() {
127 hook.initSystemShortcuts();
128 }
129}
Note: See TracBrowser for help on using the repository browser.