12
12
13
13
package org .eclipse .ui .tests .e4 ;
14
14
15
+ import static org .junit .Assert .assertFalse ;
16
+ import static org .junit .Assert .assertNotNull ;
17
+ import static org .junit .Assert .assertNull ;
18
+ import static org .junit .Assert .assertTrue ;
19
+ import static org .junit .Assert .fail ;
20
+
15
21
import java .util .Collections ;
16
22
import java .util .List ;
17
23
import java .util .Optional ;
44
50
import org .eclipse .ui .PartInitException ;
45
51
import org .eclipse .ui .internal .CloseAllHandler ;
46
52
import org .eclipse .ui .internal .Workbench ;
47
- import org .junit .Assert ;
48
53
import org .junit .Before ;
49
54
import org .junit .Test ;
50
55
import org .osgi .framework .BundleContext ;
@@ -102,12 +107,12 @@ public void testCloseMixedEditorTypes() {
102
107
103
108
Command closeAllCommand = commandService .getCommand (CLOSE_ALL_EDITORS_COMMAND_ID );
104
109
final ParameterizedCommand parameterizedCommand = ParameterizedCommand .generateCommand (closeAllCommand ,
105
- Collections .EMPTY_MAP );
110
+ Collections .emptyMap () );
106
111
107
112
// verify the close all editors handler enabledment is false (no editors are
108
113
// open yet!)
109
114
boolean canExecute = handlerService .canExecute (parameterizedCommand );
110
- Assert . assertFalse (canExecute );
115
+ assertFalse (canExecute );
111
116
112
117
// scenario 1: e4 part descriptor contribution
113
118
MPartDescriptor partDescriptor = createDummyPartDescriptor ();
@@ -119,46 +124,46 @@ public void testCloseMixedEditorTypes() {
119
124
// verify the close all handler is enabled now (since dummy editor has been
120
125
// opened)
121
126
canExecute = handlerService .canExecute (parameterizedCommand );
122
- Assert . assertTrue (canExecute );
127
+ assertTrue (canExecute );
123
128
124
129
// close all editors (dummy editor should close!)
125
130
dummyPart = partService .findPart (DUMMY_E4_PART_ID );
126
- Assert . assertNotNull (dummyPart );
131
+ assertNotNull (dummyPart );
127
132
handlerService .executeHandler (parameterizedCommand );
128
133
dummyPart = partService .findPart (DUMMY_E4_PART_ID );
129
- Assert . assertNull (dummyPart );
134
+ assertNull (dummyPart );
130
135
131
136
// verify the close all handler is *not* enabled now (since dummy editor has
132
137
// been closed)
133
138
canExecute = handlerService .canExecute (parameterizedCommand );
134
- Assert . assertFalse (canExecute );
139
+ assertFalse (canExecute );
135
140
136
141
// scenario 2: open a compatibility layer editor
137
142
IFileEditorInput input = new DummyFileEditorInput ();
138
143
Object activeWindow = applicationContext .getActive (ISources .ACTIVE_WORKBENCH_WINDOW_NAME );
139
- Assert . assertTrue ("Active workbench window not found." , activeWindow instanceof IWorkbenchWindow );
144
+ assertTrue ("Active workbench window not found." , activeWindow instanceof IWorkbenchWindow );
140
145
IWorkbenchWindow window = (IWorkbenchWindow ) activeWindow ;
141
146
try {
142
147
window .getActivePage ().openEditor (input , TEST_COMPATIBILITY_LAYER_EDITOR_ID );
143
148
} catch (PartInitException e ) {
144
- Assert . fail ("Test Compatibility Editor could not be opened. Further testing cannot complete." );
149
+ fail ("Test Compatibility Editor could not be opened. Further testing cannot complete." );
145
150
}
146
151
147
152
// verify the close all handler is enabled now (since a dummy compatibility
148
153
// layer editor has been opened)
149
154
canExecute = handlerService .canExecute (parameterizedCommand );
150
- Assert . assertTrue (canExecute );
155
+ assertTrue (canExecute );
151
156
152
157
IEditorPart compatEditor = window .getActivePage ().findEditor (input );
153
- Assert . assertNotNull (compatEditor );
158
+ assertNotNull (compatEditor );
154
159
handlerService .executeHandler (parameterizedCommand );
155
160
compatEditor = window .getActivePage ().findEditor (input );
156
- Assert . assertNull (compatEditor );
161
+ assertNull (compatEditor );
157
162
158
163
// verify the close all handler is *not* enabled now (since compatibility layer
159
164
// editor has been closed)
160
165
canExecute = handlerService .canExecute (parameterizedCommand );
161
- Assert . assertFalse (canExecute );
166
+ assertFalse (canExecute );
162
167
163
168
// scenario 3:
164
169
// finally: re-open both the compatibility layer editor *and* the dummy e4 part
@@ -168,33 +173,33 @@ public void testCloseMixedEditorTypes() {
168
173
try {
169
174
window .getActivePage ().openEditor (input , TEST_COMPATIBILITY_LAYER_EDITOR_ID );
170
175
} catch (PartInitException e ) {
171
- Assert . fail ("Test Compatibility Editor could not be opened. Further testing cannot complete." );
176
+ fail ("Test Compatibility Editor could not be opened. Further testing cannot complete." );
172
177
}
173
178
compatEditor = window .getActivePage ().findEditor (input );
174
- Assert . assertNotNull (compatEditor );
179
+ assertNotNull (compatEditor );
175
180
dummyPart = partService .findPart (DUMMY_E4_PART_ID );
176
- Assert . assertNotNull (dummyPart );
181
+ assertNotNull (dummyPart );
177
182
178
183
canExecute = handlerService .canExecute (parameterizedCommand );
179
- Assert . assertTrue (canExecute );
184
+ assertTrue (canExecute );
180
185
181
186
// close all editors
182
187
handlerService .executeHandler (parameterizedCommand );
183
188
canExecute = handlerService .canExecute (parameterizedCommand );
184
- Assert . assertFalse (canExecute );
189
+ assertFalse (canExecute );
185
190
186
191
// verify they are all closed
187
192
compatEditor = window .getActivePage ().findEditor (input );
188
- Assert . assertNull (compatEditor );
193
+ assertNull (compatEditor );
189
194
dummyPart = partService .findPart (DUMMY_E4_PART_ID );
190
- Assert . assertNull (dummyPart );
195
+ assertNull (dummyPart );
191
196
}
192
197
193
198
private MPart createAndOpenE4Part (MPartDescriptor partDescriptor ) {
194
199
Optional <MPartStack > primaryPartStack = findPrimaryConfiguationAreaPartStack (application , modelService );
195
200
196
201
if (primaryPartStack .isEmpty ()) {
197
- Assert . fail ("Test cannot proceed as the primary part stack could not be found in the application." );
202
+ fail ("Test cannot proceed as the primary part stack could not be found in the application." );
198
203
}
199
204
200
205
MPart dummyPart = partService .createPart (partDescriptor .getElementId ());
@@ -226,10 +231,10 @@ private Optional<MPartStack> findPrimaryConfiguationAreaPartStack(MApplication a
226
231
if (areaCandidates .size () == 1 ) {
227
232
MArea primaryArea = areaCandidates .get (0 );
228
233
for (MPartSashContainerElement element : primaryArea .getChildren ()) {
229
- if (element instanceof MPartStack ) {
230
- return Optional .of (( MPartStack ) element );
231
- } else if (element instanceof MPartSashContainer ) {
232
- return (( MPartSashContainer ) element ) .getChildren ().stream ().filter (c -> c instanceof MPartStack )
234
+ if (element instanceof MPartStack partStack ) {
235
+ return Optional .of (partStack );
236
+ } else if (element instanceof MPartSashContainer sash ) {
237
+ return sash .getChildren ().stream ().filter (c -> c instanceof MPartStack )
233
238
.map (c -> (MPartStack ) c ).findFirst ();
234
239
}
235
240
}
0 commit comments