1
1
/*
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.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
25
25
26
26
package org .netbeans .jemmy .operators ;
27
27
28
- import static org .testng .Assert .fail ;
29
-
28
+ import static java .util .Arrays .stream ;
30
29
import javax .swing .JDesktopPane ;
31
30
import javax .swing .JFrame ;
32
31
import javax .swing .JInternalFrame ;
33
32
import javax .swing .UIManager ;
34
- import javax .swing .event .InternalFrameEvent ;
35
- import javax .swing .event .InternalFrameListener ;
36
33
37
34
import org .netbeans .jemmy .JemmyProperties ;
38
35
import org .netbeans .jemmy .LookAndFeelProvider ;
39
36
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 ;
40
44
import org .testng .annotations .AfterMethod ;
41
45
import org .testng .annotations .BeforeMethod ;
42
46
import org .testng .annotations .Test ;
43
47
48
+ import java .beans .PropertyVetoException ;
49
+
44
50
public class JInternalFrameOperatorCloseTest {
45
51
46
52
private JFrameOperator frameOper ;
47
53
48
54
private JInternalFrameOperator internalFrameOper ;
55
+ private WindowDriver oldDriver ;
49
56
50
57
@ BeforeMethod
51
58
private void setUp (Object [] args ) throws Exception {
@@ -64,67 +71,66 @@ private void setUp(Object[] args) throws Exception {
64
71
frame .setLocationRelativeTo (null );
65
72
frame .setVisible (true );
66
73
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 () {
81
77
@ Override
82
- public void internalFrameOpened (InternalFrameEvent e ) {
78
+ public void activate (ComponentOperator oper ) {
79
+ oldDriver .activate (oper );
83
80
}
84
81
85
82
@ Override
86
- public void internalFrameIconified (InternalFrameEvent e ) {
83
+ public void requestClose (ComponentOperator oper ) {
84
+ //do nothing here
87
85
}
88
86
89
87
@ Override
90
- public void internalFrameDeiconified (InternalFrameEvent e ) {
88
+ public void requestCloseAndThenHide (ComponentOperator oper ) {
89
+ //do nothing here
91
90
}
92
91
93
92
@ Override
94
- public void internalFrameDeactivated (InternalFrameEvent e ) {
93
+ public void close (ComponentOperator oper ) {
94
+ //do nothing here
95
95
}
96
96
97
97
@ 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 );
104
100
}
105
101
106
102
@ Override
107
- public void internalFrameClosed (InternalFrameEvent e ) {
103
+ public void resize (ComponentOperator oper , int width , int height ) {
104
+ oldDriver .resize (oper , width , height );
108
105
}
106
+ }, JInternalFrameOperator .class );
107
+ internalFrameOper = new JInternalFrameOperator (frameOper );
108
+ internalFrameOper .setVerification (true );
109
+ }
109
110
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
+ }
114
117
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 {
117
120
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 );
119
124
internalFrameOper .close ();
125
+ //that would mean that the exception is not thrown
120
126
fail ();
121
127
} 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 );
124
134
}
125
-
126
- // Really closing the frame
127
- internalFrameOper .close ();
128
135
}
129
-
130
136
}
0 commit comments