Skip to content

Commit 126085a

Browse files
vogellaclaude
authored andcommitted
Migrate org.eclipse.search.tests from JUnit 4 to JUnit 5
This commit migrates the org.eclipse.search.tests bundle from JUnit 4 to JUnit 5, including all test files and the necessary dependency updates. Changes: - Updated imports from org.junit.* to org.junit.jupiter.api.* - Replaced @Before/@after with @BeforeEach/@AfterEach annotations - Replaced Assert with Assertions for all assertion methods - Updated test annotations from @test (JUnit 4) to @test (JUnit 5) - Migrated JUnitSourceSetup from @rule to @RegisterExtension - Updated assertions to use JUnit 5 style (message parameter last) MANIFEST.MF updates: - Removed JUnit 4 dependency (org.junit;bundle-version="4.13.2") - Added org.hamcrest;bundle-version="3.0.0" for matcher support - Added JUnit 5 Import-Package entries: - org.junit.jupiter.api;version="[5.14.0,6.0.0)" - org.junit.jupiter.api.extension;version="[5.14.0,6.0.0)" - org.junit.jupiter.api.function;version="[5.14.0,6.0.0)" - org.junit.platform.suite.api;version="[1.14.0,2.0.0)" - org.opentest4j (required for Assumptions.assumeFalse() in PositionTrackerTest) Files migrated: - AllFileSearchTests.java - AnnotationManagerTest.java - FileCharSequenceTests.java - FileSearchTests.java - JUnitSourceSetup.java - LineAnnotationManagerTest.java - PositionTrackerTest.java - ResultUpdaterTest.java - SearchResultPageTest.java - SortingTest.java Note: The org.opentest4j import was critical to fix compilation - it provides TestAbortedException used by JUnit 5's Assumptions API (specifically assumeFalse() in PositionTrackerTest.java:85). Verification: - Compilation succeeds with 0 errors - Tests compile and run successfully 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 937cbb2 commit 126085a

File tree

11 files changed

+125
-126
lines changed

11 files changed

+125
-126
lines changed

tests/org.eclipse.search.tests/META-INF/MANIFEST.MF

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ Require-Bundle:
1818
org.eclipse.jface.text;bundle-version="[3.24.200,4.0.0)",
1919
org.eclipse.ui.editors;bundle-version="[3.17.100,4.0.0)",
2020
org.eclipse.ltk.core.refactoring;bundle-version="[3.14.100,4.0.0)",
21-
org.junit;bundle-version="4.13.2"
21+
org.hamcrest;bundle-version="3.0.0"
2222
Import-Package: org.junit.jupiter.api;version="[5.14.0,6.0.0)",
23+
org.junit.jupiter.api.extension;version="[5.14.0,6.0.0)",
2324
org.junit.jupiter.api.function;version="[5.14.0,6.0.0)",
24-
org.junit.platform.suite.api;version="[1.14.0,2.0.0)"
25+
org.junit.platform.suite.api;version="[1.14.0,2.0.0)",
26+
org.opentest4j
2527
Bundle-ActivationPolicy: lazy
2628
Bundle-RequiredExecutionEnvironment: JavaSE-17
2729
Eclipse-BundleShape: dir

tests/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/AllFileSearchTests.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313
*******************************************************************************/
1414
package org.eclipse.search.tests.filesearch;
1515

16-
import org.junit.ClassRule;
17-
18-
import org.junit.platform.suite.api.Suite;
1916
import org.junit.platform.suite.api.SelectClasses;
17+
import org.junit.platform.suite.api.Suite;
2018

2119
@Suite
2220
@SelectClasses({
@@ -29,6 +27,4 @@
2927
SortingTest.class
3028
})
3129
public class AllFileSearchTests {
32-
@ClassRule
33-
public static JUnitSourceSetup fgJUnitSource= new JUnitSourceSetup();
3430
}

tests/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/AnnotationManagerTest.java

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

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

1919
import java.util.HashSet;
2020
import java.util.Iterator;
2121

22-
import org.junit.After;
23-
import org.junit.Before;
24-
import org.junit.ClassRule;
25-
import org.junit.Test;
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.extension.RegisterExtension;
2626

