Skip to content

Commit 633b9d4

Browse files
vogellaclaude
andcommitted
Migrate org.eclipse.ui.tests.navigator from JUnit 4 to JUnit 5
This commit migrates the entire org.eclipse.ui.tests.navigator test suite from JUnit 4 to JUnit 5, modernizing the test infrastructure and improving test reliability with better resource management. JUnit 5 Migration Changes: - Updated all test annotations (@before@beforeeach, @after → @AfterEach, @ignore@disabled) - Migrated static imports from org.junit.Assert to org.junit.jupiter.api.Assertions - Fixed all assertion parameter orders from JUnit 4 style (message-first) to JUnit 5 style (message-last): * assertEquals(message, expected, actual) → assertEquals(expected, actual, message) * assertTrue(message, condition) → assertTrue(condition, message) * assertFalse(message, condition) → assertFalse(condition, message) Test Infrastructure Improvements: - Added CloseTestWindowsExtension: A new JUnit 5 extension that automatically manages UI test windows and shell cleanup, replacing the previous JUnit 4 rule-based approach - Updated GoBackForwardsTest to use @RegisterExtension with the new extension - Ensures better test isolation by cleaning up leaked shells between tests Files Modified (32): - ActionProviderTest.java - ActivityTest.java - CloseTestWindowsExtension.java (new) - DecorationSchedulerRaceConditionTest.java - DnDTest.java - EvaluationCacheTest.java - ExtensionsTest.java - FilterTest.java - FirstClassM1Tests.java - GoBackForwardsTest.java - INavigatorContentServiceTests.java - InitialActivationTest.java - LabelProviderTest.java - LinkHelperTest.java - M12Tests.java - NavigatorTestBase.java - OpenTest.java - PerformanceTest.java - PipelineChainTest.java - PipelineTest.java - ProgrammaticOpenTest.java - ResourceTransferTest.java - ShowInTest.java - SorterTest.java - ViewerTest.java - WorkingSetTest.java - cdt/CdtTest.java - jst/JstPipelineTest.java - resources/FoldersAsProjectsContributionTest.java - resources/NestedResourcesTests.java - resources/PathComparatorTest.java - resources/ResourceMgmtActionProviderTests.java Benefits: - Uses modern JUnit 5 features and best practices - Improved resource cleanup prevents test interference - Consistent with Eclipse platform's migration to JUnit 5 - Better test isolation and reliability 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 39d028e commit 633b9d4

32 files changed

+331
-199
lines changed

tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/ActionProviderTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
*******************************************************************************/
1515
package org.eclipse.ui.tests.navigator;
1616

17-
import static org.junit.Assert.assertEquals;
18-
import static org.junit.Assert.assertNotNull;
19-
import static org.junit.Assert.assertNull;
17+
import static org.junit.jupiter.api.Assertions.assertEquals;
18+
import static org.junit.jupiter.api.Assertions.assertNotNull;
19+
import static org.junit.jupiter.api.Assertions.assertNull;
2020

2121
import java.util.ArrayList;
2222
import java.util.List;
@@ -33,7 +33,7 @@
3333
import org.eclipse.ui.tests.harness.util.DisplayHelper;
3434
import org.eclipse.ui.tests.navigator.extension.TestContentProvider;
3535
import org.eclipse.ui.tests.navigator.extension.TestExtensionTreeData;
36-
import org.junit.Test;
36+
import org.junit.jupiter.api.Test;
3737

