Skip to content

Commit d8eb08e

Browse files
committed
Migrate org.eclipse.ui.editors.tests to JUnit 5
1 parent c616082 commit d8eb08e

24 files changed

+441
-461
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ Export-Package: org.eclipse.jface.text.tests.codemining,
1010
org.eclipse.ui.internal.texteditor.stickyscroll
1111
Require-Bundle:
1212
org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)",
13-
org.junit;bundle-version="4.12.0",
1413
org.eclipse.jface;bundle-version="[3.5.0,4.0.0)",
1514
org.eclipse.text;bundle-version="[3.5.0,4.0.0)",
1615
org.eclipse.ui.workbench.texteditor;bundle-version="[3.16.500,4.0.0)",
@@ -27,7 +26,10 @@ Require-Bundle:
2726
org.eclipse.ui.tests.harness;bundle-version="1.8.0",
2827
org.mockito.mockito-core;bundle-version="5.12.0"
2928
Import-Package: org.junit.jupiter.api;version="[5.14.0,6.0.0)",
30-
org.junit.platform.suite.api;version="[1.14.0,2.0.0)"
29+
org.junit.jupiter.api.io;version="[5.14.0,6.0.0)",
30+
org.junit.platform.suite.api;version="[1.14.0,2.0.0)",
31+
org.hamcrest;version="[3.0.0,4.0.0)",
32+
org.hamcrest.core;version="[3.0.0,4.0.0)"
3133
Bundle-RequiredExecutionEnvironment: JavaSE-21
3234
Eclipse-BundleShape: dir
3335
Bundle-ActivationPolicy: lazy

tests/org.eclipse.ui.editors.tests/src/org/eclipse/jface/text/tests/codemining/CodeMiningTest.java

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@
1010
*******************************************************************************/
1111
package org.eclipse.jface.text.tests.codemining;
1212

13-
import static org.junit.Assert.assertTrue;
13+
import static org.junit.jupiter.api.Assertions.assertTrue;
1414

1515
import java.io.ByteArrayInputStream;
1616
import java.text.SimpleDateFormat;
1717
import java.util.Date;
1818
import java.util.HashMap;
1919
import java.util.concurrent.Callable;
2020

21-
import org.junit.After;
22-
import org.junit.AfterClass;
23-
import org.junit.Assert;
24-
import org.junit.BeforeClass;
25-
import org.junit.Test;
21+
import org.junit.jupiter.api.AfterAll;
22+
import org.junit.jupiter.api.AfterEach;
23+
import org.junit.jupiter.api.Assertions;
24+
import org.junit.jupiter.api.BeforeAll;
25+
import org.junit.jupiter.api.Test;
2626

