Skip to content
Permalink
Browse files
7902793: Fix IllegalMonitorStateException in JInternalFrameOperatorCl…
…oseTest

Reviewed-by: akolarkunnu
  • Loading branch information
shurymury committed Dec 15, 2020
1 parent 9d40d5c commit 94612e2e1d353abc838359bbc5f6a98042c738df
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 53 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2020, 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
@@ -734,14 +734,22 @@ public <R> R waitState(Waitable<R, Void> waitable) {
* defined by {@code "ComponentOperator.WaitStateTimeout"}
*/
public void waitStateOnQueue(final ComponentChooser state) {
waitState((comp) -> {
return (boolean) (queueTool.invokeSmoothly(
new QueueTool.QueueAction<Object>("checkComponent") {
@Override
public final Object launch() throws Exception {
return state.checkComponent(comp);
}
}));
waitState(new ComponentChooser() {
@Override
public boolean checkComponent(Component comp) {
return (boolean) (queueTool.invokeSmoothly(
new QueueTool.QueueAction<Object>("checkComponent") {
@Override
public final Object launch() throws Exception {
return state.checkComponent(comp);
}
}));
}

@Override
public String getDescription() {
return state.getDescription();
}
});
}

@@ -1,6 +1,6 @@
Manifest-version: 1.0
Main-Class: org.netbeans.jemmy.JemmyProperties
Jemmy-MajorVersion: 3.0
Jemmy-MinorVersion: 9.0
Jemmy-MinorVersion: 10.0
Jemmy-Build: @BUILD_NUMBER@

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2020, 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,27 +25,34 @@

package org.netbeans.jemmy.operators;

import static org.testng.Assert.fail;

import static java.util.Arrays.stream;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.UIManager;
import javax.swing.event.InternalFrameEvent;
import javax.swing.event.InternalFrameListener;

import org.netbeans.jemmy.JemmyProperties;
import org.netbeans.jemmy.LookAndFeelProvider;
import org.netbeans.jemmy.TimeoutExpiredException;

import static org.netbeans.jemmy.drivers.DriverManager.WINDOW_DRIVER_ID;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;

import org.netbeans.jemmy.drivers.DriverManager;
import org.netbeans.jemmy.drivers.WindowDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.beans.PropertyVetoException;

public class JInternalFrameOperatorCloseTest {

private JFrameOperator frameOper;

private JInternalFrameOperator internalFrameOper;
private WindowDriver oldDriver;

@BeforeMethod
private void setUp(Object[] args) throws Exception {
@@ -64,67 +71,66 @@ private void setUp(Object[] args) throws Exception {
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frameOper = new JFrameOperator();
internalFrameOper = new JInternalFrameOperator(frameOper);
internalFrameOper.setVerification(true);
}

@AfterMethod
protected void tearDown() throws Exception {
frameOper.setVisible(false);
frameOper.dispose();
}

@Test(dataProvider = "availableLookAndFeels", dataProviderClass = LookAndFeelProvider.class)
public void testClose(String lookAndFeel) throws Exception {
InternalFrameListener listener = new InternalFrameListener() {

//override windows driver for the operator to not do anything to close
oldDriver = DriverManager.getWindowDriver(JInternalFrameOperator.class);
DriverManager.setDriver(WINDOW_DRIVER_ID, new WindowDriver() {
@Override
public void internalFrameOpened(InternalFrameEvent e) {
public void activate(ComponentOperator oper) {
oldDriver.activate(oper);
}

@Override
public void internalFrameIconified(InternalFrameEvent e) {
public void requestClose(ComponentOperator oper) {
//do nothing here
}

@Override
public void internalFrameDeiconified(InternalFrameEvent e) {
public void requestCloseAndThenHide(ComponentOperator oper) {
//do nothing here
}

@Override
public void internalFrameDeactivated(InternalFrameEvent e) {
public void close(ComponentOperator oper) {
//do nothing here
}

@Override
public void internalFrameClosing(InternalFrameEvent e) {
try {
this.wait(80000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
public void move(ComponentOperator oper, int x, int y) {
oldDriver.move(oper, x, y);
}

@Override
public void internalFrameClosed(InternalFrameEvent e) {
public void resize(ComponentOperator oper, int width, int height) {
oldDriver.resize(oper, width, height);
}
}, JInternalFrameOperator.class);
internalFrameOper = new JInternalFrameOperator(frameOper);
internalFrameOper.setVerification(true);
}

@Override
public void internalFrameActivated(InternalFrameEvent e) {
}
};
@AfterMethod
protected void tearDown() throws Exception {
frameOper.setVisible(false);
frameOper.dispose();
DriverManager.setDriver(WINDOW_DRIVER_ID, oldDriver, JInternalFrameOperator.class);
}

// Making not to close the fame for 1 minute and expecting TimeoutExpiredException
// from waitClosed()
@Test(dataProvider = "availableLookAndFeels", dataProviderClass = LookAndFeelProvider.class)
public void testClose(String lookAndFeel) throws Exception {
try {
internalFrameOper.addInternalFrameListener(listener);
//trying to close the uncloseable frame
//expected to fail by timeout, hence decreasing timeout
internalFrameOper.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 5000);
internalFrameOper.close();
//that would mean that the exception is not thrown
fail();
} catch (TimeoutExpiredException e) {
} finally {
internalFrameOper.removeInternalFrameListener(listener);
//make sure the exception is coming from the right place
assertTrue(stream(e.getStackTrace()).anyMatch(ste ->
ste.getClassName().equals(JInternalFrameOperator.class.getName()) &&
ste.getMethodName().equals("waitClosed")));
System.out.println("This exception has been caught, as expected:");
e.printStackTrace(System.out);
}

// Really closing the frame
internalFrameOper.close();
}

}

0 comments on commit 94612e2

Please sign in to comment.