Skip to content

Commit 1012d33

Browse files
committed
Migrate 5 additional tests to JUnit 5 using CloseTestWindowsExtension
Migrated 5 tests in org.eclipse.ui.tests from CloseTestWindowsRule (JUnit 4) to CloseTestWindowsExtension (JUnit 5). Updated imports, annotations (@rule -> @ExtendWith, @before -> @beforeeach, @after -> @AfterEach, @ignore -> @disabled), and assertions.
1 parent 6dd04b2 commit 1012d33

File tree

5 files changed

+74
-89
lines changed

5 files changed

+74
-89
lines changed

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/commands/ActionDelegateProxyTest.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616

1717
import static org.eclipse.ui.tests.harness.util.UITestUtil.openTestWindow;
1818
import static org.eclipse.ui.tests.harness.util.UITestUtil.processEvents;
19-
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertFalse;
21-
import static org.junit.Assert.assertNotNull;
22-
import static org.junit.Assert.assertNull;
23-
import static org.junit.Assert.assertThrows;
24-
import static org.junit.Assert.assertTrue;
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertFalse;
21+
import static org.junit.jupiter.api.Assertions.assertNotNull;
22+
import static org.junit.jupiter.api.Assertions.assertNull;
23+
import static org.junit.jupiter.api.Assertions.assertThrows;
24+
import static org.junit.jupiter.api.Assertions.assertTrue;
2525

2626
import java.io.ByteArrayInputStream;
2727
import java.io.InputStream;
@@ -37,18 +37,16 @@
3737
import org.eclipse.ui.handlers.IHandlerService;
3838
import org.eclipse.ui.ide.IDE;
3939
import org.eclipse.ui.tests.api.workbenchpart.MenuContributionHarness;
40-
import org.eclipse.ui.tests.harness.util.CloseTestWindowsRule;
40+
import org.eclipse.ui.tests.harness.util.CloseTestWindowsExtension;
4141
import org.eclipse.ui.tests.harness.util.FileUtil;
42-
import org.junit.Ignore;
43-
import org.junit.Rule;
44-
import org.junit.Test;
42+
import org.junit.jupiter.api.Disabled;
43+
import org.junit.jupiter.api.Test;
44+
import org.junit.jupiter.api.extension.ExtendWith;
4545

