Skip to content

Commit 7c3839c

Browse files
committed
Migrate StackRendererTest and others to JUnit 5
Migrate the following tests to JUnit 5: - StackRendererTest - ToolBarManagerRendererTest - MPartTest - MWindowTest - PartOnTopManagerTest - MenuManagerRendererTest - PartRenderingEngineTests This involves: - Replacing WorkbenchContextRule with WorkbenchContextExtension - Updating imports to org.junit.jupiter.api.* - Updating annotations (@before -> @beforeeach, etc.) - Swapping assertion arguments where necessary - Updating assumptions - Adding org.opentest4j dependency for assumptions
1 parent f1b1d08 commit 7c3839c

File tree

8 files changed

+162
-178
lines changed

8 files changed

+162
-178
lines changed

tests/org.eclipse.e4.ui.tests/META-INF/MANIFEST.MF

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ Import-Package: jakarta.annotation,
4141
org.osgi.service.event,
4242
org.junit.jupiter.api;version="[5.14.0,6.0.0)",
4343
org.junit.jupiter.api.extension;version="[5.14.0,6.0.0)",
44-
org.junit.platform.suite.api;version="[1.14.0,2.0.0)"
44+
org.junit.platform.suite.api;version="[1.14.0,2.0.0)",
45+
org.opentest4j
4546
Eclipse-BundleShape: dir
4647
Automatic-Module-Name: org.eclipse.e4.ui.tests
4748
Require-Capability: eclipse.swt;filter:="(image.format=svg)"

tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/MPartTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515

1616
package org.eclipse.e4.ui.tests.workbench;
1717

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;
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;
2222

2323
import jakarta.inject.Inject;
2424
import org.eclipse.e4.core.contexts.IEclipseContext;
@@ -27,18 +27,18 @@
2727
import org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainer;
2828
import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
2929
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
30-
import org.eclipse.e4.ui.tests.rules.WorkbenchContextRule;
30+
import org.eclipse.e4.ui.tests.rules.WorkbenchContextExtension;
3131
import org.eclipse.e4.ui.workbench.IPresentationEngine;
3232
import org.eclipse.e4.ui.workbench.modeling.EModelService;
3333
import org.eclipse.swt.custom.CTabFolder;
3434
import org.eclipse.swt.custom.CTabItem;
35-
import org.junit.Rule;
36-
import org.junit.Test;
35+
import org.junit.jupiter.api.Test;
36+
import org.junit.jupiter.api.extension.RegisterExtension;
3737

