Skip to content

Commit 6ff09fb

Browse files
committed
Migrate 10 tests to JUnit 5 using CloseTestWindowsExtension
Migrated 10 tests in org.eclipse.ui.tests from using CloseTestWindowsRule (JUnit 4) to CloseTestWindowsExtension (JUnit 5). Updates include replacing imports, annotations (@rule -> @ExtendWith, @ignore -> @disabled, @before -> @beforeeach), and updating assertion argument order.
1 parent 9db8253 commit 6ff09fb

File tree

10 files changed

+82
-100
lines changed

10 files changed

+82
-100
lines changed

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/internal/ActionExpressionTest.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,17 @@
2222
import org.eclipse.ui.IWorkbenchWindow;
2323
import org.eclipse.ui.tests.api.ListElement;
2424
import org.eclipse.ui.tests.api.ListView;
25-
import org.eclipse.ui.tests.harness.util.CloseTestWindowsRule;
26-
import org.junit.Before;
27-
import org.junit.Rule;
28-
import org.junit.Test;
25+
import org.eclipse.ui.tests.harness.util.CloseTestWindowsExtension;
26+
import org.junit.jupiter.api.BeforeEach;
27+
import org.junit.jupiter.api.Test;
28+
import org.junit.jupiter.api.extension.ExtendWith;
2929

