|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
|
21 | 21 | * questions.
|
22 | 22 | */
|
23 | 23 |
|
24 |
| -import java.awt.*; |
| 24 | +import java.awt.SystemTray; |
25 | 25 |
|
26 | 26 | /*
|
27 | 27 | * @test
|
|
30 | 30 | * a proper instance is returned in supported platforms and a proper
|
31 | 31 | * exception is thrown in unsupported platforms
|
32 | 32 | * @author Dmitriy Ermashov (dmitriy.ermashov@oracle.com)
|
| 33 | + * @requires (os.family != "linux") |
33 | 34 | * @run main/othervm -DSystemTraySupport=TRUE SystemTrayInstanceTest
|
34 | 35 | */
|
35 | 36 |
|
| 37 | +/* |
| 38 | + * @test |
| 39 | + * @key headful |
| 40 | + * @requires (os.family == "linux") |
| 41 | + * @run main/othervm -DSystemTraySupport=MAYBE SystemTrayInstanceTest |
| 42 | + */ |
| 43 | + |
36 | 44 | public class SystemTrayInstanceTest {
|
37 | 45 |
|
38 |
| - private static boolean supported = false; |
| 46 | + private static boolean shouldSupport = false; |
39 | 47 |
|
40 | 48 | public static void main(String[] args) throws Exception {
|
41 | 49 | String sysTraySupport = System.getProperty("SystemTraySupport");
|
42 | 50 | if (sysTraySupport == null)
|
43 | 51 | throw new RuntimeException("SystemTray support status unknown!");
|
44 | 52 |
|
45 | 53 | if ("TRUE".equals(sysTraySupport)) {
|
46 |
| - System.out.println("System tray is supported on the platform under test"); |
47 |
| - supported = true; |
| 54 | + System.out.println("System tray should be supported on this platform."); |
| 55 | + shouldSupport = true; |
48 | 56 | }
|
49 | 57 |
|
50 | 58 | new SystemTrayInstanceTest().doTest();
|
51 | 59 | }
|
52 | 60 |
|
53 |
| - private void doTest() throws Exception { |
54 |
| - boolean flag = SystemTray.isSupported(); |
55 |
| - if (supported != flag) |
56 |
| - throw new RuntimeException("FAIL: isSupported did not return the correct value"+ |
57 |
| - (supported ? |
58 |
| - "SystemTray is supported on the platform under test" : |
59 |
| - "SystemTray is not supported on the platform under test") + |
60 |
| - "SystemTray.isSupported() method returned " + flag); |
| 61 | + private void doTest() { |
| 62 | + boolean systemSupported = SystemTray.isSupported(); |
| 63 | + if (shouldSupport && !systemSupported) { |
| 64 | + throw new RuntimeException( |
| 65 | + "FAIL: SystemTray is not supported on the platform under test, while it should." |
| 66 | + ); |
| 67 | + } |
61 | 68 |
|
62 |
| - if (supported) { |
| 69 | + if (shouldSupport || systemSupported) { |
63 | 70 | SystemTray tray = SystemTray.getSystemTray();
|
| 71 | + System.out.println("SystemTray instance received"); |
64 | 72 | } else {
|
| 73 | + boolean exceptionThrown = false; |
65 | 74 | try {
|
66 | 75 | SystemTray tray = SystemTray.getSystemTray();
|
67 | 76 | } catch (UnsupportedOperationException uoe) {
|
| 77 | + exceptionThrown = true; |
68 | 78 | System.out.println("UnsupportedOperationException thrown correctly");
|
69 | 79 | }
|
| 80 | + if (!exceptionThrown) { |
| 81 | + throw new RuntimeException("UnsupportedOperationException is not thrown"); |
| 82 | + } |
70 | 83 | }
|
71 | 84 | }
|
72 | 85 | }
|
0 commit comments