8234184: [TESTBUG] java/awt/Mouse/EnterExitEvents/ModalDialogEnterExitEventsTest.java fails in Windows
authorjdv
Fri, 15 Nov 2019 16:58:07 +0530
changeset 59191 1e8bbeb86204
parent 59190 88ddd6943a06
child 59192 a56b7a304bac
8234184: [TESTBUG] java/awt/Mouse/EnterExitEvents/ModalDialogEnterExitEventsTest.java fails in Windows Reviewed-by: psadhukhan
test/jdk/java/awt/Mouse/EnterExitEvents/ModalDialogEnterExitEventsTest.java
--- a/test/jdk/java/awt/Mouse/EnterExitEvents/ModalDialogEnterExitEventsTest.java	Fri Nov 15 09:27:50 2019 +0100
+++ b/test/jdk/java/awt/Mouse/EnterExitEvents/ModalDialogEnterExitEventsTest.java	Fri Nov 15 16:58:07 2019 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -54,36 +54,47 @@
     private static volatile AtomicInteger mouseExitCount = new AtomicInteger();
 
     private static JFrame frame;
+    private static JDialog dialog;
     private static JButton openButton;
     private static JButton closeButton;
 
-    public static void main(String[] args) {
-        Robot robot = Util.createRobot();
+    public static void main(String[] args) throws Exception {
+        try {
+            Robot robot = Util.createRobot();
 
-        SwingUtilities.invokeLater(new Runnable() {
-            @Override
-            public void run() {
-                createAndShowGUI();
-            }
-        });
-        Util.waitForIdle(robot);
+            SwingUtilities.invokeAndWait(new Runnable() {
+                @Override
+                public void run() {
+                    createAndShowGUI();
+                }
+            });
+            Util.waitForIdle(robot);
 
-        Util.clickOnComp(frame, robot, 500);
-        Util.waitForIdle(robot);
+            Util.clickOnComp(frame, robot, 500);
+            Util.waitForIdle(robot);
+
+            mouseEnterCount.set(0);
+            mouseExitCount.set(0);
 
-        mouseEnterCount.set(0);
-        mouseExitCount.set(0);
+            Util.clickOnComp(openButton, robot, 500);
+            Util.waitForIdle(robot);
+            Util.waitTillShown(dialog);
+            if (mouseExitCount.get() != 1) {
+                throw new RuntimeException("Test FAILED. Wrong number of "
+                    + "MouseExited events = " + mouseExitCount.get());
+            }
 
-        Util.clickOnComp(openButton, robot, 500);
-        Util.waitForIdle(robot);
-        if (mouseExitCount.get() != 1) {
-            throw new RuntimeException("Test FAILED. Wrong number of MouseExited events = " + mouseExitCount.get());
-        }
-
-        Util.clickOnComp(closeButton, robot, 500);
-        Util.waitForIdle(robot);
-        if (mouseEnterCount.get() != 1) {
-            throw new RuntimeException("Test FAILED. Wrong number of MouseEntered events = "+ mouseEnterCount.get());
+            Util.clickOnComp(closeButton, robot, 500);
+            Util.waitForIdle(robot);
+            robot.delay(200);
+            if (mouseEnterCount.get() != 1) {
+                throw new RuntimeException("Test FAILED. Wrong number of "
+                    + "MouseEntered events = "+ mouseEnterCount.get());
+            }
+        } finally {
+            if (frame != null) {
+                SwingUtilities.invokeAndWait(() -> frame.dispose());
+            }
         }
     }
 
@@ -106,7 +117,7 @@
         openButton.addActionListener(new ActionListener() {
             @Override
             public void actionPerformed(ActionEvent e) {
-                JDialog dialog = new JDialog(frame, "Modal Dialog", true);
+                dialog = new JDialog(frame, "Modal Dialog", true);
                 dialog.setLayout(new FlowLayout());
                 closeButton = new JButton("Close");
                 closeButton.addActionListener(new ActionListener() {