Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions tests/org.eclipse.search.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ Require-Bundle:
org.eclipse.jface.text;bundle-version="[3.24.200,4.0.0)",
org.eclipse.ui.editors;bundle-version="[3.17.100,4.0.0)",
org.eclipse.ltk.core.refactoring;bundle-version="[3.14.100,4.0.0)",
org.junit;bundle-version="4.13.2"
org.hamcrest;bundle-version="3.0.0"
Import-Package: 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.junit.platform.suite.api;version="[1.14.0,2.0.0)",
org.opentest4j
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-17
Eclipse-BundleShape: dir
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
*******************************************************************************/
package org.eclipse.search.tests.filesearch;

import org.junit.ClassRule;

import org.junit.platform.suite.api.Suite;
import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.Suite;

@Suite
@SelectClasses({
Expand All @@ -29,6 +27,4 @@
SortingTest.class
})
public class AllFileSearchTests {
@ClassRule
public static JUnitSourceSetup fgJUnitSource= new JUnitSourceSetup();
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
*******************************************************************************/
package org.eclipse.search.tests.filesearch;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.HashSet;
import java.util.Iterator;

import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
Expand Down Expand Up @@ -59,10 +59,10 @@ public class AnnotationManagerTest {

private final AnnotationTypeLookup fAnnotationTypeLookup= EditorsUI.getAnnotationTypeLookup();

@ClassRule
public static JUnitSourceSetup fgJUnitSource= new JUnitSourceSetup();
@RegisterExtension
static JUnitSourceSetup fgJUnitSource= new JUnitSourceSetup();

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
*******************************************************************************/
package org.eclipse.search.tests.filesearch;

import static org.junit.Assert.assertFalse;
import static org.junit.jupiter.api.Assertions.assertFalse;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import org.eclipse.core.runtime.CoreException;

Expand All @@ -38,12 +38,12 @@ public class FileCharSequenceTests {

private IProject fProject;

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

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

private void assertEquals(String desc, CharSequence actual, CharSequence expected) {
for (int i= 0; i < expected.length(); i++) {
Assert.assertEquals(desc + " - forward " + i, expected.charAt(i), actual.charAt(i));
Assertions.assertEquals(expected.charAt(i), actual.charAt(i), desc + " - forward " + i);
}
Assert.assertEquals(desc + " - length", expected.length(), actual.length());
Assertions.assertEquals(expected.length(), actual.length(), desc + " - length");
for (int i= expected.length() - 1; i >= 0; i--) {
Assert.assertEquals(desc + " - backward " + i, expected.charAt(i), actual.charAt(i));
Assertions.assertEquals(expected.charAt(i), actual.charAt(i), desc + " - backward " + i);
}
for (int i= 0; i < expected.length(); i+= 567) {
Assert.assertEquals(desc + " - forward - steps" + i, expected.charAt(i), actual.charAt(i));
Assertions.assertEquals(expected.charAt(i), actual.charAt(i), desc + " - forward - steps" + i);
}
for (int i= 0; i < expected.length(); i+= FileCharSequenceProvider.BUFFER_SIZE) {
Assert.assertEquals(desc + " - forward - buffersize" + i, expected.charAt(i), actual.charAt(i));
Assertions.assertEquals(expected.charAt(i), actual.charAt(i), desc + " - forward - buffersize" + i);
}

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

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


Expand All @@ -140,7 +140,7 @@ private void assertOutOfBound(String message, CharSequence cs, int i) {
} catch (IndexOutOfBoundsException e) {
return;
}
assertFalse(message, true);
assertFalse(true, message);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
*******************************************************************************/
package org.eclipse.search.tests.filesearch;

import static org.junit.Assert.assertEquals;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.ByteArrayInputStream;
import java.lang.reflect.Field;
Expand All @@ -24,10 +25,10 @@
import java.util.List;
import java.util.regex.Pattern;

import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

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

}

@ClassRule
public static JUnitSourceSetup fgJUnitSource= new JUnitSourceSetup();
@RegisterExtension
static JUnitSourceSetup fgJUnitSource= new JUnitSourceSetup();

private IProject fProject;

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

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

TestResult[] results= collector.getResults();
assertEquals("Number of total results", 4, results.length);
assertEquals(4, results.length, "Number of total results");

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

TestResult[] results= collector.getResults();
assertEquals("Number of total results", 6, results.length);
assertEquals(6, results.length, "Number of total results");
}

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

TestResult[] results= collector.getResults();
assertEquals("Number of total results", 4, results.length);
assertEquals(4, results.length, "Number of total results");
}

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

TestResult[] results= collector.getResults();
assertEquals("Number of total results", 748, results.length);
assertEquals(748, results.length, "Number of total results");
long end= System.currentTimeMillis();
System.out.println("time= " + (end - start));
} finally {
Expand Down Expand Up @@ -309,20 +310,20 @@ private void testWholeWord(TestResultCollector collector) throws Exception {
Pattern searchPattern= PatternConstructor.createPattern("h?ll", false, true, false, false);
collector.reset();
engine.search(scope, collector, searchPattern, null);
assertEquals("Number of partial-word results", 22, collector.getNumberOfResults());
assertEquals(22, collector.getNumberOfResults(), "Number of partial-word results");
}
{
// wildcards, whole word = true: match only nothing and non-word chars before and after
Pattern searchPattern= PatternConstructor.createPattern("h?ll", false, true, false, true);
collector.reset();
engine.search(scope, collector, searchPattern, null);
assertEquals("Number of whole-word results", 10, collector.getNumberOfResults());
assertEquals(10, collector.getNumberOfResults(), "Number of whole-word results");
}
// regexp, whole word = false: match all lines
Pattern searchPattern= PatternConstructor.createPattern("h[eio]ll", true, true, false, false);
collector.reset();
engine.search(scope, collector, searchPattern, null);
assertEquals("Number of partial-word results", 22, collector.getNumberOfResults());
assertEquals(22, collector.getNumberOfResults(), "Number of partial-word results");
}

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

