Skip to content

Commit 2336d9f

Browse files
committed
Migrate org.eclipse.ui.workbench.texteditor.tests to JUnit 5
1 parent 8cfdecd commit 2336d9f

19 files changed

+238
-237
lines changed

tests/org.eclipse.ui.workbench.texteditor.tests/META-INF/MANIFEST.MF

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ Automatic-Module-Name: org.eclipse.ui.workbench.texteditor.tests
2525
Import-Package: org.mockito,
2626
org.mockito.stubbing;version="5.5.0",
2727
org.junit.jupiter.api;version="[5.14.0,6.0.0)",
28-
org.junit.platform.suite.api;version="[1.14.0,2.0.0)"
28+
org.junit.jupiter.api.function;version="[5.14.0,6.0.0)",
29+
org.junit.platform.suite.api;version="[1.14.0,2.0.0)",
30+
org.opentest4j;version="[1.3.0,2.0.0)"

tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/FindReplaceLogicTest.java

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
import static org.hamcrest.Matchers.instanceOf;
2121
import static org.hamcrest.Matchers.is;
2222
import static org.hamcrest.Matchers.not;
23-
import static org.junit.Assert.assertEquals;
24-
import static org.junit.Assert.assertFalse;
25-
import static org.junit.Assert.assertTrue;
23+
import static org.junit.jupiter.api.Assertions.assertEquals;
24+
import static org.junit.jupiter.api.Assertions.assertFalse;
25+
import static org.junit.jupiter.api.Assertions.assertTrue;
2626
import static org.mockito.ArgumentMatchers.anyBoolean;
2727
import static org.mockito.ArgumentMatchers.anyInt;
2828
import static org.mockito.ArgumentMatchers.anyString;
@@ -33,9 +33,9 @@
3333

3434
import java.util.function.Predicate;
3535

36-
import org.junit.After;
37-
import org.junit.Before;
38-
import org.junit.Test;
36+
import org.junit.jupiter.api.AfterEach;
37+
import org.junit.jupiter.api.BeforeEach;
38+
import org.junit.jupiter.api.Test;
3939
import org.mockito.Mockito;
4040

4141
import org.eclipse.swt.SWT;
@@ -86,14 +86,14 @@ private void setFindAndReplaceString(IFindReplaceLogic findReplaceLogic, String
8686
findReplaceLogic.setReplaceString(replaceString);
8787
}
8888

89-
@After
89+
@AfterEach
9090
public void disposeShell() {
9191
if (parentShell != null) {
9292
parentShell.dispose();
9393
}
9494
}
9595

96-
@Before
96+
@BeforeEach
9797
public void setupShell() {
9898
parentShell= new Shell();
9999
}
@@ -252,8 +252,8 @@ public void testPerformSelectAndReplaceRegEx() {
252252
expectStatusEmpty(findReplaceLogic);
253253

254254
status= findReplaceLogic.performSelectAndReplace();
255-
assertEquals("Status wasn't correctly returned", false, status);
256-
assertEquals("Text shouldn't have been changed", "Hello World !", textViewer.getDocument().get());
255+
assertEquals(false, status, "Status wasn't correctly returned");
256+
assertEquals("Hello World !", textViewer.getDocument().get(), "Text shouldn't have been changed");
257257
expectStatusIsCode(findReplaceLogic, FindStatus.StatusCode.NO_MATCH);
258258
}
259259