46-
@Ignore("broke during e4 transition and still need adjustments")
46+
@Disabled("broke during e4 transition and still need adjustments")
47+
@ExtendWith(CloseTestWindowsExtension.class)
4748
public class ActionDelegateProxyTest {
4849

49-
@Rule
50-
public CloseTestWindowsRule closeTestWindows = new CloseTestWindowsRule();
51-
5250
private static final String DELEGATE_ACTION_SET_ID = "org.eclipse.ui.tests.delegateActionSet";
5351
private static final String INC_COMMAND = "org.eclipse.ui.tests.incMenuHarness";
5452
private static final String VIEW_ID = "org.eclipse.ui.tests.api.MenuTestHarness";

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/commands/CommandCallbackTest.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
package org.eclipse.ui.tests.commands;
1717

1818
import static org.eclipse.ui.tests.harness.util.UITestUtil.openTestWindow;
19-
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertThrows;
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertThrows;
2121

2222
import java.util.HashMap;
2323
import java.util.Map;
@@ -41,20 +41,18 @@
4141
import org.eclipse.ui.menus.UIElement;
4242
import org.eclipse.ui.services.IServiceLocator;
4343
import org.eclipse.ui.services.IServiceScopes;
44-
import org.eclipse.ui.tests.harness.util.CloseTestWindowsRule;
45-
import org.junit.After;
46-
import org.junit.Before;
47-
import org.junit.Rule;
48-
import org.junit.Test;
44+
import org.eclipse.ui.tests.harness.util.CloseTestWindowsExtension;
45+
import org.junit.jupiter.api.AfterEach;
46+
import org.junit.jupiter.api.BeforeEach;
47+
import org.junit.jupiter.api.Test;
48+
import org.junit.jupiter.api.extension.ExtendWith;
4949

5050
/**
5151
* @since 3.3
5252
*/
53+
@ExtendWith(CloseTestWindowsExtension.class)
5354
public class CommandCallbackTest {
5455

55-
@Rule
56-
public final CloseTestWindowsRule closeTestWindowsRule = new CloseTestWindowsRule();
57-
5856
private static final String HOST_PARAM_ID = "host";
5957
private static final String PROT_PARAM_ID = "protocol";
6058
private static final String PREFIX = "tests.commands.CCT.";
@@ -71,7 +69,7 @@ public class CommandCallbackTest {
7169
private CallbackHandler cmd1Handler;
7270
private CallbackHandler cmd2Handler;
7371

74-
@Before
72+
@BeforeEach
7573
public final void setUp() throws Exception {
7674
workbench = PlatformUI.getWorkbench();
7775
commandService = workbench.getService(ICommandService.class);
@@ -84,7 +82,7 @@ public final void setUp() throws Exception {
8482
cmd2Activation = handlerService.activateHandler(CMD2_ID, cmd2Handler);
8583
}
8684

87-
@After
85+
@AfterEach
8886
public final void tearDown() throws Exception {
8987
if (cmd1Activation != null) {
9088
handlerService.deactivateHandler(cmd1Activation);

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/commands/CommandEnablementTest.java

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
package org.eclipse.ui.tests.commands;
1616

1717
import static org.eclipse.ui.tests.harness.util.UITestUtil.openTestWindow;
18-
import static org.junit.Assert.assertEquals;
19-
import static org.junit.Assert.assertFalse;
20-
import static org.junit.Assert.assertNotNull;
21-
import static org.junit.Assert.assertNull;
22-
import static org.junit.Assert.assertTrue;
18+
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertFalse;
20+
import static org.junit.jupiter.api.Assertions.assertNotNull;
21+
import static org.junit.jupiter.api.Assertions.assertNull;
22+
import static org.junit.jupiter.api.Assertions.assertTrue;
2323

2424
import java.lang.reflect.Field;
2525
import java.util.Map;
@@ -68,22 +68,20 @@
6868
import org.eclipse.ui.menus.UIElement;
6969
import org.eclipse.ui.services.IEvaluationService;
7070
import org.eclipse.ui.services.ISourceProviderService;
71-
import org.eclipse.ui.tests.harness.util.CloseTestWindowsRule;
72-
import org.junit.After;
73-
import org.junit.Before;
74-
import org.junit.Ignore;
75-
import org.junit.Rule;
76-
import org.junit.Test;
71+
import org.eclipse.ui.tests.harness.util.CloseTestWindowsExtension;
72+
import org.junit.jupiter.api.AfterEach;
73+
import org.junit.jupiter.api.BeforeEach;
74+
import org.junit.jupiter.api.Disabled;
75+
import org.junit.jupiter.api.Test;
76+
import org.junit.jupiter.api.extension.ExtendWith;
7777

7878
/**
7979
* @since 3.3
8080
*/
81-
@Ignore("broke during e4 transition and still need adjustments")
81+
@Disabled("broke during e4 transition and still need adjustments")
82+
@ExtendWith(CloseTestWindowsExtension.class)
8283
public class CommandEnablementTest {
8384

84-
@Rule
85-
public CloseTestWindowsRule closeTestWindows = new CloseTestWindowsRule();
86-
8785
private static final String CONTEXT_TEST2 = "org.eclipse.ui.command.contexts.enablement_test2";
8886
private static final String CONTEXT_TEST1 = "org.eclipse.ui.command.contexts.enablement_test1";
8987
private static final String PREFIX = "tests.commands.CCT.";
@@ -110,7 +108,7 @@ public class CommandEnablementTest {
110108
private IContextActivation contextActivation2;
111109
private IWorkbench fWorkbench;
112110

113-
@Before
111+
@BeforeEach
114112
public void doSetUp() throws Exception {
115113
fWorkbench = PlatformUI.getWorkbench();
116114
commandService = fWorkbench.getService(ICommandService.class);
@@ -128,7 +126,7 @@ public void doSetUp() throws Exception {
128126
contextHandler = new CheckContextHandler();
129127
}
130128

131-
@After
129+
@AfterEach
132130
public void doTearDown() throws Exception {
133131
if (activation1 != null) {
134132
handlerService.deactivateHandler(activation1);

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/commands/HandlerActivationTest.java

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
package org.eclipse.ui.tests.commands;
1616

1717
import static org.eclipse.ui.tests.harness.util.UITestUtil.openTestWindow;
18-
import static org.junit.Assert.assertEquals;
19-
import static org.junit.Assert.assertFalse;
20-
import static org.junit.Assert.assertThrows;
21-
import static org.junit.Assert.assertTrue;
18+
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertFalse;
20+
import static org.junit.jupiter.api.Assertions.assertThrows;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
2222

2323
import java.util.HashMap;
2424
import java.util.Map;
@@ -48,23 +48,21 @@
4848
import org.eclipse.ui.handlers.IHandlerActivation;
4949
import org.eclipse.ui.handlers.IHandlerService;
5050
import org.eclipse.ui.services.IServiceLocator;
51-
import org.eclipse.ui.tests.harness.util.CloseTestWindowsRule;
51+
import org.eclipse.ui.tests.harness.util.CloseTestWindowsExtension;
5252
import org.eclipse.ui.views.contentoutline.ContentOutline;
53-
import org.junit.After;
54-
import org.junit.Before;
55-
import org.junit.Rule;
56-
import org.junit.Test;
53+
import org.junit.jupiter.api.AfterEach;
54+
import org.junit.jupiter.api.BeforeEach;
55+
import org.junit.jupiter.api.Test;
56+
import org.junit.jupiter.api.extension.ExtendWith;
5757

5858
/**
5959
* Tests various aspects of command state.
6060
*
6161
* @since 3.2
6262
*/
63+
@ExtendWith(CloseTestWindowsExtension.class)
6364
public class HandlerActivationTest {
6465

65-
@Rule
66-
public final CloseTestWindowsRule closeTestWindowsRule = new CloseTestWindowsRule();
67-
6866
static class ActTestHandler extends AbstractHandler {
6967
public String contextId;
7068

@@ -174,8 +172,7 @@ private void assertHandlerIsExecuted(Command cmd, String handlerId)
174172
ActTestHandler handler = (ActTestHandler) testHandlers.get(handlerId);
175173
int count = handler.executionCount;
176174
cmd.executeWithChecks(handlerService.createExecutionEvent(cmd, null));
177-
assertEquals("The handler count should be incremented", count + 1,
178-
handler.executionCount);
175+
assertEquals(count + 1, handler.executionCount, "The handler count should be incremented");
179176
}
180177

181178
private void createHandlerActivation(String contextId, String handlerId,
@@ -185,7 +182,7 @@ private void createHandlerActivation(String contextId, String handlerId,
185182
makeHandler(handlerId, contextId, expression);
186183
}
187184

188-
@Before
185+
@BeforeEach
189186
public final void setUp() throws Exception {
190187
for (final String[] contextInfo : CREATE_CONTEXTS) {
191188
final Context context = contextService.getContext(contextInfo[0]);
@@ -203,7 +200,7 @@ public final void setUp() throws Exception {
203200

204201
}
205202

206-
@After
203+
@AfterEach
207204
public final void tearDown() throws Exception {
208205
handlerService.deactivateHandlers(testHandlerActivations.values());
209206
testHandlerActivations.clear();
@@ -214,15 +211,15 @@ public final void tearDown() throws Exception {
214211
private void doTestForBreak() throws ExecutionException,
215212
NotDefinedException, NotEnabledException, NotHandledException {
216213
Command cmd = commandService.getCommand(CMD_ID);
217-
assertTrue("Command should be defined", cmd.isDefined());
214+
assertTrue(cmd.isDefined(), "Command should be defined");
218215

219-
assertFalse("Should not be handled yet", cmd.isHandled());
216+
assertFalse(cmd.isHandled(), "Should not be handled yet");
220217

221218
IContextActivation c1 = activateContext(C1_ID);
222219
IContextActivation c2 = activateContext(C2_ID);
223220
IContextActivation c3 = activateContext(C3_ID);
224221

225-
assertTrue("Should still be handled", cmd.isHandled());
222+
assertTrue(cmd.isHandled(), "Should still be handled");
226223

227224
assertHandlerIsExecuted(cmd, H3);
228225

@@ -260,22 +257,21 @@ public void testBasicHandler() throws Exception {
260257
new String[] { ISources.ACTIVE_CONTEXT_NAME });
261258

262259
Command cmd = commandService.getCommand(CMD_ID);
263-
assertTrue("Command should be defined", cmd.isDefined());
260+
assertTrue(cmd.isDefined(), "Command should be defined");
264261

265-
assertFalse("Should not be handled yet", cmd.isHandled());
262+
assertFalse(cmd.isHandled(), "Should not be handled yet");
266263

267264
IContextActivation activationC1 = activateContext(C1_ID);
268-
assertTrue("Should definitely be handled", cmd.isHandled());
265+
assertTrue(cmd.isHandled(), "Should definitely be handled");
269266

270267
ActTestHandler handler1 = (ActTestHandler) testHandlers.get(H1);
271268
int count = handler1.executionCount;
272269
cmd.executeWithChecks(handlerService.createExecutionEvent(cmd, null));
273-
assertEquals("The handler count should be correct", count + 1,
274-
handler1.executionCount);
270+
assertEquals(count + 1, handler1.executionCount, "The handler count should be correct");
275271

276272
contextService.deactivateContext(activationC1);
277273

278-
assertFalse("Should not be handled", cmd.isHandled());
274+
assertFalse(cmd.isHandled(), "Should not be handled");
279275
}
280276

281277
@Test
@@ -382,32 +378,29 @@ public void testTwoHandlers() throws Exception {
382378
ISources.ACTIVE_ACTION_SETS_NAME });
383379

384380
Command cmd = commandService.getCommand(CMD_ID);
385-
assertTrue("Command should be defined", cmd.isDefined());
381+
assertTrue(cmd.isDefined(), "Command should be defined");
386382

387-
assertFalse("Should not be handled yet", cmd.isHandled());
383+
assertFalse(cmd.isHandled(), "Should not be handled yet");
388384
IContextActivation activationC1 = activateContext(C1_ID);
389-
assertTrue("Should definitely be handled", cmd.isHandled());
385+
assertTrue(cmd.isHandled(), "Should definitely be handled");
390386

391387
ActTestHandler handler1 = (ActTestHandler) testHandlers.get(H1);
392388
int count1 = handler1.executionCount;
393389
cmd.executeWithChecks(new ExecutionEvent());
394-
assertEquals("The handler count should be incremented", count1 + 1,
395-
handler1.executionCount);
390+
assertEquals(count1 + 1, handler1.executionCount, "The handler count should be incremented");
396391

397392
activateContext(C2_ID);
398-
assertTrue("Should still be handled", cmd.isHandled());
393+
assertTrue(cmd.isHandled(), "Should still be handled");
399394

400395
ActTestHandler handler2 = (ActTestHandler) testHandlers.get(H2);
401396
int count2 = handler2.executionCount;
402397
count1 = handler1.executionCount;
403398
cmd.executeWithChecks(new ExecutionEvent());
404-
assertEquals("The handler1 count should not be incremented", count1,
405-
handler1.executionCount);
406-
assertEquals("The handler2 count should be incremented", count2 + 1,
407-
handler2.executionCount);
399+
assertEquals(count1, handler1.executionCount, "The handler1 count should not be incremented");
400+
assertEquals(count2 + 1, handler2.executionCount, "The handler2 count should be incremented");
408401

409402
contextService.deactivateContext(activationC1);
410-
assertTrue("Will still be handled", cmd.isHandled());
403+
assertTrue(cmd.isHandled(), "Will still be handled");
411404
}
412405

413406
@Test

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/contexts/Bug74990Test.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
package org.eclipse.ui.tests.contexts;
1515

1616
import static org.eclipse.ui.tests.harness.util.UITestUtil.openTestWindow;
17-
import static org.junit.Assert.assertTrue;
17+
import static org.junit.jupiter.api.Assertions.assertTrue;
1818

1919
import org.eclipse.ui.IViewPart;
2020
import org.eclipse.ui.IWorkbench;
@@ -24,20 +24,18 @@
2424
import org.eclipse.ui.contexts.EnabledSubmission;
2525
import org.eclipse.ui.contexts.IContext;
2626
import org.eclipse.ui.contexts.IWorkbenchContextSupport;
27-
import org.eclipse.ui.tests.harness.util.CloseTestWindowsRule;
28-
import org.junit.Rule;
29-
import org.junit.Test;
27+
import org.eclipse.ui.tests.harness.util.CloseTestWindowsExtension;
28+
import org.junit.jupiter.api.Test;
29+
import org.junit.jupiter.api.extension.ExtendWith;
3030

3131
/**
3232
* A test for whether part identifiers work properly for EnabledSubmissions.
3333
*
3434
* @since 3.1
3535
*/
36+
@ExtendWith(CloseTestWindowsExtension.class)
3637
public final class Bug74990Test {
3738

38-
@Rule
39-
public CloseTestWindowsRule closeTestWindows = new CloseTestWindowsRule();
40-
4139
/**
4240
* Tests whether a part-specific context -- submitted via Java code -- is
4341
* matched properly. This is only using the part id. The test verifies that it
@@ -62,7 +60,7 @@ public final void testPartIdSubmission() throws PartInitException {
6260

6361
try {
6462
// Test to make sure the context is not currently enabled.
65-
assertTrue("The MockViewPart context should not be enabled", !testContext.isEnabled());
63+
assertTrue(!testContext.isEnabled(), "The MockViewPart context should not be enabled");
6664

6765
/*
6866
* Open a window with the MockViewPart, and make sure it now enabled.
@@ -72,13 +70,13 @@ public final void testPartIdSubmission() throws PartInitException {
7270
page.activate(openedView);
7371
while (fWorkbench.getDisplay().readAndDispatch()) {
7472
}
75-
assertTrue("The MockViewPart context should be enabled", testContext.isEnabled());
73+
assertTrue(testContext.isEnabled(), "The MockViewPart context should be enabled");
7674

7775
// Hide the view, and test that is becomes disabled again.
7876
page.hideView(openedView);
7977
while (fWorkbench.getDisplay().readAndDispatch()) {
8078
}
81-
assertTrue("The MockViewPart context should not be enabled", !testContext.isEnabled());
79+
assertTrue(!testContext.isEnabled(), "The MockViewPart context should not be enabled");
8280

8381
} finally {
8482
contextSupport.removeEnabledSubmission(testSubmission);

0 commit comments

Comments
 (0)