3838
public class MPartTest {
3939

40-
@Rule
41-
public WorkbenchContextRule contextRule = new WorkbenchContextRule();
40+
@RegisterExtension
41+
public WorkbenchContextExtension contextRule = new WorkbenchContextExtension();
4242

4343
@Inject
4444
private IEclipseContext appContext;

tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/MWindowTest.java

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515

1616
package org.eclipse.e4.ui.tests.workbench;
1717

18-
import static org.junit.Assert.assertEquals;
19-
import static org.junit.Assert.assertFalse;
20-
import static org.junit.Assert.assertNotEquals;
21-
import static org.junit.Assert.assertNotNull;
22-
import static org.junit.Assert.assertNull;
23-
import static org.junit.Assert.assertTrue;
24-
import static org.junit.Assert.fail;
25-
import static org.junit.Assume.assumeFalse;
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.assertNotEquals;
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.assertTrue;
24+
import static org.junit.jupiter.api.Assertions.fail;
25+
import static org.junit.jupiter.api.Assumptions.assumeFalse;
2626

2727
import jakarta.inject.Inject;
2828
import org.eclipse.core.runtime.Platform;
@@ -37,7 +37,7 @@
3737
import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
3838
import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem;
3939
import org.eclipse.e4.ui.services.IServiceConstants;
40-
import org.eclipse.e4.ui.tests.rules.WorkbenchContextRule;
40+
import org.eclipse.e4.ui.tests.rules.WorkbenchContextExtension;
4141
import org.eclipse.e4.ui.workbench.modeling.EModelService;
4242
import org.eclipse.jface.action.MenuManager;
4343
import org.eclipse.swt.SWT;
@@ -51,14 +51,14 @@
5151
import org.eclipse.swt.widgets.Tree;
5252
import org.eclipse.swt.widgets.Widget;
5353
import org.eclipse.ui.tests.harness.util.DisplayHelper;
54-
import org.junit.Ignore;
55-
import org.junit.Rule;
56-
import org.junit.Test;
54+
import org.junit.jupiter.api.Disabled;
55+
import org.junit.jupiter.api.Test;
56+
import org.junit.jupiter.api.extension.RegisterExtension;
5757

5858
public class MWindowTest {
5959

60-
@Rule
61-
public WorkbenchContextRule contextRule = new WorkbenchContextRule();
60+
@RegisterExtension
61+
public WorkbenchContextExtension contextRule = new WorkbenchContextExtension();
6262

6363
@Inject
6464
private IEclipseContext appContext;
@@ -71,7 +71,7 @@ public class MWindowTest {
7171

7272
@Test
7373
public void testCreateWindow() {
74-
assumeFalse("Test fails on Mac: Bug 537639", Platform.OS_MACOSX.equals(Platform.getOS()));
74+
assumeFalse(Platform.OS_MACOSX.equals(Platform.getOS()), "Test fails on Mac: Bug 537639");
7575

7676
final MWindow window = ems.createModelElement(MWindow.class);
7777
window.setLabel("MyWindow");
@@ -147,7 +147,7 @@ public void testCreateView() {
147147

148148
@Test
149149
public void testContextChildren() {
150-
assumeFalse("Test fails on Mac: Bug 537639", Platform.OS_MACOSX.equals(Platform.getOS()));
150+
assumeFalse(Platform.OS_MACOSX.equals(Platform.getOS()), "Test fails on Mac: Bug 537639");
151151

152152
final MWindow window = createWindowWithOneView();
153153

@@ -250,7 +250,7 @@ public void testWindow_Name() {
250250
assertEquals("windowName2", shell.getText());
251251
}
252252

253-
@Ignore
253+
@Disabled
254254
@Test
255255
public void TODOtestWindow_X() {
256256
final MWindow window = ems.createModelElement(MWindow.class);
@@ -283,7 +283,7 @@ public void TODOtestWindow_X() {
283283
assertEquals(300, bounds.x);
284284
}
285285

286-
@Ignore
286+
@Disabled
287287
@Test
288288
public void TODOtestWindow_Y() {
289289
final MWindow window = ems.createModelElement(MWindow.class);
@@ -387,22 +387,22 @@ public void testDetachedWindow() {
387387
Shell topShell = (Shell) window.getWidget();
388388
Shell detachedShell = (Shell) detachedWindow.getWidget();
389389
assertEquals(window, ems.getContainer(detachedWindow));
390-
assertNull("Should have no shell image", topShell.getImage());
391-
assertEquals("Detached should have same image", topShell.getImage(), detachedShell.getImage());
390+
assertNull(topShell.getImage(), "Should have no shell image");
391+
assertEquals(topShell.getImage(), detachedShell.getImage(), "Detached should have same image");
392392

393393
// now set icon on top-level window; detached window should inherit it
394394
window.setIconURI("platform:/plugin/org.eclipse.e4.ui.tests/icons/filenav_nav.svg");
395395
while (topShell.getDisplay().readAndDispatch()) {
396396
}
397-
assertNotNull("Should have shell image", topShell.getImage());
398-
assertEquals("Detached should have same image", topShell.getImage(), detachedShell.getImage());
397+
assertNotNull(topShell.getImage(), "Should have shell image");
398+
assertEquals(topShell.getImage(), detachedShell.getImage(), "Detached should have same image");
399399

400400
// change top-level icon; detached window should inherit it
401401
window.setIconURI(null);
402402
while (topShell.getDisplay().readAndDispatch()) {
403403
}
404-
assertNull("Should have no shell image", topShell.getImage());
405-
assertEquals("Detached should have same image", topShell.getImage(), detachedShell.getImage());
404+
assertNull(topShell.getImage(), "Should have no shell image");
405+
assertEquals(topShell.getImage(), detachedShell.getImage(), "Detached should have same image");
406406

407407
// turn detached into top-level window; inherited icon should be removed
408408
window.setIconURI("platform:/plugin/org.eclipse.e4.ui.tests/icons/filenav_nav.svg");

tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/PartOnTopManagerTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
package org.eclipse.e4.ui.tests.workbench;
1717

18-
import static org.junit.Assert.assertFalse;
19-
import static org.junit.Assert.assertTrue;
18+
import static org.junit.jupiter.api.Assertions.assertFalse;
19+
import static org.junit.jupiter.api.Assertions.assertTrue;
2020

2121
import jakarta.inject.Inject;
2222
import org.eclipse.e4.ui.internal.workbench.PartOnTopManager;
@@ -29,21 +29,21 @@
2929
import org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainer;
3030
import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
3131
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
32-
import org.eclipse.e4.ui.tests.rules.WorkbenchContextRule;
32+
import org.eclipse.e4.ui.tests.rules.WorkbenchContextExtension;
3333
import org.eclipse.e4.ui.workbench.IWorkbench;
3434
import org.eclipse.e4.ui.workbench.modeling.EModelService;
3535
import org.eclipse.e4.ui.workbench.modeling.EPartService;
36-
import org.junit.Rule;
37-
import org.junit.Test;
36+
import org.junit.jupiter.api.Test;
37+
import org.junit.jupiter.api.extension.RegisterExtension;
3838

3939
/**
4040
* This test class is used to validate the correctness of the
4141
* {@link PartOnTopManager}.
4242
*/
4343
public class PartOnTopManagerTest {
4444

45-
@Rule
46-
public WorkbenchContextRule contextRule = new WorkbenchContextRule();
45+
@RegisterExtension
46+
public WorkbenchContextExtension contextRule = new WorkbenchContextExtension();
4747

4848
@Inject
4949
private EModelService ems;

0 commit comments

Comments
 (0)