Skip to content

Commit 94612e2

Browse files
committed
7902793: Fix IllegalMonitorStateException in JInternalFrameOperatorCloseTest
Reviewed-by: akolarkunnu
1 parent 9d40d5c commit 94612e2

File tree

3 files changed

+67
-53
lines changed

3 files changed

+67
-53
lines changed

src/org/netbeans/jemmy/operators/Operator.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2020, 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
@@ -734,14 +734,22 @@ public <R> R waitState(Waitable<R, Void> waitable) {
734734
* defined by {@code "ComponentOperator.WaitStateTimeout"}
735735
*/
736736
public void waitStateOnQueue(final ComponentChooser state) {
737-
waitState((comp) -> {
738-
return (boolean) (queueTool.invokeSmoothly(
739-
new QueueTool.QueueAction<Object>("checkComponent") {
740-
@Override
741-
public final Object launch() throws Exception {
742-
return state.checkComponent(comp);
743-
}
744-
}));
737+
waitState(new ComponentChooser() {
738+
@Override
739+
public boolean checkComponent(Component comp) {
740+
return (boolean) (queueTool.invokeSmoothly(
741+
new QueueTool.QueueAction<Object>("checkComponent") {
742+
@Override
743+
public final Object launch() throws Exception {
744+
return state.checkComponent(comp);
745+
}
746+
}));
747+
}
748+
749+
@Override
750+
public String getDescription() {
751+
return state.getDescription();
752+
}
745753
});
746754
}
747755

src/org/netbeans/jemmy/version_info

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Manifest-version: 1.0
22
Main-Class: org.netbeans.jemmy.JemmyProperties
33
Jemmy-MajorVersion: 3.0
4-
Jemmy-MinorVersion: 9.0
4+
Jemmy-MinorVersion: 10.0
55
Jemmy-Build: @BUILD_NUMBER@
66

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2020, 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
@@ -25,27 +25,34 @@
2525

2626
package org.netbeans.jemmy.operators;
2727

28-
import static org.testng.Assert.fail;
29-
28+
import static java.util.Arrays.stream;
3029
import javax.swing.JDesktopPane;
3130
import javax.swing.JFrame;
3231
import javax.swing.JInternalFrame;
3332
import javax.swing.UIManager;
34-
import javax.swing.event.InternalFrameEvent;
35-
import javax.swing.event.InternalFrameListener;
3633

3734
import org.netbeans.jemmy.JemmyProperties;
3835
import org.netbeans.jemmy.LookAndFeelProvider;
3936
import org.netbeans.jemmy.TimeoutExpiredException;
37+
38+
import static org.netbeans.jemmy.drivers.DriverManager.WINDOW_DRIVER_ID;
39+
import static org.testng.Assert.assertTrue;
40+
import static org.testng.Assert.fail;
41+
42+
import org.netbeans.jemmy.drivers.DriverManager;
43+
import org.netbeans.jemmy.drivers.WindowDriver;
4044
import org.testng.annotations.AfterMethod;
4145
import org.testng.annotations.BeforeMethod;
4246
import org.testng.annotations.Test;
4347

48+
import java.beans.PropertyVetoException;
49+
4450
public class JInternalFrameOperatorCloseTest {
4551

4652
private JFrameOperator frameOper;
4753

4854
private JInternalFrameOperator internalFrameOper;
55+
private WindowDriver oldDriver;
4956

5057
@BeforeMethod
5158
private void setUp(Object[] args) throws Exception {
@@ -64,67 +71,66 @@ private void setUp(Object[] args) throws Exception {
6471
frame.setLocationRelativeTo(null);
6572
frame.setVisible(true);
6673
frameOper = new JFrameOperator();
67-
internalFrameOper = new JInternalFrameOperator(frameOper);
68-
internalFrameOper.setVerification(true);
69-
}
70-
71-
@AfterMethod
72-
protected void tearDown() throws Exception {
73-
frameOper.setVisible(false);
74-
frameOper.dispose();
75-
}
76-
77-
@Test(dataProvider = "availableLookAndFeels", dataProviderClass = LookAndFeelProvider.class)
78-
public void testClose(String lookAndFeel) throws Exception {
79-
InternalFrameListener listener = new InternalFrameListener() {
80-
74+
//override windows driver for the operator to not do anything to close
75+
oldDriver = DriverManager.getWindowDriver(JInternalFrameOperator.class);
76+
DriverManager.setDriver(WINDOW_DRIVER_ID, new WindowDriver() {
8177
@Override
82-
public void internalFrameOpened(InternalFrameEvent e) {
78+
public void activate(ComponentOperator oper) {
79+
oldDriver.activate(oper);
8380
}
8481

8582
@Override
86-
public void internalFrameIconified(InternalFrameEvent e) {
83+
public void requestClose(ComponentOperator oper) {
84+
//do nothing here
8785
}
8886

8987
@Override
90-
public void internalFrameDeiconified(InternalFrameEvent e) {
88+
public void requestCloseAndThenHide(ComponentOperator oper) {
89+
//do nothing here
9190
}
9291

9392
@Override
94-
public void internalFrameDeactivated(InternalFrameEvent e) {
93+
public void close(ComponentOperator oper) {
94+
//do nothing here
9595
}
9696

9797
@Override
98-
public void internalFrameClosing(InternalFrameEvent e) {
99-
try {
100-
this.wait(80000);
101-
} catch (InterruptedException e1) {
102-
e1.printStackTrace();
103-
}
98+
public void move(ComponentOperator oper, int x, int y) {
99+
oldDriver.move(oper, x, y);
104100
}
105101

106102
@Override
107-
public void internalFrameClosed(InternalFrameEvent e) {
103+
public void resize(ComponentOperator oper, int width, int height) {
104+
oldDriver.resize(oper, width, height);
108105
}
106+
}, JInternalFrameOperator.class);
107+
internalFrameOper = new JInternalFrameOperator(frameOper);
108+
internalFrameOper.setVerification(true);
109+
}
109110

110-
@Override
111-
public void internalFrameActivated(InternalFrameEvent e) {
112-
}
113-
};
111+
@AfterMethod
112+
protected void tearDown() throws Exception {
113+
frameOper.setVisible(false);
114+
frameOper.dispose();
115+
DriverManager.setDriver(WINDOW_DRIVER_ID, oldDriver, JInternalFrameOperator.class);
116+
}
114117

115-
// Making not to close the fame for 1 minute and expecting TimeoutExpiredException
116-
// from waitClosed()
118+
@Test(dataProvider = "availableLookAndFeels", dataProviderClass = LookAndFeelProvider.class)
119+
public void testClose(String lookAndFeel) throws Exception {
117120
try {
118-
internalFrameOper.addInternalFrameListener(listener);
121+
//trying to close the uncloseable frame
122+
//expected to fail by timeout, hence decreasing timeout
123+
internalFrameOper.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 5000);
119124
internalFrameOper.close();
125+
//that would mean that the exception is not thrown
120126
fail();
121127
} catch (TimeoutExpiredException e) {
122-
} finally {
123-
internalFrameOper.removeInternalFrameListener(listener);
128+
//make sure the exception is coming from the right place
129+
assertTrue(stream(e.getStackTrace()).anyMatch(ste ->
130+
ste.getClassName().equals(JInternalFrameOperator.class.getName()) &&
131+
ste.getMethodName().equals("waitClosed")));
132+
System.out.println("This exception has been caught, as expected:");
133+
e.printStackTrace(System.out);
124134
}
125-
126-
// Really closing the frame
127-
internalFrameOper.close();
128135
}
129-
130136
}

0 commit comments

Comments
 (0)