Skip to content
Permalink
Browse files
8168388: GetMousePositionTest fails with the message "Mouse position …
…should not be null"

Reviewed-by: psadhukhan, serb
  • Loading branch information
Alexander Zuev committed Oct 21, 2021
1 parent 09f5235 commit 0c3eaea11c83b3ee63d80de85d58a1cb6f870fd3
Showing 2 changed files with 21 additions and 24 deletions.
@@ -183,7 +183,6 @@ java/awt/Mixing/AWT_Mixing/JToggleButtonInGlassPaneOverlapping.java 8158801 wind
java/awt/Mixing/AWT_Mixing/JToggleButtonOverlapping.java 8158801 windows-all
java/awt/Mixing/MixingOnDialog.java 8225777 linux-all
java/awt/Mixing/NonOpaqueInternalFrame.java 7124549 macosx-all
java/awt/Mouse/GetMousePositionTest/GetMousePositionWithOverlay.java 8168388 linux-all
java/awt/Focus/ActualFocusedWindowTest/ActualFocusedWindowRetaining.java 6829264 generic-all
java/awt/datatransfer/DragImage/MultiResolutionDragImageTest.java 8080982 generic-all
java/awt/datatransfer/SystemFlavorMap/AddFlavorTest.java 8079268 linux-all
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2021, 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
@@ -25,6 +25,7 @@
import java.awt.Point;
import java.awt.Robot;
import java.awt.Rectangle;
import javax.swing.SwingUtilities;

/*
* @test
@@ -42,23 +43,21 @@ public class GetMousePositionWithOverlay {

public static void main(String[] args) throws Throwable {
robot = new Robot();
robot.setAutoDelay(100);

try{
constructTestUI();
} catch (Exception e) {
try {
SwingUtilities.invokeAndWait(GetMousePositionWithOverlay::constructTestUI);
doTest();
} finally {
dispose();
throw new RuntimeException("Unexpected Exception!");
}

robot.waitForIdle();

doTest();
dispose();
}

private static void doTest() {

frontFrame.toFront();
private static void doTest() throws Exception {
SwingUtilities.invokeAndWait(() -> frontFrame.toFront());
robot.waitForIdle();

Rectangle bounds = new Rectangle(frontFrame.getLocationOnScreen(), frontFrame.getSize());
@@ -67,45 +66,44 @@ private static void doTest() {

Point pos = backFrame.getMousePosition();
if (pos != null) {
dispose();
throw new RuntimeException("Test failed. Mouse position should be null but was " + pos);
}

pos = frontFrame.getMousePosition();
if (pos == null) {
dispose();
throw new RuntimeException("Test failed. Mouse position should not be null");
}

robot.mouseMove(189, 189);
robot.mouseMove(bounds.x + bounds.width + 5, bounds.y + bounds.height + 5);
robot.waitForIdle();

pos = backFrame.getMousePosition();
if (pos == null) {
dispose();
throw new RuntimeException("Test failed. Mouse position should not be null");
}

}

private static void dispose() {

if (backFrame != null) {
backFrame.dispose();
}
private static void dispose() throws Exception {
SwingUtilities.invokeAndWait(() -> {
if (backFrame != null) {
backFrame.dispose();
}

if (frontFrame != null) {
frontFrame.dispose();
}
if (frontFrame != null) {
frontFrame.dispose();
}
});
}

private static void constructTestUI() {
backFrame = new Frame();
backFrame.setUndecorated(true);
backFrame.setBounds(100, 100, 100, 100);
backFrame.setResizable(false);
backFrame.setVisible(true);

frontFrame = new Frame();
frontFrame.setUndecorated(true);
frontFrame.setBounds(120, 120, 60, 60);
frontFrame.setResizable(false);
frontFrame.setVisible(true);

1 comment on commit 0c3eaea

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 0c3eaea Oct 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.