2727
import org.eclipse.swt.custom.StyleRange;
2828
import org.eclipse.swt.custom.StyledText;
@@ -65,20 +65,20 @@ public class CodeMiningTest {
6565

6666
private static IProject project;
6767

68-
@BeforeClass
69-
public static void beforeClass() throws Exception {
68+
@BeforeAll
69+
static void beforeClass() throws Exception {
7070
hideWelcomePage();
7171
createProject(PROJECT_NAME);
7272
}
7373

74-
@AfterClass
75-
public static void afterClass() throws Exception {
74+
@AfterAll
75+
static void afterClass() throws Exception {
7676
if (project != null)
7777
project.delete(true, new NullProgressMonitor());
7878
}
7979

80-
@After
81-
public void after() {
80+
@AfterEach
81+
void after() {
8282
closeAllEditors();
8383
drainEventQueue();
8484
CodeMiningTestProvider.provideContentMiningAtOffset = -1;
@@ -112,7 +112,7 @@ public void run(IProgressMonitor monitor) throws CoreException {
112112
}
113113

114114
@Test
115-
public void testClearCodeMiningTextEditorDecorationIfInInvisibleArea() throws Exception {
115+
void testClearCodeMiningTextEditorDecorationIfInInvisibleArea() throws Exception {
116116
IFile file = project.getFile("test.testprojectionviewer");
117117
if (file.exists()) {
118118
file.delete(true, new NullProgressMonitor());
@@ -144,7 +144,7 @@ public Boolean call() throws Exception {
144144
}
145145
});
146146
StyleRange style = styledText.getStyleRangeAtOffset(offsetAtLine95 - 1);
147-
assertTrue(style.metrics.width > 0);
147+
assertTrue(style != null && style.metrics != null && style.metrics.width > 0);
148148
// scroll to top so that code minings are not in visible area
149149
viewer.setSelectedRange(0, 0);
150150
viewer.revealRange(0, 1);
@@ -156,14 +156,14 @@ public Boolean call() throws Exception {
156156
// assert that line vertical height and styleRange was removed after
157157
// deleting the codeminings
158158
for (int i = 0; i < 100; i++) {
159-
assertTrue("line vertical indent not zeri at line index " + i, styledText.getLineVerticalIndent(i) == 0);
159+
assertTrue(styledText.getLineVerticalIndent(i) == 0, "line vertical indent not zeri at line index " + i);
160160
}
161161
style = styledText.getStyleRangeAtOffset(offsetAtLine95 - 1);
162162
assertTrue(style == null);
163163
}
164164

165165
@Test
166-
public void testInlinedAnnotationSupportIsInLinesReturnsValidResultAfterDocumentChange() throws Exception {
166+
void testInlinedAnnotationSupportIsInLinesReturnsValidResultAfterDocumentChange() throws Exception {
167167
IFile file = project.getFile("test.testprojectionviewer");
168168
if (file.exists()) {
169169
file.delete(true, new NullProgressMonitor());
@@ -185,8 +185,7 @@ public void testInlinedAnnotationSupportIsInLinesReturnsValidResultAfterDocument
185185
additions.put(annot, new Position(0, source.length()));
186186
annotationModel.modifyAnnotations(deletionsArray, additions, null);
187187

188-
Assert.assertTrue("Line header code mining above 3rd line not drawn",
189-
waitForCondition(widget.getDisplay(), 2000, new Callable<Boolean>() {
188+
Assertions.assertTrue(waitForCondition(widget.getDisplay(), 2000, new Callable<Boolean>() {
190189
@Override
191190
public Boolean call() throws Exception {
192191
try {
@@ -196,14 +195,13 @@ public Boolean call() throws Exception {
196195
return false;
197196
}
198197
}
199-
}));
198+
}), "Line header code mining above 3rd line not drawn");
200199

201200
IDocument doc = viewer.getDocument();
202201
widget.setCaretOffset(offset);
203202
doc.replace(offset, 0, "\n insert text");
204203
drainEventQueue();
205-
Assert.assertTrue("Line header code mining above 4th line after inserting text not drawn",
206-
waitForCondition(widget.getDisplay(), 2000, new Callable<Boolean>() {
204+
Assertions.assertTrue(waitForCondition(widget.getDisplay(), 2000, new Callable<Boolean>() {
207205
@Override
208206
public Boolean call() throws Exception {
209207
try {
@@ -213,11 +211,11 @@ public Boolean call() throws Exception {
213211
return false;
214212
}
215213
}
216-
}));
214+
}), "Line header code mining above 4th line after inserting text not drawn");
217215
}
218216

219217
@Test
220-
public void testCodeMiningOnEmptyLine() throws Exception {
218+
void testCodeMiningOnEmptyLine() throws Exception {
221219
IFile file = project.getFile("test.txt");
222220
if (file.exists()) {
223221
file.delete(true, new NullProgressMonitor());
@@ -230,21 +228,19 @@ public void testCodeMiningOnEmptyLine() throws Exception {
230228
drainEventQueue();
231229
ISourceViewer viewer = (ISourceViewer) editor.getAdapter(ITextViewer.class);
232230
StyledText widget = viewer.getTextWidget();
233-
Assert.assertTrue("line content mining not available",
234-
waitForCondition(widget.getDisplay(), 1000, new Callable<Boolean>() {
231+
Assertions.assertTrue(waitForCondition(widget.getDisplay(), 1000, new Callable<Boolean>() {
235232
@Override
236233
public Boolean call() throws Exception {
237234
return widget.getStyleRangeAtOffset(0) != null
238235
&& widget.getStyleRangeAtOffset(0).metrics != null;
239236
}
240-
}));
237+
}), "line content mining not available");
241238
drainEventQueue();
242239

243240
CodeMiningTestProvider.provideHeaderMiningAtLine = 1;
244241
((ISourceViewerExtension5) viewer).updateCodeMinings();
245242

246-
Assert.assertTrue("Code mining not drawn at empty line after calling updateCodeMinings",
247-
waitForCondition(widget.getDisplay(), 2000, new Callable<Boolean>() {
243+
Assertions.assertTrue(waitForCondition(widget.getDisplay(), 2000, new Callable<Boolean>() {
248244
@Override
249245
public Boolean call() throws Exception {
250246
try {
@@ -254,11 +250,11 @@ public Boolean call() throws Exception {
254250
return false;
255251
}
256252
}
257-
}));
253+
}), "Code mining not drawn at empty line after calling updateCodeMinings");
258254
}
259255

260256
@Test
261-
public void testCodeMiningAtEndOfLine() throws Exception {
257+
void testCodeMiningAtEndOfLine() throws Exception {
262258
IFile file = project.getFile("test.txt");
263259
if (file.exists()) {
264260
file.delete(true, new NullProgressMonitor());
@@ -273,21 +269,19 @@ public void testCodeMiningAtEndOfLine() throws Exception {
273269
drainEventQueue();
274270
ISourceViewer viewer = (ISourceViewer) editor.getAdapter(ITextViewer.class);
275271
StyledText widget = viewer.getTextWidget();
276-
Assert.assertTrue("line content mining not available",
277-
waitForCondition(widget.getDisplay(), 1000, new Callable<Boolean>() {
272+
Assertions.assertTrue(waitForCondition(widget.getDisplay(), 1000, new Callable<Boolean>() {
278273
@Override
279274
public Boolean call() throws Exception {
280275
return widget.getStyleRangeAtOffset(0) != null
281276
&& widget.getStyleRangeAtOffset(0).metrics != null;
282277
}
283-
}));
278+
}), "line content mining not available");
284279
drainEventQueue();
285280

286281
CodeMiningTestProvider.provideContentMiningAtOffset = firstPart.length();
287282
((ISourceViewerExtension5) viewer).updateCodeMinings();
288283

289-
Assert.assertTrue("Code mining not drawn at the end of second line after calling updateCodeMinings",
290-
waitForCondition(widget.getDisplay(), 2000, new Callable<Boolean>() {
284+
Assertions.assertTrue(waitForCondition(widget.getDisplay(), 2000, new Callable<Boolean>() {
291285
@Override
292286
public Boolean call() throws Exception {
293287
try {
@@ -297,7 +291,7 @@ public Boolean call() throws Exception {
297291
return false;
298292
}
299293
}
300-
}));
294+
}), "Code mining not drawn at the end of second line after calling updateCodeMinings");
301295
}
302296

303297
private void drainEventQueue() {
@@ -411,4 +405,4 @@ private final boolean waitForCondition(Display display, long timeout, Callable<B
411405
} while (!cond && diff < timeout);
412406
return cond;
413407
}
414-
}
408+
}

tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/CaseActionTest.java

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

16-
import static org.junit.Assert.assertArrayEquals;
17-
import static org.junit.Assert.assertEquals;
16+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
17+
import static org.junit.jupiter.api.Assertions.assertEquals;
1818

1919
import java.io.ByteArrayInputStream;
2020

21-
import org.junit.After;
22-
import org.junit.AfterClass;
23-
import org.junit.Before;
24-
import org.junit.BeforeClass;
25-
import org.junit.Test;
21+
import org.junit.jupiter.api.AfterAll;
22+
import org.junit.jupiter.api.AfterEach;
23+
import org.junit.jupiter.api.BeforeAll;
24+
import org.junit.jupiter.api.BeforeEach;
25+
import org.junit.jupiter.api.Test;
2626

2727
import org.eclipse.core.runtime.NullProgressMonitor;
2828

@@ -44,30 +44,30 @@
4444
import org.eclipse.ui.texteditor.AbstractTextEditor;
4545
import org.eclipse.ui.texteditor.ITextEditorActionConstants;
4646

47-
public class CaseActionTest {
47+
class CaseActionTest {
4848

4949
private static IProject project;
5050
private static IFile file;
5151
private AbstractTextEditor editor;
5252

53-
@BeforeClass
54-
public static void setUpBeforeClass() throws Exception {
53+
@BeforeAll
54+
static void setUpBeforeClass() throws Exception {
5555
project = ResourcesPlugin.getWorkspace().getRoot().getProject("test");
5656
project.create(new NullProgressMonitor());
5757
project.open(new NullProgressMonitor());
5858
file = project.getFile("foo.txt");
5959
file.create(new ByteArrayInputStream("bar".getBytes()), true, new NullProgressMonitor());
6060
}
6161

62-
@AfterClass
63-
public static void tearDownAfterClass() throws Exception {
62+
@AfterAll
63+
static void tearDownAfterClass() throws Exception {
6464
file.delete(true, new NullProgressMonitor());
6565
project.delete(true, new NullProgressMonitor());
6666
TestUtil.cleanUp();
6767
}
6868

69-
@Before
70-
public void setUp() throws Exception {
69+
@BeforeEach
70+
void setUp() throws Exception {
7171
IIntroPart intro = PlatformUI.getWorkbench().getIntroManager().getIntro();
7272
if (intro != null) {
7373
PlatformUI.getWorkbench().getIntroManager().closeIntro(intro);
@@ -80,14 +80,14 @@ public void setUp() throws Exception {
8080
// make sure we start from a clean state
8181
}
8282

83-
@After
84-
public void tearDown() throws Exception {
83+
@AfterEach
84+
void tearDown() throws Exception {
8585
editor.close(false);
8686
editor= null;
8787
}
8888

8989
@Test
90-
public void testMultiSelectionCase() {
90+
void testMultiSelectionCase() {
9191
IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
9292
doc.set("foo bar foo");
9393
IRegion[] initialSelection = { new Region(0,3), new Region(8, 3) };
@@ -109,4 +109,4 @@ public void testMultiSelectionCase() {
109109
}, ((IMultiTextSelection) editor.getSelectionProvider().getSelection()).getRegions());
110110
}
111111

112-
}
112+
}

tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/ChainedPreferenceStoreTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414

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

17-
import static org.junit.Assert.assertEquals;
17+
import static org.junit.jupiter.api.Assertions.assertEquals;
1818

1919
import java.util.ArrayList;
2020
import java.util.List;
2121

22-
import org.junit.After;
23-
import org.junit.Test;
22+
import org.junit.jupiter.api.AfterEach;
23+
import org.junit.jupiter.api.Test;
2424

2525
import org.eclipse.jface.preference.IPreferenceStore;
2626
import org.eclipse.jface.preference.PreferenceStore;
@@ -47,8 +47,8 @@ public void propertyChange(PropertyChangeEvent event) {
4747
private static final String DEFAULT_VALUE= "4";
4848
private static final String DEFAULT_DEFAULT_VALUE= "";
4949

50-
@After
51-
public void tearDown() {
50+
@AfterEach
51+
void tearDown() {
5252
TestUtil.cleanUp();
5353
}
5454

@@ -57,7 +57,7 @@ public void tearDown() {
5757
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=69419
5858
*/
5959
@Test
60-
public void testChainedStore0() {
60+
void testChainedStore0() {
6161
IPreferenceStore store1= new PreferenceStore();
6262
IPreferenceStore store2= new PreferenceStore();
6363
IPreferenceStore chainedStore= new ChainedPreferenceStore(new IPreferenceStore[] { store1, store2 });
@@ -80,7 +80,7 @@ public void testChainedStore0() {
8080
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=52827
8181
*/
8282
@Test
83-
public void testChainedStore1() {
83+
void testChainedStore1() {
8484
IPreferenceStore store1= new PreferenceStore();
8585
IPreferenceStore store2= new PreferenceStore();
8686
IPreferenceStore chainedStore= new ChainedPreferenceStore(new IPreferenceStore[] { store1, store2 });
@@ -101,7 +101,7 @@ public void testChainedStore1() {
101101
* Third case where the initial implementation used to have an assertion which would fail in this case
102102
*/
103103
@Test
104-
public void testChainedStore2() {
104+
void testChainedStore2() {
105105
IPreferenceStore store1= new PreferenceStore();
106106
IPreferenceStore store2= new PreferenceStore();
107107
IPreferenceStore chainedStore= new ChainedPreferenceStore(new IPreferenceStore[] { store1, store2 });
@@ -123,7 +123,7 @@ public void testChainedStore2() {
123123
* Case where the initial implementation used to throw an IAE
124124
*/
125125
@Test
126-
public void testChainedStore3() {
126+
void testChainedStore3() {
127127
IPreferenceStore store1= new PreferenceStore();
128128
IPreferenceStore store2= new PreferenceStore();
129129
IPreferenceStore chainedStore= new ChainedPreferenceStore(new IPreferenceStore[] { store1, store2 });

0 commit comments

Comments
 (0)