2727
import org.eclipse.core.resources.IFile;
2828
import org.eclipse.core.resources.IMarker;
@@ -59,10 +59,10 @@ public class AnnotationManagerTest {
5959

6060
private final AnnotationTypeLookup fAnnotationTypeLookup= EditorsUI.getAnnotationTypeLookup();
6161

62-
@ClassRule
63-
public static JUnitSourceSetup fgJUnitSource= new JUnitSourceSetup();
62+
@RegisterExtension
63+
static JUnitSourceSetup fgJUnitSource= new JUnitSourceSetup();
6464

65-
@Before
65+
@BeforeEach
6666
public void setUp() {
6767
SearchTestUtil.ensureWelcomePageClosed();
6868
EditorAnnotationManager.debugSetHighlighterType(EditorAnnotationManager.HIGHLIGHTER_ANNOTATION);
@@ -72,7 +72,7 @@ public void setUp() {
7272
fQuery2= new FileSearchQuery("Test", false, true, scope); //$NON-NLS-1$
7373
}
7474

75-
@After
75+
@AfterEach
7676
public void tearDown() {
7777
InternalSearchUI.getInstance().removeAllQueries();
7878
fQuery1= null;
@@ -104,7 +104,7 @@ public void testAddAnnotation() throws Exception {
104104
Match[] matches= result.getMatches(file);
105105
for (int j= 0; j < matches.length; j++) {
106106
Position position= new Position(matches[j].getOffset(), matches[j].getLength());
107-
assertTrue("position not found at: "+j, positions.remove(position)); //$NON-NLS-1$
107+
assertTrue(positions.remove(position), "position not found at: "+j); //$NON-NLS-1$
108108
}
109109
assertEquals(0, positions.size());
110110

tests/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/FileCharSequenceTests.java

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

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

1818
import java.io.IOException;
1919
import java.nio.charset.StandardCharsets;
2020

21-
import org.junit.After;
22-
import org.junit.Assert;
23-
import org.junit.Before;
24-
import org.junit.Test;
21+
import org.junit.jupiter.api.AfterEach;
22+
import org.junit.jupiter.api.Assertions;
23+
import org.junit.jupiter.api.BeforeEach;
24+
import org.junit.jupiter.api.Test;
2525

2626
import org.eclipse.core.runtime.CoreException;
2727

@@ -38,12 +38,12 @@ public class FileCharSequenceTests {
3838

3939
private IProject fProject;
4040

41-
@Before
41+
@BeforeEach
4242
public void setUp() throws Exception {
4343
fProject= ResourceHelper.createProject("my-project"); //$NON-NLS-1$
4444
}
4545

46-
@After
46+
@AfterEach
4747
public void tearDown() throws Exception {
4848
ResourceHelper.deleteProject("my-project"); //$NON-NLS-1$
4949
}
@@ -114,23 +114,23 @@ private void assertSubSequence(String message, CharSequence actual, CharSequence
114114

115115
private void assertEquals(String desc, CharSequence actual, CharSequence expected) {
116116
for (int i= 0; i < expected.length(); i++) {
117-
Assert.assertEquals(desc + " - forward " + i, expected.charAt(i), actual.charAt(i));
117+
Assertions.assertEquals(expected.charAt(i), actual.charAt(i), desc + " - forward " + i);
118118
}
119-
Assert.assertEquals(desc + " - length", expected.length(), actual.length());
119+
Assertions.assertEquals(expected.length(), actual.length(), desc + " - length");
120120
for (int i= expected.length() - 1; i >= 0; i--) {
121-
Assert.assertEquals(desc + " - backward " + i, expected.charAt(i), actual.charAt(i));
121+
Assertions.assertEquals(expected.charAt(i), actual.charAt(i), desc + " - backward " + i);
122122
}
123123
for (int i= 0; i < expected.length(); i+= 567) {
124-
Assert.assertEquals(desc + " - forward - steps" + i, expected.charAt(i), actual.charAt(i));
124+
Assertions.assertEquals(expected.charAt(i), actual.charAt(i), desc + " - forward - steps" + i);
125125
}
126126
for (int i= 0; i < expected.length(); i+= FileCharSequenceProvider.BUFFER_SIZE) {
127-
Assert.assertEquals(desc + " - forward - buffersize" + i, expected.charAt(i), actual.charAt(i));
127+
Assertions.assertEquals(expected.charAt(i), actual.charAt(i), desc + " - forward - buffersize" + i);
128128
}
129129

130130
assertOutOfBound(desc + "access at length", actual, expected.length());
131131
assertOutOfBound(desc + "access at -1", actual, -1);
132132

133-
Assert.assertEquals(desc + " - length", actual.toString(), expected.toString());
133+
Assertions.assertEquals(expected.toString(), actual.toString(), desc + " - length");
134134
}
135135

136136

@@ -140,7 +140,7 @@ private void assertOutOfBound(String message, CharSequence cs, int i) {
140140
} catch (IndexOutOfBoundsException e) {
141141
return;
142142
}
143-
assertFalse(message, true);
143+
assertFalse(true, message);
144144
}
145145

146146

tests/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/FileSearchTests.java

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
*******************************************************************************/
1616
package org.eclipse.search.tests.filesearch;
1717

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

2021
import java.io.ByteArrayInputStream;
2122
import java.lang.reflect.Field;
@@ -24,10 +25,10 @@
2425
import java.util.List;
2526
import java.util.regex.Pattern;
2627

27-
import org.junit.After;
28-
import org.junit.Before;
29-
import org.junit.ClassRule;
30-
import org.junit.Test;
28+
import org.junit.jupiter.api.AfterEach;
29+
import org.junit.jupiter.api.BeforeEach;
30+
import org.junit.jupiter.api.Test;
31+
import org.junit.jupiter.api.extension.RegisterExtension;
3132

3233
import org.eclipse.core.runtime.ContributorFactorySimple;
3334
import org.eclipse.core.runtime.CoreException;
@@ -120,17 +121,17 @@ public boolean acceptPatternMatch(TextSearchMatchAccess match) throws CoreExcept
120121

121122
}
122123

123-
@ClassRule
124-
public static JUnitSourceSetup fgJUnitSource= new JUnitSourceSetup();
124+
@RegisterExtension
125+
static JUnitSourceSetup fgJUnitSource= new JUnitSourceSetup();
125126

126127
private IProject fProject;
127128

128-
@Before
129+
@BeforeEach
129130
public void setUp() throws Exception{
130131
fProject= ResourceHelper.createProject("my-project"); //$NON-NLS-1$
131132
}
132133

133-
@After
134+
@AfterEach
134135
public void tearDown() throws Exception {
135136
ResourceHelper.deleteProject("my-project"); //$NON-NLS-1$
136137
}
@@ -161,7 +162,7 @@ private void testSimpleFiles(TestResultCollector collector) throws Exception {
161162
TextSearchEngine.create().search(scope, collector, searchPattern, null);
162163

163164
TestResult[] results= collector.getResults();
164-
assertEquals("Number of total results", 4, results.length);
165+
assertEquals(4, results.length, "Number of total results");
165166

166167
assertMatches(results, 2, file1, buf.toString(), "hello");
167168
assertMatches(results, 2, file2, buf.toString(), "hello");
@@ -194,7 +195,7 @@ private void testWildCards1(TestResultCollector collector) throws Exception {
194195
TextSearchEngine.create().search(scope, collector, searchPattern, null);
195196

196197
TestResult[] results= collector.getResults();
197-
assertEquals("Number of total results", 6, results.length);
198+
assertEquals(6, results.length, "Number of total results");
198199
}
199200

200201
@Test
@@ -224,7 +225,7 @@ private void testWildCards2(TestResultCollector collector) throws Exception {
224225
TextSearchEngine.create().search(scope, collector, searchPattern, null);
225226

226227
TestResult[] results= collector.getResults();
227-
assertEquals("Number of total results", 4, results.length);
228+
assertEquals(4, results.length, "Number of total results");
228229
}
229230

230231
@Test
@@ -262,7 +263,7 @@ private void testWildCards3(TestResultCollector collector) throws Exception {
262263
TextSearchEngine.create().search(scope, collector, searchPattern, null);
263264

264265
TestResult[] results= collector.getResults();
265-
assertEquals("Number of total results", 748, results.length);
266+
assertEquals(748, results.length, "Number of total results");
266267
long end= System.currentTimeMillis();
267268
System.out.println("time= " + (end - start));
268269
} finally {
@@ -309,20 +310,20 @@ private void testWholeWord(TestResultCollector collector) throws Exception {
309310
Pattern searchPattern= PatternConstructor.createPattern("h?ll", false, true, false, false);
310311
collector.reset();
311312
engine.search(scope, collector, searchPattern, null);
312-
assertEquals("Number of partial-word results", 22, collector.getNumberOfResults());
313+
assertEquals(22, collector.getNumberOfResults(), "Number of partial-word results");
313314
}
314315
{
315316
// wildcards, whole word = true: match only nothing and non-word chars before and after
316317
Pattern searchPattern= PatternConstructor.createPattern("h?ll", false, true, false, true);
317318
collector.reset();
318319
engine.search(scope, collector, searchPattern, null);
319-
assertEquals("Number of whole-word results", 10, collector.getNumberOfResults());
320+
assertEquals(10, collector.getNumberOfResults(), "Number of whole-word results");
320321
}
321322
// regexp, whole word = false: match all lines
322323
Pattern searchPattern= PatternConstructor.createPattern("h[eio]ll", true, true, false, false);
323324
collector.reset();
324325
engine.search(scope, collector, searchPattern, null);
325-
assertEquals("Number of partial-word results", 22, collector.getNumberOfResults());
326+
assertEquals(22, collector.getNumberOfResults(), "Number of partial-word results");
326327
}
327328

328329
@Test
@@ -354,7 +355,7 @@ private void testFileOpenInEditor(TestResultCollector collector) throws Exceptio
354355
TextSearchEngine.create().search(scope, collector, searchPattern, null);
355356

356357
TestResult[] results= collector.getResults();
357-
assertEquals("Number of total results", 4, results.length);
358+
assertEquals(4, results.length, "Number of total results");
358359

359360
assertMatches(results, 2, file1, buf.toString(), "hello");
360361
assertMatches(results, 2, file2, buf.toString(), "hello");
@@ -510,39 +511,39 @@ private void testFileNamePatterns(TestResultCollector collector) throws Exceptio
510511
String[] fileNamePatterns= { "*" };
511512

512513
TestResult[] results= performSearch(collector, fileNamePatterns, searchPattern);
513-
assertEquals("Number of total results", 4, results.length);
514+
assertEquals(4, results.length, "Number of total results");
514515

515516
fileNamePatterns= new String[] { "*.x" };
516517
results= performSearch(collector, fileNamePatterns, searchPattern);
517-
assertEquals("Number of total results", 2, results.length);
518+
assertEquals(2, results.length, "Number of total results");
518519

519520
fileNamePatterns= new String[] { "*.x", "*.y*" };
520521
results= performSearch(collector, fileNamePatterns, searchPattern);
521-
assertEquals("Number of total results", 3, results.length);
522+
assertEquals(3, results.length, "Number of total results");
522523

523524
fileNamePatterns= new String[] { "!*.x" };
524525
results= performSearch(collector, fileNamePatterns, searchPattern);
525-
assertEquals("Number of total results", 2, results.length);
526+
assertEquals(2, results.length, "Number of total results");
526527

527528
fileNamePatterns= new String[] { "!*.x", "!*.y" };
528529
results= performSearch(collector, fileNamePatterns, searchPattern);
529-
assertEquals("Number of total results", 1, results.length);
530+
assertEquals(1, results.length, "Number of total results");
530531

531532
fileNamePatterns= new String[] { "*", "!*.y" };
532533
results= performSearch(collector, fileNamePatterns, searchPattern);
533-
assertEquals("Number of total results", 3, results.length);
534+
assertEquals(3, results.length, "Number of total results");
534535

535536
fileNamePatterns= new String[] { "*", "!*.*" };
536537
results= performSearch(collector, fileNamePatterns, searchPattern);
537-
assertEquals("Number of total results", 0, results.length);
538+
assertEquals(0, results.length, "Number of total results");
538539

539540
fileNamePatterns= new String[] { "*.x", "*.y*", "!*.y" };
540541
results= performSearch(collector, fileNamePatterns, searchPattern);
541-
assertEquals("Number of total results", 2, results.length);
542+
assertEquals(2, results.length, "Number of total results");
542543

543544
fileNamePatterns= new String[] { "file*", "!*.x*", "!*.y" };
544545
results= performSearch(collector, fileNamePatterns, searchPattern);
545-
assertEquals("Number of total results", 1, results.length);
546+
assertEquals(1, results.length, "Number of total results");
546547
}
547548

548549
private TestResult[] performSearch(TestResultCollector collector, String[] fileNamePatterns, Pattern searchPattern) {
@@ -610,7 +611,7 @@ private void testBinaryContentTypeWithDescriber(TestResultCollector collector) t
610611
TextSearchEngine.create().search(scope, collector, searchPattern, null);
611612

612613
TestResult[] results= collector.getResults();
613-
assertEquals("Number of total results", 1, results.length);
614+
assertEquals(1, results.length, "Number of total results");
614615

615616
assertMatches(results, 1, textfile, "text hello", "hello");
616617
assertMatches(results, 0, binaryfile, "binary hello", "hello");
@@ -625,10 +626,10 @@ private void assertMatches(TestResult[] results, int expectedCount, IFile file,
625626
for (TestResult curr : results) {
626627
if (file.equals(curr.resource)) {
627628
k++;
628-
assertEquals("Wrong positions", string, fileContent.substring(curr.offset, curr.offset + curr.length));
629+
assertEquals(string, fileContent.substring(curr.offset, curr.offset + curr.length), "Wrong positions");
629630
}
630631
}
631-
assertEquals("Number of results in file", expectedCount, k);
632+
assertEquals(expectedCount, k, "Number of results in file");
632633
}
633634

634635

tests/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/JUnitSourceSetup.java

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

16-
import org.junit.rules.ExternalResource;
17-
18-
import org.eclipse.core.runtime.CoreException;
16+
import org.junit.jupiter.api.extension.AfterAllCallback;
17+
import org.junit.jupiter.api.extension.BeforeAllCallback;
18+
import org.junit.jupiter.api.extension.ExtensionContext;
1919

2020
import org.eclipse.core.resources.IProject;
2121
import org.eclipse.core.resources.ResourcesPlugin;
2222

2323
import org.eclipse.search.tests.ResourceHelper;
2424

25-
public class JUnitSourceSetup extends ExternalResource {
25+
public class JUnitSourceSetup implements BeforeAllCallback, AfterAllCallback {
2626

2727
public static final String STANDARD_PROJECT_NAME= "JUnitSource";
2828

@@ -42,21 +42,17 @@ public JUnitSourceSetup(String projectName) {
4242
}
4343

4444
@Override
45-
public void before() throws Exception {
45+
public void beforeAll(ExtensionContext context) throws Exception {
4646
IProject project= ResourcesPlugin.getWorkspace().getRoot().getProject(fProjectName);
4747
if (!project.exists()) { // allow nesting of JUnitSetups
4848
fProject= ResourceHelper.createJUnitSourceProject(fProjectName);
4949
}
5050
}
5151

5252
@Override
53-
public void after() /*throws Exception (but JUnit4 API is stupid...)*/ {
53+
public void afterAll(ExtensionContext context) throws Exception {
5454
if (fProject != null) { // delete only by the setup who created the project
55-
try {
56-
ResourceHelper.deleteProject(fProjectName);
57-
} catch (CoreException e) {
58-
throw new AssertionError(e); // workaround stupid JUnit4 API
59-
}
55+
ResourceHelper.deleteProject(fProjectName);
6056
fProject= null;
6157
}
6258
}

0 commit comments

Comments
 (0)