3838
public class ActionProviderTest extends NavigatorTestBase {
3939

tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/ActivityTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*******************************************************************************/
1616
package org.eclipse.ui.tests.navigator;
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 java.util.HashSet;
2222
import java.util.Set;
@@ -25,7 +25,7 @@
2525
import org.eclipse.jface.viewers.StructuredSelection;
2626
import org.eclipse.ui.PlatformUI;
2727
import org.eclipse.ui.activities.IWorkbenchActivitySupport;
28-
import org.junit.Test;
28+
import org.junit.jupiter.api.Test;
2929

3030
public class ActivityTest extends NavigatorTestBase {
3131

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 IBM Corporation and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* IBM Corporation - initial API and implementation
13+
*******************************************************************************/
14+
15+
package org.eclipse.ui.tests.navigator;
16+
17+
import static org.eclipse.ui.tests.harness.util.UITestUtil.processEvents;
18+
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
20+
import java.util.ArrayList;
21+
import java.util.List;
22+
import java.util.Set;
23+
24+
import org.eclipse.swt.widgets.Shell;
25+
import org.eclipse.ui.IWindowListener;
26+
import org.eclipse.ui.IWorkbenchWindow;
27+
import org.eclipse.ui.PlatformUI;
28+
import org.junit.jupiter.api.extension.AfterEachCallback;
29+
import org.junit.jupiter.api.extension.BeforeEachCallback;
30+
import org.junit.jupiter.api.extension.ExtensionContext;
31+
32+
/**
33+
* JUnit 5 Extension for UI tests to clean up windows/shells:
34+
* <ul>
35+
* <li>prints the test name to the log before and after each test case
36+
* <li>closes windows opened during the test case
37+
* <li>checks for shells unintentionally leaked from the test case
38+
* </ul>
39+
*/
40+
public class CloseTestWindowsExtension implements BeforeEachCallback, AfterEachCallback {
41+
42+
private String testName;
43+
private final List<IWorkbenchWindow> testWindows = new ArrayList<>(3);
44+
private TestWindowListener windowListener;
45+
private Set<Shell> initialShells;
46+
private boolean leakChecksDisabled;
47+
48+
@Override
49+
public void beforeEach(ExtensionContext context) throws Exception {
50+
this.testName = context.getDisplayName();
51+
addWindowListener();
52+
storeInitialShells();
53+
trace(formatTestStartMessage(testName));
54+
}
55+
56+
@Override
57+
public void afterEach(ExtensionContext context) throws Exception {
58+
trace(formatTestFinishedMessage(testName));
59+
removeWindowListener();
60+
processEvents();
61+
closeAllTestWindows();
62+
processEvents();
63+
checkForLeakedShells();
64+
}
65+
66+
private static void trace(String msg) {
67+
System.out.println(msg);
68+
}
69+
70+
private void addWindowListener() {
71+
windowListener = new TestWindowListener();
72+
PlatformUI.getWorkbench().addWindowListener(windowListener);
73+
}
74+
75+
private void removeWindowListener() {
76+
if (windowListener != null) {
77+
PlatformUI.getWorkbench().removeWindowListener(windowListener);
78+
}
79+
}
80+
81+
private void closeAllTestWindows() {
82+
List<IWorkbenchWindow> testWindowsCopy = new ArrayList<>(testWindows);
83+
for (IWorkbenchWindow testWindow : testWindowsCopy) {
84+
testWindow.close();
85+
}
86+
testWindows.clear();
87+
}
88+
89+
private class TestWindowListener implements IWindowListener {
90+
@Override
91+
public void windowActivated(IWorkbenchWindow window) {
92+
// do nothing
93+
}
94+
95+
@Override
96+
public void windowDeactivated(IWorkbenchWindow window) {
97+
// do nothing
98+
}
99+
100+
@Override
101+
public void windowClosed(IWorkbenchWindow window) {
102+
testWindows.remove(window);
103+
}
104+
105+
@Override
106+
public void windowOpened(IWorkbenchWindow window) {
107+
testWindows.add(window);
108+
}
109+
}
110+
111+
private void storeInitialShells() {
112+
this.initialShells = Set.of(PlatformUI.getWorkbench().getDisplay().getShells());
113+
}
114+
115+
private void checkForLeakedShells() {
116+
List<String> leakedModalShellTitles = new ArrayList<>();
117+
Shell[] shells = PlatformUI.getWorkbench().getDisplay().getShells();
118+
for (Shell shell : shells) {
119+
if (!shell.isDisposed() && !initialShells.contains(shell)) {
120+
leakedModalShellTitles.add(shell.getText());
121+
shell.close();
122+
}
123+
}
124+
if (!leakChecksDisabled) {
125+
assertEquals(0, leakedModalShellTitles.size(),
126+
"Test leaked modal shell: [" + String.join(", ", leakedModalShellTitles) + "]");
127+
}
128+
}
129+
130+
public void disableLeakChecks() {
131+
this.leakChecksDisabled = true;
132+
}
133+
134+
private static String formatTestStartMessage(String testName) {
135+
return "----- " + testName + System.lineSeparator() + testName + ": setUp...";
136+
}
137+
138+
private static String formatTestFinishedMessage(String testName) {
139+
return testName + ": tearDown...\n";
140+
}
141+
142+
}

tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/DecorationSchedulerRaceConditionTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*******************************************************************************/
1414
package org.eclipse.ui.tests.navigator;
1515

16-
import static org.junit.Assert.assertEquals;
16+
import static org.junit.jupiter.api.Assertions.assertEquals;
1717

1818
import java.util.concurrent.Semaphore;
1919

@@ -32,9 +32,9 @@
3232
import org.eclipse.ui.tests.harness.util.DisplayHelper;
3333
import org.eclipse.ui.tests.navigator.extension.DecorationSchedulerRaceConditionTestDecorator;
3434
import org.eclipse.ui.tests.navigator.util.TestWorkspace;
35-
import org.junit.After;
36-
import org.junit.Before;
37-
import org.junit.Test;
35+
import org.junit.jupiter.api.AfterEach;
36+
import org.junit.jupiter.api.BeforeEach;
37+
import org.junit.jupiter.api.Test;
3838

3939
/**
4040
* @since 3.3
@@ -79,7 +79,7 @@ public DecorationSchedulerRaceConditionTest() {
7979
}
8080

8181
@Override
82-
@Before
82+
@BeforeEach
8383
public void setUp() throws CoreException {
8484
super.setUp();
8585

@@ -102,7 +102,7 @@ public void setUp() throws CoreException {
102102
assertEquals(TestWorkspace.P1_PROJECT_NAME + DECORATION_TEXT_1, rootItems[0].getText());
103103
}
104104

105-
@After
105+
@AfterEach
106106
public void resetDecoratorEnablement() throws CoreException {
107107
IDecoratorManager manager = PlatformUI.getWorkbench().getDecoratorManager();
108108
manager.setEnabled("org.eclipse.ui.tests.navigator.bug417255Decorator", false);

tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/DnDTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
*******************************************************************************/
1515
package org.eclipse.ui.tests.navigator;
1616

17-
import static org.junit.Assert.assertEquals;
18-
import static org.junit.Assert.assertFalse;
19-
import static org.junit.Assert.assertNotNull;
20-
import static org.junit.Assert.assertTrue;
17+
import static org.junit.jupiter.api.Assertions.assertEquals;
18+
import static org.junit.jupiter.api.Assertions.assertFalse;
19+
import static org.junit.jupiter.api.Assertions.assertNotNull;
20+
import static org.junit.jupiter.api.Assertions.assertTrue;
2121

2222
import org.eclipse.core.resources.IFile;
2323
import org.eclipse.jface.viewers.StructuredSelection;
@@ -31,7 +31,7 @@
3131
import org.eclipse.ui.tests.harness.util.DisplayHelper;
3232
import org.eclipse.ui.tests.harness.util.SWTEventHelper;
3333
import org.eclipse.ui.tests.navigator.extension.TestDragAssistant;
34-
import org.junit.Test;
34+
import org.junit.jupiter.api.Test;
3535

3636
public class DnDTest extends NavigatorTestBase {
3737

tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/EvaluationCacheTest.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
import org.eclipse.ui.navigator.INavigatorViewerDescriptor;
2424
import org.eclipse.ui.tests.navigator.util.TestNavigatorActivationService;
2525
import org.eclipse.ui.tests.navigator.util.TestNavigatorViewerDescriptor;
26-
import org.junit.Assert;
27-
import org.junit.Test;
26+
import org.junit.jupiter.api.Assertions;
27+
import org.junit.jupiter.api.Test;
2828

2929
/**
3030
* Tests the {@link EvaluationCache} to ensure it can find various key types as
@@ -51,9 +51,9 @@ private void doSimpleAddGet(boolean toComputeOverrides) {
5151
Object key = new Object();
5252
NavigatorContentDescriptor[] value = new NavigatorContentDescriptor[0];
5353
cache.setDescriptors(key, value, toComputeOverrides);
54-
Assert.assertSame(value, cache.getDescriptors(key, toComputeOverrides));
54+
Assertions.assertSame(value, cache.getDescriptors(key, toComputeOverrides));
5555
// The other "half" of the cache should not have this.
56-
Assert.assertNull(cache.getDescriptors(key, !toComputeOverrides));
56+
Assertions.assertNull(cache.getDescriptors(key, !toComputeOverrides));
5757
}
5858

5959
@Test
@@ -76,10 +76,10 @@ private void doNotSameInstEqual(boolean toComputeOverrides) {
7676
// Equal thing but different instance should still be equal.
7777
java.util.List key2 = new ArrayList<>(key);
7878
// Should also find it under this new, equal key.
79-
Assert.assertSame(value, cache.getDescriptors(key2, toComputeOverrides));
79+
Assertions.assertSame(value, cache.getDescriptors(key2, toComputeOverrides));
8080
// The other "half" of the cache should not have this for either key.
81-
Assert.assertNull(cache.getDescriptors(key, !toComputeOverrides));
82-
Assert.assertNull(cache.getDescriptors(key2, !toComputeOverrides));
81+
Assertions.assertNull(cache.getDescriptors(key, !toComputeOverrides));
82+
Assertions.assertNull(cache.getDescriptors(key2, !toComputeOverrides));
8383
}
8484

8585
@Test
@@ -96,10 +96,10 @@ private void doTestReplace(boolean toComputeOverrides) {
9696
Object key = new Object();
9797
NavigatorContentDescriptor[] value1 = new NavigatorContentDescriptor[0];
9898
cache.setDescriptors(key, value1, toComputeOverrides);
99-
Assert.assertSame(value1, cache.getDescriptors(key, toComputeOverrides));
99+
Assertions.assertSame(value1, cache.getDescriptors(key, toComputeOverrides));
100100
NavigatorContentDescriptor[] value2 = new NavigatorContentDescriptor[0];
101101
cache.setDescriptors(key, value2, toComputeOverrides);
102-
Assert.assertSame(value2, cache.getDescriptors(key, toComputeOverrides));
102+
Assertions.assertSame(value2, cache.getDescriptors(key, toComputeOverrides));
103103
}
104104

105105
@Test
@@ -118,14 +118,14 @@ public void testOnVisibilityOrActivationChangeClearsCaches() {
118118
NavigatorContentDescriptor[] value1 = new NavigatorContentDescriptor[0];
119119
cache.setDescriptors(key, value1, false);
120120
// Make sure they actually got inserted.
121-
Assert.assertSame(value1, cache.getDescriptors(key, false));
121+
Assertions.assertSame(value1, cache.getDescriptors(key, false));
122122
NavigatorContentDescriptor[] value2 = new NavigatorContentDescriptor[0];
123123
cache.setDescriptors(key, value2, true);
124-
Assert.assertSame(value2, cache.getDescriptors(key, true));
124+
Assertions.assertSame(value2, cache.getDescriptors(key, true));
125125
cache.onVisibilityOrActivationChange();
126126
// Now trying to find them should give null (non present).
127-
Assert.assertNull(cache.getDescriptors(key, false));
128-
Assert.assertNull(cache.getDescriptors(key, true));
127+
Assertions.assertNull(cache.getDescriptors(key, false));
128+
Assertions.assertNull(cache.getDescriptors(key, true));
129129
}
130130

131131
// TODO Some way to reliably test the clearing of entries. Possibly using

tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/ExtensionsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
*******************************************************************************/
1616
package org.eclipse.ui.tests.navigator;
1717

18-
import static org.junit.Assert.assertEquals;
18+
import static org.junit.jupiter.api.Assertions.assertEquals;
1919

2020
import org.eclipse.swt.widgets.Display;
2121
import org.eclipse.ui.internal.navigator.filters.CommonFilterSelectionDialog;
2222
import org.eclipse.ui.navigator.CommonViewer;
2323
import org.eclipse.ui.tests.harness.util.DisplayHelper;
24-
import org.junit.Test;
24+
import org.junit.jupiter.api.Test;
2525

2626
public class ExtensionsTest extends NavigatorTestBase {
2727

tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/FilterTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
*******************************************************************************/
1616
package org.eclipse.ui.tests.navigator;
1717

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

2121
import org.eclipse.swt.widgets.TreeItem;
2222
import org.eclipse.ui.internal.navigator.NavigatorContentService;
2323
import org.eclipse.ui.internal.navigator.NavigatorFilterService;
24-
import org.junit.Test;
24+
import org.junit.jupiter.api.Test;
2525

2626
public class FilterTest extends NavigatorTestBase {
2727

tests/org.eclipse.ui.tests.navigator/src/org/eclipse/ui/tests/navigator/FirstClassM1Tests.java

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

1616
package org.eclipse.ui.tests.navigator;
1717

18-
import static org.junit.Assert.assertEquals;
18+
import static org.junit.jupiter.api.Assertions.assertEquals;
1919

2020
import org.eclipse.swt.widgets.TreeItem;
2121
import org.eclipse.ui.tests.navigator.m12.model.M1Project;
22-
import org.junit.Test;
22+
import org.junit.jupiter.api.Test;
2323

2424
/**
2525
* M1/M2 tests with M1 as a first class provider (i.e. override policy set to

0 commit comments

Comments
 (0)