TestResult[] results= collector.getResults();
assertEquals("Number of total results", 4, results.length);
assertEquals(4, results.length, "Number of total results");

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

TestResult[] results= performSearch(collector, fileNamePatterns, searchPattern);
assertEquals("Number of total results", 4, results.length);
assertEquals(4, results.length, "Number of total results");

fileNamePatterns= new String[] { "*.x" };
results= performSearch(collector, fileNamePatterns, searchPattern);
assertEquals("Number of total results", 2, results.length);
assertEquals(2, results.length, "Number of total results");

fileNamePatterns= new String[] { "*.x", "*.y*" };
results= performSearch(collector, fileNamePatterns, searchPattern);
assertEquals("Number of total results", 3, results.length);
assertEquals(3, results.length, "Number of total results");

fileNamePatterns= new String[] { "!*.x" };
results= performSearch(collector, fileNamePatterns, searchPattern);
assertEquals("Number of total results", 2, results.length);
assertEquals(2, results.length, "Number of total results");

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

fileNamePatterns= new String[] { "*", "!*.y" };
results= performSearch(collector, fileNamePatterns, searchPattern);
assertEquals("Number of total results", 3, results.length);
assertEquals(3, results.length, "Number of total results");

fileNamePatterns= new String[] { "*", "!*.*" };
results= performSearch(collector, fileNamePatterns, searchPattern);
assertEquals("Number of total results", 0, results.length);
assertEquals(0, results.length, "Number of total results");

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

fileNamePatterns= new String[] { "file*", "!*.x*", "!*.y" };
results= performSearch(collector, fileNamePatterns, searchPattern);
assertEquals("Number of total results", 1, results.length);
assertEquals(1, results.length, "Number of total results");
}

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

TestResult[] results= collector.getResults();
assertEquals("Number of total results", 1, results.length);
assertEquals(1, results.length, "Number of total results");

assertMatches(results, 1, textfile, "text hello", "hello");
assertMatches(results, 0, binaryfile, "binary hello", "hello");
Expand All @@ -625,10 +626,10 @@ private void assertMatches(TestResult[] results, int expectedCount, IFile file,
for (TestResult curr : results) {
if (file.equals(curr.resource)) {
k++;
assertEquals("Wrong positions", string, fileContent.substring(curr.offset, curr.offset + curr.length));
assertEquals(string, fileContent.substring(curr.offset, curr.offset + curr.length), "Wrong positions");
}
}
assertEquals("Number of results in file", expectedCount, k);
assertEquals(expectedCount, k, "Number of results in file");
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
*******************************************************************************/
package org.eclipse.search.tests.filesearch;

import org.junit.rules.ExternalResource;

import org.eclipse.core.runtime.CoreException;
import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;

import org.eclipse.search.tests.ResourceHelper;

public class JUnitSourceSetup extends ExternalResource {
public class JUnitSourceSetup implements BeforeAllCallback, AfterAllCallback {

public static final String STANDARD_PROJECT_NAME= "JUnitSource";

Expand All @@ -42,21 +42,17 @@ public JUnitSourceSetup(String projectName) {
}

@Override
public void before() throws Exception {
public void beforeAll(ExtensionContext context) throws Exception {
IProject project= ResourcesPlugin.getWorkspace().getRoot().getProject(fProjectName);
if (!project.exists()) { // allow nesting of JUnitSetups
fProject= ResourceHelper.createJUnitSourceProject(fProjectName);
}
}

@Override
public void after() /*throws Exception (but JUnit4 API is stupid...)*/ {
public void afterAll(ExtensionContext context) throws Exception {
if (fProject != null) { // delete only by the setup who created the project
try {
ResourceHelper.deleteProject(fProjectName);
} catch (CoreException e) {
throw new AssertionError(e); // workaround stupid JUnit4 API
}
ResourceHelper.deleteProject(fProjectName);
fProject= null;
}
}
Expand Down
Loading
Loading