Skip to content

Commit 6201dcc

Browse files
Amos ShiGoeLin
Amos Shi
authored andcommitted
8193543: Regression automated test '/open/test/jdk/java/awt/TrayIcon/SystemTrayInstance/SystemTrayInstanceTest.java' fails
Reviewed-by: mdoerr Backport-of: 08024d9583d02398d986db0e9b32fe19a2b8fec2
1 parent 98cbef8 commit 6201dcc

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

test/jdk/java/awt/TrayIcon/SystemTrayInstance/SystemTrayInstanceTest.java

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
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.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -21,7 +21,7 @@
2121
* questions.
2222
*/
2323

24-
import java.awt.*;
24+
import java.awt.SystemTray;
2525

2626
/*
2727
* @test
@@ -30,43 +30,56 @@
3030
* a proper instance is returned in supported platforms and a proper
3131
* exception is thrown in unsupported platforms
3232
* @author Dmitriy Ermashov (dmitriy.ermashov@oracle.com)
33+
* @requires (os.family != "linux")
3334
* @run main/othervm -DSystemTraySupport=TRUE SystemTrayInstanceTest
3435
*/
3536

37+
/*
38+
* @test
39+
* @key headful
40+
* @requires (os.family == "linux")
41+
* @run main/othervm -DSystemTraySupport=MAYBE SystemTrayInstanceTest
42+
*/
43+
3644
public class SystemTrayInstanceTest {
3745

38-
private static boolean supported = false;
46+
private static boolean shouldSupport = false;
3947

4048
public static void main(String[] args) throws Exception {
4149
String sysTraySupport = System.getProperty("SystemTraySupport");
4250
if (sysTraySupport == null)
4351
throw new RuntimeException("SystemTray support status unknown!");
4452

4553
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;
4856
}
4957

5058
new SystemTrayInstanceTest().doTest();
5159
}
5260

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+
}
6168

62-
if (supported) {
69+
if (shouldSupport || systemSupported) {
6370
SystemTray tray = SystemTray.getSystemTray();
71+
System.out.println("SystemTray instance received");
6472
} else {
73+
boolean exceptionThrown = false;
6574
try {
6675
SystemTray tray = SystemTray.getSystemTray();
6776
} catch (UnsupportedOperationException uoe) {
77+
exceptionThrown = true;
6878
System.out.println("UnsupportedOperationException thrown correctly");
6979
}
80+
if (!exceptionThrown) {
81+
throw new RuntimeException("UnsupportedOperationException is not thrown");
82+
}
7083
}
7184
}
7285
}

0 commit comments

Comments
 (0)