Skip to content

Commit c810e66

Browse files
committed
Convert LeastTests to JUnit 5
1 parent da48e88 commit c810e66

3 files changed

Lines changed: 26 additions & 35 deletions

File tree

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/leaks/Bug397302Tests.java

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2013, 2017 IBM Corporation and others.
2+
* Copyright (c) 2013, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -14,24 +14,21 @@
1414

1515
package org.eclipse.ui.tests.leaks;
1616

17+
import static org.junit.jupiter.api.Assertions.assertEquals;
18+
import static org.junit.jupiter.api.Assertions.assertNull;
19+
1720
import java.lang.ref.WeakReference;
1821
import java.util.Collections;
1922
import java.util.Map;
2023

2124
import org.eclipse.ui.AbstractSourceProvider;
2225
import org.eclipse.ui.ISourceProviderListener;
23-
import org.eclipse.ui.tests.harness.util.TestRunLogUtil;
24-
import org.junit.Assert;
25-
import org.junit.Rule;
26-
import org.junit.Test;
27-
import org.junit.rules.TestWatcher;
26+
import org.junit.jupiter.api.Test;
2827

2928
/**
3029
* @since 3.5
3130
*/
3231
public class Bug397302Tests {
33-
@Rule
34-
public TestWatcher LOG_TESTRUN = TestRunLogUtil.LOG_TESTRUN;
3532

3633
/**
3734
* @since 3.5
@@ -68,7 +65,7 @@ public void dispose() {
6865

6966
@Override
7067
public Map getCurrentState() {
71-
return Collections.EMPTY_MAP;
68+
return Collections.emptyMap();
7269
}
7370

7471
@Override
@@ -77,7 +74,7 @@ public String[] getProvidedSourceNames() {
7774
}
7875

7976
public void callOut() {
80-
this.fireSourceChanged(0, Collections.EMPTY_MAP);
77+
this.fireSourceChanged(0, Collections.emptyMap());
8178
}
8279

8380
}
@@ -100,17 +97,17 @@ public void testBugAsDescribed() {
10097

10198
testSourceProvider.callOut();
10299

103-
Assert.assertEquals(1, a.getCallCount());
104-
Assert.assertEquals(1, b.getCallCount());
100+
assertEquals(1, a.getCallCount());
101+
assertEquals(1, b.getCallCount());
105102

106103
// remove listeners, call out to them, and verify that they no longer got called
107104
testSourceProvider.removeSourceProviderListener(a);
108105
testSourceProvider.removeSourceProviderListener(b);
109106

110107
testSourceProvider.callOut();
111108

112-
Assert.assertEquals(1, a.getCallCount());
113-
Assert.assertEquals(1, b.getCallCount());
109+
assertEquals(1, a.getCallCount());
110+
assertEquals(1, b.getCallCount());
114111

115112
// loose our strong references to a & b, force a GC, and see whether either gets leaked.
116113
// Test: The bug asserts that B has been leaked. Force a GC, and test whether
@@ -121,8 +118,8 @@ public void testBugAsDescribed() {
121118

122119
System.gc();
123120

124-
Assert.assertNull("Reference A", listenerARef.get());
125-
Assert.assertNull("Reference B", listenerBRef.get());
121+
assertNull(listenerARef.get(), "Reference A");
122+
assertNull(listenerBRef.get(), "Reference B");
126123

127124
// Need this to prevent the above GC call from sweeping everything up before we're ready.
128125
// See this only when NOT in debug.

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/leaks/ContextEditorPart.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2014 IBM Corporation and others.
2+
* Copyright (c) 2014, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -40,13 +40,11 @@ public class ContextEditorPart extends EditorPart {
4040

4141
@Override
4242
public void doSave(IProgressMonitor arg0) {
43-
// TODO Auto-generated method stub
4443

4544
}
4645

4746
@Override
4847
public void doSaveAs() {
49-
// TODO Auto-generated method stub
5048

5149
}
5250

@@ -79,13 +77,11 @@ public void setSelection(ISelection selection) {
7977

8078
@Override
8179
public boolean isDirty() {
82-
// TODO Auto-generated method stub
8380
return false;
8481
}
8582

8683
@Override
8784
public boolean isSaveAsAllowed() {
88-
// TODO Auto-generated method stub
8985
return false;
9086
}
9187

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/leaks/LeakTests.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2004, 2021 IBM Corporation and others.
2+
* Copyright (c) 2004, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -17,8 +17,8 @@
1717

1818
import static org.eclipse.ui.tests.harness.util.UITestUtil.openTestWindow;
1919
import static org.eclipse.ui.tests.harness.util.UITestUtil.processEvents;
20-
import static org.junit.Assert.assertNotNull;
21-
import static org.junit.Assert.assertTrue;
20+
import static org.junit.jupiter.api.Assertions.assertNotNull;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
2222

2323
import java.lang.ref.PhantomReference;
2424
import java.lang.ref.Reference;
@@ -44,12 +44,12 @@
4444
import org.eclipse.ui.internal.part.NullEditorInput;
4545
import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
4646
import org.eclipse.ui.tests.api.MockViewPart;
47-
import org.eclipse.ui.tests.harness.util.CloseTestWindowsRule;
47+
import org.eclipse.ui.tests.harness.util.CloseTestWindowsExtension;
4848
import org.eclipse.ui.tests.harness.util.FileUtil;
49-
import org.junit.After;
50-
import org.junit.Before;
51-
import org.junit.Rule;
52-
import org.junit.Test;
49+
import org.junit.jupiter.api.AfterEach;
50+
import org.junit.jupiter.api.BeforeEach;
51+
import org.junit.jupiter.api.Test;
52+
import org.junit.jupiter.api.extension.ExtendWith;
5353

5454
/**
5555
* Very simple leak tests to determine if any of our heavy objects are not being
@@ -58,9 +58,8 @@
5858
*
5959
* @since 3.1
6060
*/
61+
@ExtendWith(CloseTestWindowsExtension.class)
6162
public class LeakTests {
62-
@Rule
63-
public final CloseTestWindowsRule closeTestWindows = new CloseTestWindowsRule();
6463

6564
private IWorkbenchPage fActivePage;
6665

@@ -72,7 +71,6 @@ public static void checkRef(ReferenceQueue<?> queue, Reference<?> ref)
7271
throws IllegalArgumentException, InterruptedException {
7372
boolean flag = false;
7473
for (int i = 0; i < 100; i++) {
75-
System.runFinalization();
7674
System.gc();
7775
Thread.yield();
7876
processEvents();
@@ -83,21 +81,21 @@ public static void checkRef(ReferenceQueue<?> queue, Reference<?> ref)
8381
}
8482
}
8583

86-
assertTrue("Reference not enqueued", flag);
84+
assertTrue(flag, "Reference not enqueued");
8785
}
8886

8987
@SuppressWarnings("unchecked")
9088
private Reference createReference(ReferenceQueue queue, Object object) {
9189
return new PhantomReference<>(object, queue);
9290
}
9391

94-
@Before
92+
@BeforeEach
9593
public final void setUp() throws Exception {
9694
fWin = openTestWindow(IDE.RESOURCE_PERSPECTIVE_ID);
9795
fActivePage = fWin.getActivePage();
9896
}
9997

100-
@After
98+
@AfterEach
10199
public final void tearDown() throws Exception {
102100
fWin = null;
103101
fActivePage = null;

0 commit comments

Comments
 (0)