3030
/**
3131
* This class contains tests for popup menu enablement
3232
*/
33+
@ExtendWith(CloseTestWindowsExtension.class)
3334
public abstract class ActionExpressionTest {
3435

35-
@Rule
36-
public final CloseTestWindowsRule closeTestWindowsRule = new CloseTestWindowsRule();
37-
3836
protected IWorkbenchWindow fWindow;
3937

4038
protected IWorkbenchPage fPage;
@@ -47,7 +45,7 @@ public abstract class ActionExpressionTest {
4745

4846
ListElement redTrue = new ListElement("red", true);
4947

50-
@Before
48+
@BeforeEach
5149
public final void setUp() throws Exception {
5250
fWindow = openTestWindow();
5351
fPage = fWindow.getActivePage();

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/internal/Bug41931Test.java

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

1717
import static org.eclipse.ui.tests.harness.util.UITestUtil.openTestWindow;
18-
import static org.junit.Assert.assertEquals;
18+
import static org.junit.jupiter.api.Assertions.assertEquals;
1919

2020
import java.io.ByteArrayInputStream;
2121
import java.io.InputStream;
@@ -30,22 +30,20 @@
3030
import org.eclipse.ui.IWorkbenchWindow;
3131
import org.eclipse.ui.ide.IDE;
3232
import org.eclipse.ui.internal.WorkbenchPage;
33-
import org.eclipse.ui.tests.harness.util.CloseTestWindowsRule;
34-
import org.junit.Ignore;
35-
import org.junit.Rule;
36-
import org.junit.Test;
33+
import org.eclipse.ui.tests.harness.util.CloseTestWindowsExtension;
34+
import org.junit.jupiter.api.Disabled;
35+
import org.junit.jupiter.api.Test;
36+
import org.junit.jupiter.api.extension.ExtendWith;
3737

3838
/**
3939
* Test for Bug 41931.
4040
*
4141
* @since 3.0
4242
*/
43-
@Ignore
43+
@Disabled
44+
@ExtendWith(CloseTestWindowsExtension.class)
4445
public class Bug41931Test {
4546

46-
@Rule
47-
public CloseTestWindowsRule closeTestWindows = new CloseTestWindowsRule();
48-
4947
/**
5048
* Tests that the <code>bringToTop(IWorkbenchPart)</code> correctly
5149
* updates the activation list.
@@ -83,8 +81,8 @@ public void testBringToTop() throws CoreException {
8381
IEditorPart[] expectedResults = { editorA, editorB, editorC };
8482
IWorkbenchPartReference[] actualResults = page.getSortedParts();
8583
for (int i = 0; i < expectedResults.length; i++) {
86-
assertEquals(
87-
"Pre-test order is not correct.", expectedResults[i].getTitle(), actualResults[i].getPart(false).getTitle()); //$NON-NLS-1$
84+
assertEquals(expectedResults[i].getTitle(), actualResults[i].getPart(false).getTitle(),
85+
"Pre-test order is not correct."); //$NON-NLS-1$
8886
}
8987

9088
// Bring editor B to the top.
@@ -94,8 +92,8 @@ public void testBringToTop() throws CoreException {
9492
expectedResults = new IEditorPart[] { editorA, editorC, editorB };
9593
actualResults = page.getSortedParts();
9694
for (int i = 0; i < expectedResults.length; i++) {
97-
assertEquals(
98-
"bringToTop() does not change sorted part order.", expectedResults[i].getTitle(), actualResults[i].getPart(false).getTitle()); //$NON-NLS-1$
95+
assertEquals(expectedResults[i].getTitle(), actualResults[i].getPart(false).getTitle(),
96+
"bringToTop() does not change sorted part order."); //$NON-NLS-1$
9997
}
10098
}
10199
}

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/internal/PerspectiveSwitcherTest.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,22 @@
1515
package org.eclipse.ui.tests.internal;
1616

1717
import static org.eclipse.ui.PlatformUI.getWorkbench;
18-
import static org.junit.Assert.assertNotNull;
18+
import static org.junit.jupiter.api.Assertions.assertNotNull;
1919

2020
import org.eclipse.e4.ui.workbench.modeling.EModelService;
2121
import org.eclipse.jface.preference.IPreferenceStore;
2222
import org.eclipse.ui.IWorkbenchPreferenceConstants;
2323
import org.eclipse.ui.internal.WorkbenchWindow;
2424
import org.eclipse.ui.internal.util.PrefUtil;
25-
import org.eclipse.ui.tests.harness.util.CloseTestWindowsRule;
25+
import org.eclipse.ui.tests.harness.util.CloseTestWindowsExtension;
2626
import org.eclipse.ui.tests.harness.util.PreferenceMementoRule;
2727
import org.junit.Rule;
28-
import org.junit.Test;
28+
import org.junit.jupiter.api.Test;
29+
import org.junit.jupiter.api.extension.ExtendWith;
2930

31+
@ExtendWith(CloseTestWindowsExtension.class)
3032
public class PerspectiveSwitcherTest {
3133

32-
@Rule
33-
public final CloseTestWindowsRule closeTestWindowsRule = new CloseTestWindowsRule();
34-
3534
@Rule
3635
public final PreferenceMementoRule preferenceMemento = new PreferenceMementoRule();
3736

@@ -44,14 +43,14 @@ public void testCreatePerspectiveSwithcerInToolbar() {
4443
IPreferenceStore apiPreferenceStore = PrefUtil.getAPIPreferenceStore();
4544

4645
WorkbenchWindow window = (WorkbenchWindow) getWorkbench().getActiveWorkbenchWindow();
47-
assertNotNull("We should have a perspective bar in the beginning", getPerspectiveSwitcher(window)); //$NON-NLS-1$
46+
assertNotNull(getPerspectiveSwitcher(window), "We should have a perspective bar in the beginning"); //$NON-NLS-1$
4847

4948
// turn off the 'Open Perspective' item
5049
preferenceMemento.setPreference(apiPreferenceStore, IWorkbenchPreferenceConstants.SHOW_OPEN_ON_PERSPECTIVE_BAR,
5150
false);
5251

5352
// check that we still have a perspective bar
54-
assertNotNull("The perspective bar should have been created successfully", getPerspectiveSwitcher(window)); //$NON-NLS-1$
53+
assertNotNull(getPerspectiveSwitcher(window), "The perspective bar should have been created successfully"); //$NON-NLS-1$
5554

5655
}
5756

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/internal/StickyViewManagerTest.java

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

1717
import static org.eclipse.ui.PlatformUI.getWorkbench;
18-
import static org.junit.Assert.assertNotNull;
19-
import static org.junit.Assert.assertNull;
18+
import static org.junit.jupiter.api.Assertions.assertNotNull;
19+
import static org.junit.jupiter.api.Assertions.assertNull;
2020

2121
import org.eclipse.ui.IPageLayout;
2222
import org.eclipse.ui.IPerspectiveDescriptor;
@@ -26,27 +26,26 @@
2626
import org.eclipse.ui.IWorkbenchPage;
2727
import org.eclipse.ui.IWorkbenchPreferenceConstants;
2828
import org.eclipse.ui.PlatformUI;
29-
import org.eclipse.ui.tests.harness.util.CloseTestWindowsRule;
29+
import org.eclipse.ui.tests.harness.util.CloseTestWindowsExtension;
3030
import org.eclipse.ui.tests.harness.util.PreferenceMementoRule;
31-
import org.junit.Before;
32-
import org.junit.Ignore;
3331
import org.junit.Rule;
34-
import org.junit.Test;
32+
import org.junit.jupiter.api.BeforeEach;
33+
import org.junit.jupiter.api.Disabled;
34+
import org.junit.jupiter.api.Test;
35+
import org.junit.jupiter.api.extension.ExtendWith;
3536

3637
/**
3738
* @since 3.6
3839
*/
39-
@Ignore
40+
@Disabled
41+
@ExtendWith(CloseTestWindowsExtension.class)
4042
public class StickyViewManagerTest {
4143

42-
@Rule
43-
public final CloseTestWindowsRule closeTestWindowsRule = new CloseTestWindowsRule();
44-
4544
@Rule
4645
public final PreferenceMementoRule preferenceMemento = new PreferenceMementoRule();
4746

4847

49-
@Before
48+
@BeforeEach
5049
public final void setUp() throws Exception {
5150
preferenceMemento.setPreference(PlatformUI.getPreferenceStore(),
5251
IWorkbenchPreferenceConstants.ENABLE_32_STICKY_CLOSE_BEHAVIOR, false);

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/internal/TextHandlerTest.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
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.assertFalse;
20-
import static org.junit.Assert.assertTrue;
21-
import static org.junit.Assume.assumeFalse;
19+
import static org.junit.jupiter.api.Assertions.assertFalse;
20+
import static org.junit.jupiter.api.Assertions.assertTrue;
21+
import static org.junit.jupiter.api.Assumptions.assumeFalse;
2222

2323
import org.eclipse.core.runtime.Platform;
2424
import org.eclipse.swt.dnd.Clipboard;
@@ -27,23 +27,21 @@
2727
import org.eclipse.swt.dnd.URLTransfer;
2828
import org.eclipse.ui.IWorkbenchWindow;
2929
import org.eclipse.ui.actions.TextActionHandler;
30-
import org.eclipse.ui.tests.harness.util.CloseTestWindowsRule;
31-
import org.junit.Rule;
32-
import org.junit.Test;
30+
import org.eclipse.ui.tests.harness.util.CloseTestWindowsExtension;
31+
import org.junit.jupiter.api.Test;
32+
import org.junit.jupiter.api.extension.ExtendWith;
3333

3434
/**
3535
* Test for {@link TextActionHandler}.
3636
*
3737
* @since 3.5
3838
*/
39+
@ExtendWith(CloseTestWindowsExtension.class)
3940
public class TextHandlerTest {
4041

41-
@Rule
42-
public final CloseTestWindowsRule closeTestWindowsRule = new CloseTestWindowsRule();
43-
4442
@Test
4543
public void testEditableText() throws Exception {
46-
assumeFalse("Test fails on Mac: Bug 544675", Platform.OS_MACOSX.equals(Platform.getOS()));
44+
assumeFalse(Platform.OS_MACOSX.equals(Platform.getOS()), "Test fails on Mac: Bug 544675");
4745

4846
IWorkbenchWindow window = openTestWindow();
4947
TextControlView view = (TextControlView) window.getActivePage()

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/keys/Bug36537Test.java

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

1717
import static org.eclipse.ui.tests.harness.util.UITestUtil.openTestWindow;
18-
import static org.junit.Assert.assertFalse;
18+
import static org.junit.jupiter.api.Assertions.assertFalse;
1919

2020
import java.util.ArrayList;
2121
import java.util.HashMap;
@@ -29,20 +29,18 @@
2929
import org.eclipse.ui.IWorkbench;
3030
import org.eclipse.ui.IWorkbenchWindow;
3131
import org.eclipse.ui.keys.IBindingService;
32-
import org.eclipse.ui.tests.harness.util.CloseTestWindowsRule;
33-
import org.junit.Rule;
34-
import org.junit.Test;
32+
import org.eclipse.ui.tests.harness.util.CloseTestWindowsExtension;
33+
import org.junit.jupiter.api.Test;
34+
import org.junit.jupiter.api.extension.ExtendWith;
3535

3636
/**
3737
* Tests Bug 36537
3838
*
3939
* @since 3.0
4040
*/
41+
@ExtendWith(CloseTestWindowsExtension.class)
4142
public class Bug36537Test {
4243

43-
@Rule
44-
public CloseTestWindowsRule closeTestWindows = new CloseTestWindowsRule();
45-
4644
/**
4745
* Tests that there are no redundant key bindings defined in the
4846
* application.
@@ -115,8 +113,8 @@ public void testForRedundantKeySequenceBindings() {
115113
nullMatches++;
116114
}
117115

118-
assertFalse(
119-
"Redundant key bindings: " + binding + ", " + matchedBinding, same && (nullMatches < 1)); //$NON-NLS-1$ //$NON-NLS-2$
116+
assertFalse(same && (nullMatches < 1),
117+
"Redundant key bindings: " + binding + ", " + matchedBinding); //$NON-NLS-1$ //$NON-NLS-2$
120118
}
121119

122120
// Add the key binding.

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/keys/Bug40023Test.java

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

1717
import static org.eclipse.ui.tests.harness.util.UITestUtil.openTestWindow;
18-
import static org.junit.Assert.assertTrue;
18+
import static org.junit.jupiter.api.Assertions.assertTrue;
1919

2020
import java.io.FileNotFoundException;
2121
import java.io.IOException;
@@ -33,22 +33,20 @@
3333
import org.eclipse.ui.internal.Workbench;
3434
import org.eclipse.ui.internal.keys.BindingService;
3535
import org.eclipse.ui.keys.IBindingService;
36-
import org.eclipse.ui.tests.harness.util.CloseTestWindowsRule;
37-
import org.junit.Ignore;
38-
import org.junit.Rule;
39-
import org.junit.Test;
36+
import org.eclipse.ui.tests.harness.util.CloseTestWindowsExtension;
37+
import org.junit.jupiter.api.Disabled;
38+
import org.junit.jupiter.api.Test;
39+
import org.junit.jupiter.api.extension.ExtendWith;
4040

4141
/**
4242
* Tests Bug 40023
4343
*
4444
* @since 3.0
4545
*/
46-
@Ignore("Intermittent failure. SWT Bug 44344. XGrabPointer?")
46+
@Disabled("Intermittent failure. SWT Bug 44344. XGrabPointer?")
47+
@ExtendWith(CloseTestWindowsExtension.class)
4748
public class Bug40023Test {
4849

49-
@Rule
50-
public CloseTestWindowsRule closeTestWindows = new CloseTestWindowsRule();
51-
5250
/**
5351
* Retrieves a menu item matching or starting with the given name from an
5452
* array of menu items.
@@ -112,7 +110,7 @@ public void testCheckOnCheckbox() throws CoreException, CommandException,
112110
"&Window"); //$NON-NLS-1$
113111
MenuItem lockToolBarsMenuItem = getMenuItem(windowMenu.getMenu()
114112
.getItems(), "Lock the &Toolbars"); //$NON-NLS-1$
115-
assertTrue("Checkbox menu item is not checked.", lockToolBarsMenuItem //$NON-NLS-1$
116-
.getSelection());
113+
assertTrue(lockToolBarsMenuItem //$NON-NLS-1$
114+
.getSelection(), "Checkbox menu item is not checked.");
117115
}
118116
}

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/keys/Bug43321Test.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
package org.eclipse.ui.tests.keys;
1616

1717
import static org.eclipse.ui.tests.harness.util.UITestUtil.openTestWindow;
18-
import static org.junit.Assert.assertTrue;
18+
import static org.junit.jupiter.api.Assertions.assertTrue;
1919

2020
import java.io.ByteArrayInputStream;
2121
import java.util.ArrayList;
@@ -35,22 +35,20 @@
3535
import org.eclipse.ui.internal.Workbench;
3636
import org.eclipse.ui.internal.keys.BindingService;
3737
import org.eclipse.ui.keys.IBindingService;
38-
import org.eclipse.ui.tests.harness.util.CloseTestWindowsRule;
38+
import org.eclipse.ui.tests.harness.util.CloseTestWindowsExtension;
3939
import org.eclipse.ui.tests.harness.util.FileUtil;
4040
import org.eclipse.ui.texteditor.AbstractTextEditor;
41-
import org.junit.Rule;
42-
import org.junit.Test;
41+
import org.junit.jupiter.api.Test;
42+
import org.junit.jupiter.api.extension.ExtendWith;
4343

4444
/**
4545
* Tests Bug 43321
4646
*
4747
* @since 3.0
4848
*/
49+
@ExtendWith(CloseTestWindowsExtension.class)
4950
public class Bug43321Test {
5051

51-
@Rule
52-
public CloseTestWindowsRule closeTestWindows = new CloseTestWindowsRule();
53-
5452
/**
5553
* Tests that non-check box items on the menu are not checked when activated
5654
* from the keyboard.
@@ -88,7 +86,7 @@ public void testNoCheckOnNonCheckbox() throws CommandException,
8886
// Get the menu item we've just selected.
8987
IAction action = editor.getEditorSite().getActionBars()
9088
.getGlobalActionHandler(ActionFactory.COPY.getId());
91-
assertTrue("Non-checkbox menu item is checked.", !action.isChecked()); //$NON-NLS-1$
89+
assertTrue(!action.isChecked(), "Non-checkbox menu item is checked."); //$NON-NLS-1$
9290

9391
FileUtil.deleteProject(testProject);
9492
}

0 commit comments

Comments
 (0)