Skip to content

Commit 4ba0593

Browse files
committed
Migrate org.eclipse.jface.text.tests to JUnit 5 (excluding CodeMiningTest)
Migrated most tests in the bundle to JUnit 5. CodeMiningTest is excluded and will be handled in a separate PR.
1 parent f2cf3b4 commit 4ba0593

14 files changed

+97
-90
lines changed

tests/org.eclipse.jface.text.tests/META-INF/MANIFEST.MF

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ Automatic-Module-Name: org.eclipse.jface.text.tests
2929
Import-Package: org.mockito,
3030
org.mockito.invocation,
3131
org.mockito.stubbing,
32+
org.opentest4j,
3233
org.junit.jupiter.api;version="[5.14.0,6.0.0)",
34+
org.junit.jupiter.api.extension;version="[5.14.0,6.0.0)",
3335
org.junit.jupiter.api.function;version="[5.14.0,6.0.0)",
3436
org.junit.jupiter.params;version="[5.14.0,6.0.0)",
3537
org.junit.jupiter.params.provider;version="[5.14.0,6.0.0)",

tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/AbstractPairMatcherTest.java

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

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

2222
import java.util.ArrayList;
2323
import java.util.List;
2424

25-
import org.junit.Test;
25+
import org.junit.jupiter.api.Test;
2626

2727
import org.eclipse.jface.text.BadLocationException;
2828
import org.eclipse.jface.text.Document;

tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/AbstractUndoManagerTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
*******************************************************************************/
1414
package org.eclipse.jface.text.tests;
1515

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

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

