From f8a119b5397572ca23d59ac4e23d471cfb5de0c3 Mon Sep 17 00:00:00 2001 From: Goetz Lindenmaier <goetz@openjdk.org> Date: Mon, 11 Nov 2024 08:59:36 +0000 Subject: [PATCH] 8327924: Simplify TrayIconScalingTest.java Backport-of: 1496b5de9004c6a9e43ead5f6e9e88362028a7cc --- .../awt/TrayIcon/TrayIconScalingTest.java | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/test/jdk/java/awt/TrayIcon/TrayIconScalingTest.java b/test/jdk/java/awt/TrayIcon/TrayIconScalingTest.java index 075137ff091..3fa4b8345b1 100644 --- a/test/jdk/java/awt/TrayIcon/TrayIconScalingTest.java +++ b/test/jdk/java/awt/TrayIcon/TrayIconScalingTest.java @@ -85,28 +85,27 @@ public class TrayIconScalingTest { System.out.println("SystemTray is not supported"); return; } - PassFailJFrame passFailJFrame = PassFailJFrame.builder() - .title("TrayIcon Test Instructions") - .instructions(INSTRUCTIONS) - .testTimeOut(8) - .rows(25) - .columns(70) - .screenCapture() - .build(); - createAndShowGUI(); - // does not have a test window, - // hence only the instruction frame is positioned - PassFailJFrame.positionTestWindow(null, - PassFailJFrame.Position.HORIZONTAL); + createAndShowTrayIcon(); + try { - passFailJFrame.awaitAndCheck(); + PassFailJFrame.builder() + .title("TrayIcon Test Instructions") + .instructions(INSTRUCTIONS) + .testTimeOut(8) + .rows(25) + .columns(70) + .screenCapture() + .build() + .awaitAndCheck(); } finally { - tray.remove(icon); + if (tray != null) { + tray.remove(icon); + } } } - private static void createAndShowGUI() { + private static void createAndShowTrayIcon() { ArrayList<Image> imageList = new ArrayList<>(); for (int size = 16; size <= 48; size += 4) { imageList.add(createIcon(size)); @@ -120,7 +119,7 @@ public class TrayIconScalingTest { try { tray.add(icon); } catch (AWTException e) { - throw new RuntimeException("Error while adding icon to system tray"); + throw new RuntimeException("Error while adding icon to system tray", e); } } -- GitLab