@@ -288,12 +288,12 @@ public void testPerformSelectAndReplaceRegExWithLinebreaks() {
288288
expectStatusEmpty(findReplaceLogic);
289289

290290
setFindAndReplaceString(findReplaceLogic, """
291-
""", " ");
291+
""", " ");
292292
status= findReplaceLogic.performSelectAndReplace();
293-
assertEquals("Status wasn't correctly returned", false, status);
294-
assertEquals("Text shouldn't have been changed", """
293+
assertEquals(false, status, "Status wasn't correctly returned");
294+
assertEquals("""
295295
Hello!
296-
World!""", textViewer.getDocument().get());
296+
World!""", textViewer.getDocument().get(), "Text shouldn't have been changed");
297297
}
298298

299299
@Test
@@ -324,8 +324,8 @@ public void testPerformSelectAndReplaceWithConfigurationChanges() {
324324
expectStatusEmpty(findReplaceLogic);
325325

326326
status= findReplaceLogic.performSelectAndReplace();
327-
assertEquals("Status wasn't correctly returned", false, status);
328-
assertEquals("Text shouldn't have been changed", "Hello World ! !", textViewer.getDocument().get());
327+
assertEquals(false, status, "Status wasn't correctly returned");
328+
assertEquals("Hello World ! !", textViewer.getDocument().get(), "Text shouldn't have been changed");
329329
expectStatusIsCode(findReplaceLogic, FindStatus.StatusCode.NO_MATCH);
330330
}
331331

@@ -355,20 +355,20 @@ public void testPerformReplaceAndFind_caseInsensitive() {
355355
setFindAndReplaceString(findReplaceLogic, "<Replace>", " ");
356356

357357
boolean status= findReplaceLogic.performReplaceAndFind();
358-
assertTrue("replace should have been performed", status);
358+
assertTrue(status, "replace should have been performed");
359359
assertThat(textViewer.getDocument().get(), equalTo("Hello World<replace>!"));
360360
assertThat(findReplaceLogic.getTarget().getSelectionText(), equalTo("<replace>"));
361361
expectStatusEmpty(findReplaceLogic);
362362

363363
setFindAndReplaceString(findReplaceLogic, "<replace>", " ");
364364
status= findReplaceLogic.performReplaceAndFind();
365-
assertTrue("replace should have been performed", status);
365+
assertTrue(status, "replace should have been performed");
366366
assertThat(textViewer.getDocument().get(), equalTo("Hello World !"));
367367
expectStatusIsCode(findReplaceLogic, FindStatus.StatusCode.NO_MATCH);
368368

369369
status= findReplaceLogic.performReplaceAndFind();
370-
assertFalse("replace should not have been performed", status);
371-
assertEquals("Text shouldn't have been changed", "Hello World !", textViewer.getDocument().get());
370+
assertFalse(status, "replace should not have been performed");
371+
assertEquals("Hello World !", textViewer.getDocument().get(), "Text shouldn't have been changed");
372372
expectStatusIsCode(findReplaceLogic, FindStatus.StatusCode.NO_MATCH);
373373
}
374374

@@ -381,12 +381,12 @@ public void testPerformReplaceAndFind_caseSensitive() {
381381
setFindAndReplaceString(findReplaceLogic, "<replace>", " ");
382382

383383
boolean status= findReplaceLogic.performReplaceAndFind();
384-
assertTrue("replace should have been performed", status);
384+
assertTrue(status, "replace should have been performed");
385385
assertThat(textViewer.getDocument().get(), equalTo("Hello<Replace>World !"));
386386
assertThat(findReplaceLogic.getTarget().getSelectionText(), equalTo(" "));
387387

388388
status= findReplaceLogic.performReplaceAndFind();
389-
assertFalse("replace should not have been performed", status);
389+
assertFalse(status, "replace should not have been performed");
390390
assertThat(textViewer.getDocument().get(), equalTo("Hello<Replace>World !"));
391391
assertThat(findReplaceLogic.getTarget().getSelectionText(), equalTo(" "));
392392
}
@@ -400,20 +400,20 @@ public void testPerformReplaceAndFind_caseSensitiveAndIncremental() {
400400
setFindAndReplaceString(findReplaceLogic, "<Replace>", " ");
401401

402402
boolean status= findReplaceLogic.performReplaceAndFind();
403-
assertTrue("replace should have been performed", status);
403+
assertTrue(status, "replace should have been performed");
404404
assertThat(textViewer.getDocument().get(), equalTo("Hello World<replace>!"));
405405
assertThat(findReplaceLogic.getTarget().getSelectionText(), equalTo("<replace>"));
406406
expectStatusEmpty(findReplaceLogic);
407407

408408
setFindAndReplaceString(findReplaceLogic, "<replace>", " ");
409409
status= findReplaceLogic.performReplaceAndFind();
410-
assertTrue("replace should have been performed", status);
410+
assertTrue(status, "replace should have been performed");
411411
assertThat(textViewer.getDocument().get(), equalTo("Hello World !"));
412412
expectStatusIsCode(findReplaceLogic, FindStatus.StatusCode.NO_MATCH);
413413

414414
status= findReplaceLogic.performReplaceAndFind();
415-
assertFalse("replace should not have been performed", status);
416-
assertEquals("Text shouldn't have been changed", "Hello World !", textViewer.getDocument().get());
415+
assertFalse(status, "replace should not have been performed");
416+
assertEquals("Hello World !", textViewer.getDocument().get(), "Text shouldn't have been changed");
417417
expectStatusIsCode(findReplaceLogic, FindStatus.StatusCode.NO_MATCH);
418418
}
419419

@@ -484,8 +484,8 @@ private void executeReplaceAndFindRegExTest(TextViewer textViewer, IFindReplaceL
484484

485485
setFindAndReplaceString(findReplaceLogic, "<(\\w*)>", " ");
486486
status= findReplaceLogic.performReplaceAndFind();
487-
assertEquals("Status wasn't correctly returned", false, status);
488-
assertEquals("Text shouldn't have been changed", "Hello World ! !", textViewer.getDocument().get());
487+
assertEquals(false, status, "Status wasn't correctly returned");
488+
assertEquals("Hello World ! !", textViewer.getDocument().get(), "Text shouldn't have been changed");
489489
expectStatusIsCode(findReplaceLogic, FindStatus.StatusCode.NO_MATCH);
490490
}
491491

tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/FindReplaceTestUtil.java

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

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

1818
import java.util.function.Supplier;
1919

@@ -60,4 +60,4 @@ public static void waitForFocus(Supplier<Boolean> hasFocusValidator, String test
6060
}
6161
}
6262

63-
}
63+
}

tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/FindReplaceUITest.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,19 @@
1010
*
1111
* Contributors:
1212
* IBM Corporation - initial API and implementation
13-
*******************************************************************************/
13+
******************************************************************************/
1414
package org.eclipse.ui.internal.findandreplace;
1515

1616
import static org.hamcrest.MatcherAssert.assertThat;
1717
import static org.hamcrest.Matchers.is;
18-
import static org.junit.Assert.assertEquals;
18+
import static org.junit.jupiter.api.Assertions.assertEquals;
1919

2020
import java.util.ResourceBundle;
2121

22-
import org.junit.After;
23-
import org.junit.Before;
24-
import org.junit.Rule;
25-
import org.junit.Test;
26-
import org.junit.rules.TestName;
22+
import org.junit.jupiter.api.AfterEach;
23+
import org.junit.jupiter.api.BeforeEach;
24+
import org.junit.jupiter.api.Test;
25+
import org.junit.jupiter.api.TestInfo;
2726

2827
import org.eclipse.swt.SWT;
2928

@@ -37,17 +36,18 @@
3736
import org.eclipse.ui.texteditor.FindReplaceAction;
3837

3938
public abstract class FindReplaceUITest<AccessType extends IFindReplaceUIAccess> {
40-
@Rule
41-
public TestName testName= new TestName();
39+
40+
protected TestInfo testInfo;
4241

4342
private TextViewer fTextViewer;
4443

4544
private FindReplaceAction findReplaceAction;
4645

4746
private AccessType dialog;
4847

49-
@Before
50-
public final void ensureWorkbenchWindowIsActive() {
48+
@BeforeEach
49+
public final void ensureWorkbenchWindowIsActive(TestInfo info) {
50+
this.testInfo = info;
5151
PlatformUI.getWorkbench().getWorkbenchWindows()[0].getShell().forceActive();
5252
}
5353

@@ -80,7 +80,7 @@ protected void reopenFindReplaceUIForTextViewer() {
8080

8181
protected abstract AccessType openUIFromTextViewer(TextViewer viewer);
8282

83-
@After
83+
@AfterEach
8484
public void tearDown() throws Exception {
8585
if (dialog != null) {
8686
dialog.closeAndRestore();
@@ -388,4 +388,4 @@ protected final IFindReplaceTarget getFindReplaceTarget() {
388388
return fTextViewer.getFindReplaceTarget();
389389
}
390390

391-
}
391+
}

tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlayTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
import static org.eclipse.ui.internal.findandreplace.FindReplaceTestUtil.waitForFocus;
1717
import static org.hamcrest.MatcherAssert.assertThat;
1818
import static org.hamcrest.Matchers.is;
19-
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertFalse;
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertFalse;
2121

22-
import org.junit.Test;
22+
import org.junit.jupiter.api.Test;
2323

2424
import org.eclipse.swt.graphics.Point;
2525

@@ -48,7 +48,7 @@ public OverlayAccess openUIFromTextViewer(TextViewer viewer) {
4848
actionAccessor.invoke("showOverlayInEditor");
4949
FindReplaceOverlay overlay= (FindReplaceOverlay) actionAccessor.get("overlay");
5050
OverlayAccess uiAccess= new OverlayAccess(getFindReplaceTarget(), overlay);
51-
waitForFocus(uiAccess::hasFocus, testName.getMethodName());
51+
waitForFocus(uiAccess::hasFocus, testInfo.getTestMethod().get().getName());
5252
return uiAccess;
5353
}
5454

@@ -177,7 +177,7 @@ public void testDisableOverlayViaPreference() {
177177
boolean useOverlayPreference= preferences.getBoolean(USE_FIND_REPLACE_OVERLAY, true);
178178
try {
179179
preferences.putBoolean(USE_FIND_REPLACE_OVERLAY, false);
180-
assertFalse("dialog should be closed after changing preference", getDialog().isShown());
180+
assertFalse(getDialog().isShown(), "dialog should be closed after changing preference");
181181
} finally {
182182
preferences.putBoolean(USE_FIND_REPLACE_OVERLAY, useOverlayPreference);
183183
reopenFindReplaceUIForTextViewer();

tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/workbench/texteditor/tests/AbstractTextZoomHandlerTest.java

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

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

18-
import org.junit.Test;
18+
import org.junit.jupiter.api.Test;
1919

2020
import org.eclipse.swt.widgets.Composite;
2121

@@ -231,4 +231,4 @@ public Object getSelectedPage() {
231231
}
232232
}
233233

234-
}
234+
}

tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/workbench/texteditor/tests/DocumentLineDifferTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
package org.eclipse.ui.workbench.texteditor.tests;
1515

1616
import static org.eclipse.jface.text.DocumentRewriteSessionType.SEQUENTIAL;
17-
import static org.junit.Assert.assertFalse;
18-
import static org.junit.Assert.assertTrue;
17+
import static org.junit.jupiter.api.Assertions.assertFalse;
18+
import static org.junit.jupiter.api.Assertions.assertTrue;
1919

20-
import org.junit.Test;
20+
import org.junit.jupiter.api.Test;
2121

2222
import org.eclipse.jface.text.Document;
2323
import org.eclipse.jface.text.IDocument;
@@ -169,4 +169,4 @@ public void nonSuspendedLineDifferStaysNonSuspendedAfterDocumentRewriteSession()
169169
assertFalse(fLineDiffer.isSuspended());
170170
}
171171

172-
}
172+
}

0 commit comments

Comments
 (0)