2525
import org.eclipse.swt.SWT;
2626
import org.eclipse.swt.widgets.Shell;
@@ -62,7 +62,7 @@ public abstract class AbstractUndoManagerTest {
6262
private static final boolean DEBUG= false;
6363

6464

65-
@Before
65+
@BeforeEach
6666
public void setUp() {
6767
fShell= new Shell();
6868
fUndoManager= createUndoManager(MAX_UNDO_LEVEL);
@@ -73,7 +73,7 @@ public void setUp() {
7373

7474
abstract protected IUndoManager createUndoManager(int maxUndoLevel);
7575

76-
@After
76+
@AfterEach
7777
public void tearDown() {
7878
fUndoManager.disconnect();
7979
fUndoManager= null;

tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/DefaultPairMatcherTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*******************************************************************************/
1414
package org.eclipse.jface.text.tests;
1515

16-
import org.junit.Test;
16+
import org.junit.jupiter.api.Test;
1717

1818
import org.eclipse.jface.text.BadLocationException;
1919
import org.eclipse.jface.text.source.ICharacterPairMatcher;

tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/DefaultPairMatcherTest2.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*******************************************************************************/
1414
package org.eclipse.jface.text.tests;
1515

16-
import org.junit.Test;
16+
import org.junit.jupiter.api.Test;
1717

1818
import org.eclipse.jface.text.BadLocationException;
1919
import org.eclipse.jface.text.source.ICharacterPairMatcher;

tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/ProjectionViewerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
*******************************************************************************/
1111
package org.eclipse.jface.text.tests;
1212

13-
import static org.junit.Assert.assertTrue;
1413
import static org.junit.jupiter.api.Assertions.assertEquals;
1514
import static org.junit.jupiter.api.Assertions.assertFalse;
1615
import static org.junit.jupiter.api.Assertions.assertThrows;
16+
import static org.junit.jupiter.api.Assertions.assertTrue;
1717

1818
import org.junit.jupiter.api.Test;
1919
import org.junit.jupiter.params.ParameterizedTest;

tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextViewerTest.java

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,21 @@
1616
*******************************************************************************/
1717
package org.eclipse.jface.text.tests;
1818

19-
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertTrue;
21-
import static org.junit.Assert.fail;
22-
import static org.junit.Assume.assumeNotNull;
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertNotNull;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
22+
import static org.junit.jupiter.api.Assertions.fail;
23+
import static org.junit.jupiter.api.Assumptions.assumeFalse;
2324

2425
import java.util.Arrays;
2526
import java.util.concurrent.atomic.AtomicBoolean;
2627
import java.util.stream.Collectors;
2728

28-
import org.junit.Assume;
29-
import org.junit.Before;
30-
import org.junit.Rule;
31-
import org.junit.Test;
32-
import org.junit.rules.TestWatcher;
29+
import org.junit.jupiter.api.BeforeEach;
30+
import org.junit.jupiter.api.Test;
31+
import org.junit.jupiter.api.extension.ExtensionContext;
32+
import org.junit.jupiter.api.extension.RegisterExtension;
33+
import org.junit.jupiter.api.extension.TestWatcher;
3334

3435
import org.eclipse.test.Screenshots;
3536

@@ -81,13 +82,18 @@ public class TextViewerTest {
8182

8283
private Shell fShell;
8384

84-
@Before
85+
@BeforeEach
8586
public void before() {
8687
fShell= new Shell();
8788
}
8889

89-
@Rule
90-
public TestWatcher screenshotRule= Screenshots.onFailure(() -> fShell);
90+
@RegisterExtension
91+
public TestWatcher screenshotRule = new TestWatcher() {
92+
@Override
93+
public void testFailed(ExtensionContext context, Throwable cause) {
94+
Screenshots.takeScreenshot(TextViewerTest.class, context.getDisplayName());
95+
}
96+
};
9197

9298
@Test
9399
public void testSetRedraw_Bug441827() throws Exception {
@@ -185,7 +191,7 @@ private void checkInAndOutUIThread(Runnable r) throws InterruptedException {
185191

186192
@Test
187193
public void testCtrlHomeViewportListener() {
188-
Assume.assumeFalse("See bug 541415. For whatever reason, this shortcut doesn't work on Mac", Util.isMac());
194+
assumeFalse(Util.isMac(), "See bug 541415. For whatever reason, this shortcut doesn't work on Mac");
189195
fShell.setLayout(new FillLayout());
190196
fShell.setSize(500, 200);
191197
SourceViewer textViewer= new SourceViewer(fShell, null, SWT.NONE);
@@ -207,7 +213,7 @@ protected boolean condition() {
207213

208214
@Test
209215
public void testCtrlEndViewportListener() {
210-
Assume.assumeFalse("See bug 541415. For whatever reason, this shortcut doesn't work on Mac", Util.isMac());
216+
assumeFalse(Util.isMac(), "See bug 541415. For whatever reason, this shortcut doesn't work on Mac");
211217
fShell.setLayout(new FillLayout());
212218
fShell.setSize(500, 200);
213219
SourceViewer textViewer= new SourceViewer(fShell, null, SWT.NONE);
@@ -240,43 +246,43 @@ public void testDefaultContentImplementation() {
240246
fail("Failed to obtain default instance of TextViewers document adapter. " + ex.getMessage());
241247
return;
242248
}
243-
assumeNotNull(content);
249+
assertNotNull(content);
244250

245251
final String line0= "Hello ";
246252
final String line1= "";
247253
final String line2= "World!";
248254
final String text= line0 + "\n" + line1 + "\r\n" + line2;
249255
content.setText(text);
250-
assertEquals("Get text range failed.", "H", content.getTextRange(0, 1));
251-
assertEquals("Get text range failed.", "ll", content.getTextRange(2, 2));
252-
assertEquals("Adapter content length wrong.", text.length(), content.getCharCount());
253-
assertEquals("Adapter returned wrong content.", line0, content.getLine(0));
254-
assertEquals("Adapter returned wrong content.", line1, content.getLine(1));
255-
assertEquals("Adapter returned wrong content.", line2, content.getLine(2));
256+
assertEquals("H", content.getTextRange(0, 1), "Get text range failed.");
257+
assertEquals("ll", content.getTextRange(2, 2), "Get text range failed.");
258+
assertEquals(text.length(), content.getCharCount(), "Adapter content length wrong.");
259+
assertEquals(line0, content.getLine(0), "Adapter returned wrong content.");
260+
assertEquals(line1, content.getLine(1), "Adapter returned wrong content.");
261+
assertEquals(line2, content.getLine(2), "Adapter returned wrong content.");
256262

257263
content.setText("\r\n\r\n");
258-
assertEquals("Wrong line for offset.", 0, content.getLineAtOffset(0));
259-
assertEquals("Wrong line for offset.", 0, content.getLineAtOffset(1));
260-
assertEquals("Wrong line for offset.", 1, content.getLineAtOffset(2));
261-
assertEquals("Wrong line for offset.", 1, content.getLineAtOffset(3));
262-
assertEquals("Wrong line for offset.", 2, content.getLineAtOffset(4));
263-
assertEquals("Wrong line for offset.", content.getLineCount() - 1, content.getLineAtOffset(content.getCharCount()));
264+
assertEquals(0, content.getLineAtOffset(0), "Wrong line for offset.");
265+
assertEquals(0, content.getLineAtOffset(1), "Wrong line for offset.");
266+
assertEquals(1, content.getLineAtOffset(2), "Wrong line for offset.");
267+
assertEquals(1, content.getLineAtOffset(3), "Wrong line for offset.");
268+
assertEquals(2, content.getLineAtOffset(4), "Wrong line for offset.");
269+
assertEquals(content.getLineCount() - 1, content.getLineAtOffset(content.getCharCount()), "Wrong line for offset.");
264270

265271
content.setText(null);
266-
assertEquals("Adapter returned wrong line count.", 1, content.getLineCount());
272+
assertEquals(1, content.getLineCount(), "Adapter returned wrong line count.");
267273
content.setText("");
268-
assertEquals("Adapter returned wrong line count.", 1, content.getLineCount());
274+
assertEquals(1, content.getLineCount(), "Adapter returned wrong line count.");
269275
content.setText("a\n");
270-
assertEquals("Adapter returned wrong line count.", 2, content.getLineCount());
276+
assertEquals(2, content.getLineCount(), "Adapter returned wrong line count.");
271277
content.setText("\n\n");
272-
assertEquals("Adapter returned wrong line count.", 3, content.getLineCount());
278+
assertEquals(3, content.getLineCount(), "Adapter returned wrong line count.");
273279

274280
content.setText("\r\ntest\r\n");
275-
assertEquals("Wrong offset for line.", 0, content.getOffsetAtLine(0));
276-
assertEquals("Wrong offset for line.", 2, content.getOffsetAtLine(1));
277-
assertEquals("Wrong offset for line.", 8, content.getOffsetAtLine(2));
281+
assertEquals(0, content.getOffsetAtLine(0), "Wrong offset for line.");
282+
assertEquals(2, content.getOffsetAtLine(1), "Wrong offset for line.");
283+
assertEquals(8, content.getOffsetAtLine(2), "Wrong offset for line.");
278284
content.setText("");
279-
assertEquals("Wrong offset for line.", 0, content.getOffsetAtLine(0));
285+
assertEquals(0, content.getOffsetAtLine(0), "Wrong offset for line.");
280286
}
281287

282288
public static void ctrlEnd(ITextViewer viewer) {

tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextViewerUndoManagerTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
*******************************************************************************/
1414
package org.eclipse.jface.text.tests;
1515

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

21-
import org.junit.Test;
21+
import org.junit.jupiter.api.Test;
2222

2323
import org.eclipse.core.commands.ExecutionException;
2424
import org.eclipse.core.commands.operations.AbstractOperation;

tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/contentassist/AbstractContentAssistTest.java

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

1515
package org.eclipse.jface.text.tests.contentassist;
1616

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

2020
import java.util.Arrays;
2121
import java.util.Collection;
2222
import java.util.List;
2323

24-
import org.junit.After;
25-
import org.junit.Assert;
26-
import org.junit.Before;
24+
import org.junit.jupiter.api.AfterEach;
25+
import org.junit.jupiter.api.BeforeEach;
2726

2827
import org.eclipse.swt.SWT;
2928
import org.eclipse.swt.custom.ST;
@@ -60,7 +59,7 @@ public class AbstractContentAssistTest {
6059
public AbstractContentAssistTest() {
6160
}
6261

63-
@Before
62+
@BeforeEach
6463
public void setUp() {
6564
Shell[] shells= Display.getDefault().getShells();
6665
for (Shell s : shells) {
@@ -69,7 +68,7 @@ public void setUp() {
6968
DisplayHelper.runEventLoop(Display.getDefault(), 0);
7069
}
7170

72-
@After
71+
@AfterEach
7372
public void close() {
7473
if (shell != null && !shell.isDisposed()) {
7574
shell.close();
@@ -102,7 +101,7 @@ protected void setupSourceViewer(ContentAssistant contentAssistant, String initi
102101

103102
shell.open();
104103
processEvents();
105-
Assert.assertTrue(new DisplayHelper() {
104+
assertTrue(new DisplayHelper() {
106105
@Override
107106
protected boolean condition() {
108107
return viewer.getTextWidget().isVisible();
@@ -234,7 +233,7 @@ protected static Shell findNewShell(Collection<Shell> beforeShells) {
234233
DisplayHelper.sleep(getDisplay(), 100);
235234
afterShells= findNewShells(beforeShells);
236235
}
237-
assertEquals("Not unique new shell found", 1, afterShells.size());
236+
assertEquals(1, afterShells.size(), "Not unique new shell found");
238237
return afterShells.get(0);
239238
}
240239

tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/contentassist/AsyncContentAssistTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import static org.junit.jupiter.api.Assertions.assertNotNull;
1818
import static org.junit.jupiter.api.Assertions.assertNull;
1919
import static org.junit.jupiter.api.Assertions.assertTrue;
20-
import static org.junit.Assume.assumeFalse;
20+
import static org.junit.jupiter.api.Assumptions.assumeFalse;
2121

2222
import java.util.Arrays;
2323
import java.util.Collection;
@@ -134,7 +134,7 @@ protected boolean condition() {
134134

135135
@Test
136136
public void testCompleteActivationChar() {
137-
assumeFalse("test fails on Windows, see https://github.com/eclipse-platform/eclipse.platform.ui/issues/890", Util.isWindows());
137+
assumeFalse(Util.isWindows(), "test fails on Windows, see https://github.com/eclipse-platform/eclipse.platform.ui/issues/890");
138138
shell.setLayout(new FillLayout());
139139
shell.setSize(500, 300);
140140
SourceViewer viewer= new SourceViewer(shell, null, SWT.NONE);

0 commit comments

Comments
 (0)