diff --git a/tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/HTML2TextReaderTest.java b/tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/HTML2TextReaderTest.java
index 39f19788068..035056ad215 100644
--- a/tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/HTML2TextReaderTest.java
+++ b/tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/HTML2TextReaderTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2016 IBM Corporation and others.
+ * Copyright (c) 2006, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -16,6 +16,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.IOException;
import java.io.Reader;
@@ -76,7 +77,7 @@ private void verify(String input, String expectedOutput, int styleRangeCount) th
StyleRange range2= ranges.get(i + 1);
if (range1.start + range1.length > range2.start) {
- assertTrue("StyleRanges overlap", false);
+ fail("StyleRanges overlap");
}
}
@@ -108,7 +109,7 @@ private void verify(String input, String expectedOutput, StyleRange[] styleRange
StyleRange range2= ranges.get(i + 1);
if (range1.start + range1.length > range2.start) {
- assertTrue("StyleRanges overlap", false);
+ fail("StyleRanges overlap");
}
}
diff --git a/tests/org.eclipse.text.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.text.tests/META-INF/MANIFEST.MF
index bfd99b7350f..9ffe2164ddb 100644
--- a/tests/org.eclipse.text.tests/META-INF/MANIFEST.MF
+++ b/tests/org.eclipse.text.tests/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Plugin.name
Bundle-SymbolicName: org.eclipse.text.tests
-Bundle-Version: 3.14.600.qualifier
+Bundle-Version: 3.14.700.qualifier
Bundle-Vendor: %Plugin.providerName
Bundle-Localization: plugin
Export-Package:
diff --git a/tests/org.eclipse.text.tests/src/org/eclipse/text/tests/AnnotationModelExtension2Test.java b/tests/org.eclipse.text.tests/src/org/eclipse/text/tests/AnnotationModelExtension2Test.java
index e4b7b9503bf..58e56a6553b 100644
--- a/tests/org.eclipse.text.tests/src/org/eclipse/text/tests/AnnotationModelExtension2Test.java
+++ b/tests/org.eclipse.text.tests/src/org/eclipse/text/tests/AnnotationModelExtension2Test.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2015 IBM Corporation and others.
+ * Copyright (c) 2007, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -13,7 +13,7 @@
*******************************************************************************/
package org.eclipse.text.tests;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.Arrays;
@@ -139,7 +139,7 @@ private void assertEquals(Annotation[] expected, Annotation[] actual, IAnnotatio
for (Annotation a : actual) {
if (!expectedSet.contains(a)) {
String message = "Unexpected annotation " + getName(a) + " in result with models [" + getAnnotationModelNames(insideModel, beforeModel, afterModel) + "]";
- assertTrue(message, false);
+ fail(message);
}
expectedSet.remove(a);
}
@@ -149,7 +149,7 @@ private void assertEquals(Annotation[] expected, Annotation[] actual, IAnnotatio
for (Annotation missing : expectedSet) {
message= message + "\n" + getName(missing);
}
- assertTrue(message, false);
+ fail(message);
}
}
diff --git a/tests/org.eclipse.text.tests/src/org/eclipse/text/tests/ChildDocumentTest.java b/tests/org.eclipse.text.tests/src/org/eclipse/text/tests/ChildDocumentTest.java
index a2f526e707e..a1a975d1fd6 100644
--- a/tests/org.eclipse.text.tests/src/org/eclipse/text/tests/ChildDocumentTest.java
+++ b/tests/org.eclipse.text.tests/src/org/eclipse/text/tests/ChildDocumentTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2010 IBM Corporation and others.
+ * Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -37,19 +37,13 @@ public class ChildDocumentTest {
private ChildDocumentManager fManager;
- protected void checkPositions(Position[] positions) {
+ protected void checkPositions(Position[] positions) throws BadPositionCategoryException {
- try {
+ Position[] v = fDocument.getPositions(IDocument.DEFAULT_CATEGORY);
+ assertTrue("invalid number of positions", v.length == positions.length);
- Position[] v= fDocument.getPositions(IDocument.DEFAULT_CATEGORY);
- assertTrue("invalid number of positions", v.length == positions.length);
-
- for (int i= 0; i < positions.length; i++) {
- assertEquals(print(v[i]) + " != " + print(positions[i]), positions[i], v[i]);
- }
-
- } catch (BadPositionCategoryException x) {
- assertTrue("BadPositionCategoryException thrown", false);
+ for (int i = 0; i < positions.length; i++) {
+ assertEquals(print(v[i]) + " != " + print(positions[i]), positions[i], v[i]);
}
}
@@ -68,7 +62,7 @@ protected String print(Position p) {
return "[" + p.getOffset() + "," + p.getLength() + "]";
}
- protected void checkLineInformationConsistency() {
+ protected void checkLineInformationConsistency() throws BadLocationException {
DefaultLineTracker textTracker= new DefaultLineTracker();
textTracker.set(fDocument.get());
@@ -77,22 +71,18 @@ protected void checkLineInformationConsistency() {
assertEquals("Child document store and child line tracker are inconsistent", trackerLines, textLines);
- for (int i= 0; i < trackerLines; i++) {
- try {
- IRegion trackerLine = fDocument.getLineInformation(i);
- IRegion textLine = textTracker.getLineInformation(i);
- assertEquals("Child document store and child line tracker are inconsistent", trackerLine.getOffset(),
- textLine.getOffset());
- assertEquals("Child document store and child line tracker are inconsistent", trackerLine.getLength(),
- textLine.getLength());
- } catch (BadLocationException e) {
- throw new AssertionError("BadLocationException thrown", e);
- }
+ for (int i = 0; i < trackerLines; i++) {
+ IRegion trackerLine = fDocument.getLineInformation(i);
+ IRegion textLine = textTracker.getLineInformation(i);
+ assertEquals("Child document store and child line tracker are inconsistent", trackerLine.getOffset(),
+ textLine.getOffset());
+ assertEquals("Child document store and child line tracker are inconsistent", trackerLine.getLength(),
+ textLine.getLength());
}
}
@Before
- public void setUp() {
+ public void setUp() throws BadLocationException {
fParent= new Document();
@@ -111,30 +101,20 @@ public void setUp() {
" }\n";
fParent.set(text);
- fManager= new ChildDocumentManager();
- try {
- fDocument= fManager.createSlaveDocument(fParent);
- if (fDocument instanceof ChildDocument) {
- ChildDocument child= (ChildDocument) fDocument;
- child.setParentDocumentRange(0, fParent.getLength());
- }
- } catch (BadLocationException x) {
- assertTrue(false);
+ fManager = new ChildDocumentManager();
+ fDocument = fManager.createSlaveDocument(fParent);
+ if (fDocument instanceof ChildDocument child) {
+ child.setParentDocumentRange(0, fParent.getLength());
}
- try {
+ fDocument.addPosition(new Position(0, 20));
+ fDocument.addPosition(new Position(21, 15));
+ fDocument.addPosition(new Position(38, 111));
+ fDocument.addPosition(new Position(61, 12));
+ fDocument.addPosition(new Position(75, 27));
+ fDocument.addPosition(new Position(105, 12));
+ fDocument.addPosition(new Position(119, 27));
- fDocument.addPosition(new Position( 0, 20));
- fDocument.addPosition(new Position( 21, 15));
- fDocument.addPosition(new Position( 38, 111));
- fDocument.addPosition(new Position( 61, 12));
- fDocument.addPosition(new Position( 75, 27));
- fDocument.addPosition(new Position(105, 12));
- fDocument.addPosition(new Position(119, 27));
-
- } catch (BadLocationException x) {
- assertTrue("initilization failed", false);
- }
}
@After
@@ -143,17 +123,11 @@ public void tearDown () {
}
@Test
- public void testDelete1() {
+ public void testDelete1() throws BadLocationException, BadPositionCategoryException {
- try {
+ fDocument.replace(21, 16, "");
- fDocument.replace(21, 16, "");
-
- } catch (BadLocationException x) {
- assertTrue("BadLocationException thrown", false);
- }
-
- Position[] positions= new Position[] {
+ Position[] positions = {
new Position( 0, 20),
new Position( 21, 0),
new Position( 22, 111),
@@ -167,62 +141,38 @@ public void testDelete1() {
}
@Test
- public void testEditScript1() {
+ public void testEditScript1() throws BadPositionCategoryException, BadLocationException {
// 1. step
+ fDocument.replace(0, fDocument.getLength(), "");
- try {
-
- fDocument.replace(0, fDocument.getLength(), "");
-
- } catch (BadLocationException x) {
- assertTrue("BadLocationException thrown", false);
- }
-
- Position[] positions= new Position[] {
- new Position( 0, 0)
- };
+ Position[] positions = { new Position(0, 0) };
checkPositions(positions);
-
// 2. step
- try {
-
- fDocument.replace(0, 0, "\t");
-
- } catch (BadLocationException x) {
- assertTrue("BadLocationException thrown", false);
- }
+ fDocument.replace(0, 0, "\t");
- positions= new Position[] {
+ positions = new Position[] {
new Position( 1, 0)
};
checkPositions(positions);
-
}
@Test
- public void testFindPositions() {
-
- try {
-
- fDocument.addPosition(new Position( 21, 13));
- fDocument.addPosition(new Position( 0, 19));
- fDocument.addPosition(new Position( 21, 14));
- fDocument.addPosition(new Position( 21, 16));
- fDocument.addPosition(new Position( 0, 0));
- fDocument.addPosition(new Position( 104, 1));
- fDocument.addPosition(new Position( 120, 1));
- fDocument.addPosition(new Position( 119, 1));
-
- } catch (BadLocationException x) {
- assertTrue("initilization failed", false);
- }
-
-
- Position[] positions= new Position[] {
+ public void testFindPositions() throws BadLocationException, BadPositionCategoryException {
+
+ fDocument.addPosition(new Position(21, 13));
+ fDocument.addPosition(new Position(0, 19));
+ fDocument.addPosition(new Position(21, 14));
+ fDocument.addPosition(new Position(21, 16));
+ fDocument.addPosition(new Position(0, 0));
+ fDocument.addPosition(new Position(104, 1));
+ fDocument.addPosition(new Position(120, 1));
+ fDocument.addPosition(new Position(119, 1));
+
+ Position[] positions = {
new Position( 0, 0),
new Position( 0, 19),
new Position( 0, 20),
@@ -245,17 +195,11 @@ public void testFindPositions() {
}
@Test
- public void testInsert1() {
+ public void testInsert1() throws BadLocationException, BadPositionCategoryException {
- try {
+ fDocument.replace(0, 0, "//comment\n");
- fDocument.replace(0, 0, "//comment\n");
-
- } catch (BadLocationException x) {
- assertTrue("BadLocationException thrown", false);
- }
-
- Position[] positions= new Position[] {
+ Position[] positions = {
new Position( 10, 20),
new Position( 31, 15),
new Position( 48, 111),
@@ -269,17 +213,11 @@ public void testInsert1() {
}
@Test
- public void testInsert2() {
-
- try {
+ public void testInsert2() throws BadLocationException, BadPositionCategoryException {
- fDocument.replace(61, 0, "//comment\n");
+ fDocument.replace(61, 0, "//comment\n");
- } catch (BadLocationException x) {
- assertTrue("BadLocationException thrown", false);
- }
-
- Position[] positions= new Position[] {
+ Position[] positions = {
new Position( 0, 20),
new Position( 21, 15),
new Position( 38, 121),
@@ -293,17 +231,11 @@ public void testInsert2() {
}
@Test
- public void testInsert3() {
-
- try {
+ public void testInsert3() throws BadLocationException, BadPositionCategoryException {
- fDocument.replace(101, 0, "//comment\n");
+ fDocument.replace(101, 0, "//comment\n");
- } catch (BadLocationException x) {
- assertTrue("BadLocationException thrown", false);
- }
-
- Position[] positions= new Position[] {
+ Position[] positions = {
new Position( 0, 20),
new Position( 21, 15),
new Position( 38, 121),
@@ -317,19 +249,11 @@ public void testInsert3() {
}
@Test
- public void testInsert4() {
-
- try {
-
- fDocument.replace(20, 0, "// comment");
+ public void testInsert4() throws BadPositionCategoryException, BadLocationException {
- } catch (BadLocationException x) {
- assertTrue("BadLocationException thrown", false);
- }
-
- System.out.print(fDocument.get());
+ fDocument.replace(20, 0, "// comment");
- Position[] positions= new Position[] {
+ Position[] positions = {
new Position( 0, 20),
new Position( 31, 15),
new Position( 48, 111),
@@ -343,17 +267,11 @@ public void testInsert4() {
}
@Test
- public void testReplace1() {
+ public void testReplace1() throws BadLocationException, BadPositionCategoryException {
- try {
+ fDocument.replace(8, 11, "pkg1");
- fDocument.replace(8, 11, "pkg1");
-
- } catch (BadLocationException x) {
- assertTrue("BadLocationException thrown", false);
- }
-
- Position[] positions= new Position[] {
+ Position[] positions = {
new Position( 0, 13),
new Position( 14, 15),
new Position( 31, 111),
@@ -367,17 +285,10 @@ public void testReplace1() {
}
@Test
- public void testReplace2() {
-
- try {
+ public void testReplace2() throws BadLocationException, BadPositionCategoryException {
+ fDocument.replace(21, 16, "//comment\n");
- fDocument.replace(21, 16, "//comment\n");
-
- } catch (BadLocationException x) {
- assertTrue("BadLocationException thrown", false);
- }
-
- Position[] positions= new Position[] {
+ Position[] positions = {
new Position( 0, 20),
new Position( 31, 0),
new Position( 32, 111),
@@ -391,24 +302,14 @@ public void testReplace2() {
}
@Test
- public void testReplace3() {
-
- Position[] actual= new Position[] {
- new Position(0, 150),
- };
+ public void testReplace3() throws BadLocationException {
- try {
+ Position[] actual = { new Position(0, 150), };
- fDocument.addPosition(actual[0]);
- fDocument.replace(0, 150, "xxxxxxxxxx");
+ fDocument.addPosition(actual[0]);
+ fDocument.replace(0, 150, "xxxxxxxxxx");
- } catch (BadLocationException x) {
- assertTrue("BadLocationException thrown", false);
- }
-
- Position[] expected= new Position[] {
- new Position(0, 10)
- };
+ Position[] expected = { new Position(0, 10) };
checkPositions(expected, actual);
}
@@ -420,57 +321,38 @@ public void testReplace3() {
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=51594
*/
@Test
- public void testReplace4() {
- try {
- int start= fParent.getLineOffset(5);
- int end= fParent.getLineOffset(8);
- ChildDocument child= (ChildDocument) fDocument;
- child.setParentDocumentRange(start, end - start);
- fParent.replace(end, 1, "x");
- checkLineInformationConsistency();
- } catch (BadLocationException e) {
- assertTrue("BadLocationException thrown", false);
- }
+ public void testReplace4() throws BadLocationException {
+ int start = fParent.getLineOffset(5);
+ int end = fParent.getLineOffset(8);
+ ChildDocument child = (ChildDocument) fDocument;
+ child.setParentDocumentRange(start, end - start);
+ fParent.replace(end, 1, "x");
+ checkLineInformationConsistency();
}
@Test
- public void testAppend() {
+ public void testAppend() throws BadLocationException {
- Position[] actual= new Position[] {
- new Position(0, 2),
- };
-
- try {
+ Position[] actual = { new Position(0, 2), };
- fDocument.replace(0, 150, "");
- fDocument.replace(fDocument.getLength(), 0, "xx");
- fDocument.addPosition(actual[0]);
- fDocument.replace(fDocument.getLength(), 0, "xxxxxxxx");
+ fDocument.replace(0, 150, "");
+ fDocument.replace(fDocument.getLength(), 0, "xx");
+ fDocument.addPosition(actual[0]);
+ fDocument.replace(fDocument.getLength(), 0, "xxxxxxxx");
- } catch (BadLocationException x) {
- assertTrue("BadLocationException thrown", false);
- }
-
- Position[] expected= new Position[] {
- new Position(0, 2)
- };
+ Position[] expected = { new Position(0, 2) };
checkPositions(expected, actual);
}
@Test
- public void testShiftLeft() {
-
- try {
+ public void testShiftLeft() throws BadLocationException, BadPositionCategoryException {
- fDocument.replace(73, 1, "");
- fDocument.replace(98, 1, "");
+ fDocument.replace(73, 1, "");
+ fDocument.replace(98, 1, "");
- } catch (BadLocationException x) {
- assertTrue("BadLocationException thrown", false);
- }
- Position[] positions= new Position[] {
+ Position[] positions = {
new Position( 0, 20),
new Position( 21, 15),
new Position( 38, 109),
@@ -484,18 +366,11 @@ public void testShiftLeft() {
}
@Test
- public void testShiftRight() {
-
- try {
-
- fDocument.replace( 73, 0, "\t");
- fDocument.replace(100, 0, "\t");
-
- } catch (BadLocationException x) {
- assertTrue("BadLocationException thrown", false);
- }
+ public void testShiftRight() throws BadLocationException, BadPositionCategoryException {
+ fDocument.replace(73, 0, "\t");
+ fDocument.replace(100, 0, "\t");
- Position[] positions= new Position[] {
+ Position[] positions = {
new Position( 0, 20),
new Position( 21, 15),
new Position( 38, 113),
diff --git a/tests/org.eclipse.text.tests/src/org/eclipse/text/tests/DocumentTest.java b/tests/org.eclipse.text.tests/src/org/eclipse/text/tests/DocumentTest.java
index b83634fcfe1..540083bd6df 100644
--- a/tests/org.eclipse.text.tests/src/org/eclipse/text/tests/DocumentTest.java
+++ b/tests/org.eclipse.text.tests/src/org/eclipse/text/tests/DocumentTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2010 IBM Corporation and others.
+ * Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -31,17 +31,10 @@ public class DocumentTest {
private Document fDocument;
- protected void checkPositions(Position[] expected) {
-
- try {
-
- Position[] actual= fDocument.getPositions(IDocument.DEFAULT_CATEGORY);
- checkPositions(expected, actual);
-
- } catch (BadPositionCategoryException x) {
- assertTrue("BadPositionCategoryException thrown", false);
- }
+ protected void checkPositions(Position[] expected) throws BadPositionCategoryException {
+ Position[] actual = fDocument.getPositions(IDocument.DEFAULT_CATEGORY);
+ checkPositions(expected, actual);
}
protected void checkPositions(Position[] expected, Position[] actual) {
@@ -55,7 +48,7 @@ protected void checkPositions(Position[] expected, Position[] actual) {
}
@Before
- public void setUp() {
+ public void setUp() throws BadLocationException {
fDocument= new Document();
@@ -75,19 +68,14 @@ public void setUp() {
fDocument.set(text);
- try {
+ fDocument.addPosition(new Position(0, 20)); // "package TestPackage;"
+ fDocument.addPosition(new Position(21, 15)); // "/*\n* comment\n*/"
+ fDocument.addPosition(new Position(38, 111)); // "public class Class {\n ... }"
+ fDocument.addPosition(new Position(61, 12)); // "// comment1\n"
+ fDocument.addPosition(new Position(75, 27)); // "public void method1() {\n }"
+ fDocument.addPosition(new Position(105, 12)); // "// comment2\n"
+ fDocument.addPosition(new Position(119, 27)); // "public void method2() {\n }"
- fDocument.addPosition(new Position( 0, 20)); // "package TestPackage;"
- fDocument.addPosition(new Position( 21, 15)); // "/*\n* comment\n*/"
- fDocument.addPosition(new Position( 38, 111)); // "public class Class {\n ... }"
- fDocument.addPosition(new Position( 61, 12)); // "// comment1\n"
- fDocument.addPosition(new Position( 75, 27)); // "public void method1() {\n }"
- fDocument.addPosition(new Position(105, 12)); // "// comment2\n"
- fDocument.addPosition(new Position(119, 27)); // "public void method2() {\n }"
-
- } catch (BadLocationException x) {
- assertTrue("initilization failed", false);
- }
}
@After
@@ -103,17 +91,11 @@ public void testEmptyDocument() {
}
@Test
- public void testDelete1() {
-
- try {
-
- fDocument.replace(21, 16, "");
+ public void testDelete1() throws BadLocationException, BadPositionCategoryException {
- } catch (BadLocationException x) {
- assertTrue("BadLocationException thrown", false);
- }
+ fDocument.replace(21, 16, "");
- Position[] positions= new Position[] {
+ Position[] positions = {
new Position( 0, 20),
new Position( 21, 0),
new Position( 22, 111),
@@ -127,35 +109,21 @@ public void testDelete1() {
}
@Test
- public void testEditScript1() {
+ public void testEditScript1() throws BadLocationException, BadPositionCategoryException {
// 1. step
+ fDocument.replace(0, fDocument.getLength(), "");
- try {
-
- fDocument.replace(0, fDocument.getLength(), "");
-
- } catch (BadLocationException x) {
- assertTrue("BadLocationException thrown", false);
- }
-
- Position[] positions= new Position[] {
- new Position( 0, 0)
- };
+ Position[] positions = { new Position(0, 0) };
checkPositions(positions);
// 2. step
- try {
-
- fDocument.replace(0, 0, "\t");
- } catch (BadLocationException x) {
- assertTrue("BadLocationException thrown", false);
- }
+ fDocument.replace(0, 0, "\t");
- positions= new Position[] {
+ positions = new Position[] {
new Position( 1, 0)
};
@@ -164,25 +132,18 @@ public void testEditScript1() {
}
@Test
- public void testFindPositions() {
-
- try {
-
- fDocument.addPosition(new Position( 21, 13));
- fDocument.addPosition(new Position( 0, 19));
- fDocument.addPosition(new Position( 21, 14));
- fDocument.addPosition(new Position( 21, 16));
- fDocument.addPosition(new Position( 0, 0));
- fDocument.addPosition(new Position( 104, 1));
- fDocument.addPosition(new Position( 120, 1));
- fDocument.addPosition(new Position( 119, 1));
-
- } catch (BadLocationException x) {
- assertTrue("initilization failed", false);
- }
-
-
- Position[] positions= new Position[] {
+ public void testFindPositions() throws BadLocationException, BadPositionCategoryException {
+
+ fDocument.addPosition(new Position(21, 13));
+ fDocument.addPosition(new Position(0, 19));
+ fDocument.addPosition(new Position(21, 14));
+ fDocument.addPosition(new Position(21, 16));
+ fDocument.addPosition(new Position(0, 0));
+ fDocument.addPosition(new Position(104, 1));
+ fDocument.addPosition(new Position(120, 1));
+ fDocument.addPosition(new Position(119, 1));
+
+ Position[] positions = {
new Position( 0, 0),
new Position( 0, 19),
new Position( 0, 20),
@@ -205,17 +166,10 @@ public void testFindPositions() {
}
@Test
- public void testInsert1() {
-
- try {
+ public void testInsert1() throws BadPositionCategoryException, BadLocationException {
+ fDocument.replace(0, 0, "//comment\n");
- fDocument.replace(0, 0, "//comment\n");
-
- } catch (BadLocationException x) {
- assertTrue("BadLocationException thrown", false);
- }
-
- Position[] positions= new Position[] {
+ Position[] positions = {
new Position( 10, 20),
new Position( 31, 15),
new Position( 48, 111),
@@ -229,15 +183,9 @@ public void testInsert1() {
}
@Test
- public void testInsert2() {
-
- try {
+ public void testInsert2() throws BadLocationException, BadPositionCategoryException {
- fDocument.replace(61, 0, "//comment\n");
-
- } catch (BadLocationException x) {
- assertTrue("BadLocationException thrown", false);
- }
+ fDocument.replace(61, 0, "//comment\n");
Position[] positions= new Position[] {
new Position( 0, 20),
@@ -253,17 +201,11 @@ public void testInsert2() {
}
@Test
- public void testInsert3() {
-
- try {
-
- fDocument.replace(101, 0, "//comment\n");
+ public void testInsert3() throws BadLocationException, BadPositionCategoryException {
- } catch (BadLocationException x) {
- assertTrue("BadLocationException thrown", false);
- }
+ fDocument.replace(101, 0, "//comment\n");
- Position[] positions= new Position[] {
+ Position[] positions = {
new Position( 0, 20),
new Position( 21, 15),
new Position( 38, 121),
@@ -277,19 +219,11 @@ public void testInsert3() {
}
@Test
- public void testInsert4() {
-
- try {
+ public void testInsert4() throws BadLocationException, BadPositionCategoryException {
- fDocument.replace(20, 0, "// comment");
-
- } catch (BadLocationException x) {
- assertTrue("BadLocationException thrown", false);
- }
+ fDocument.replace(20, 0, "// comment");
- System.out.print(fDocument.get());
-
- Position[] positions= new Position[] {
+ Position[] positions = {
new Position( 0, 20),
new Position( 31, 15),
new Position( 48, 111),
@@ -303,17 +237,11 @@ public void testInsert4() {
}
@Test
- public void testReplace1() {
-
- try {
-
- fDocument.replace(8, 11, "pkg1");
+ public void testReplace1() throws BadLocationException, BadPositionCategoryException {
- } catch (BadLocationException x) {
- assertTrue("BadLocationException thrown", false);
- }
+ fDocument.replace(8, 11, "pkg1");
- Position[] positions= new Position[] {
+ Position[] positions = {
new Position( 0, 13),
new Position( 14, 15),
new Position( 31, 111),
@@ -327,17 +255,11 @@ public void testReplace1() {
}
@Test
- public void testReplace2() {
-
- try {
+ public void testReplace2() throws BadLocationException, BadPositionCategoryException {
- fDocument.replace(21, 16, "//comment\n");
-
- } catch (BadLocationException x) {
- assertTrue("BadLocationException thrown", false);
- }
+ fDocument.replace(21, 16, "//comment\n");
- Position[] positions= new Position[] {
+ Position[] positions = {
new Position( 0, 20),
new Position( 31, 0),
new Position( 32, 111),
@@ -351,38 +273,22 @@ public void testReplace2() {
}
@Test
- public void testReplace3() {
-
- Position[] actual= new Position[] {
- new Position(0, 150),
- };
-
- try {
+ public void testReplace3() throws BadLocationException {
- fDocument.addPosition(actual[0]);
- fDocument.replace(0, 150, "xxxxxxxxxx");
+ Position[] actual = { new Position(0, 150), };
- } catch (BadLocationException x) {
- assertTrue("BadLocationException thrown", false);
- }
+ fDocument.addPosition(actual[0]);
+ fDocument.replace(0, 150, "xxxxxxxxxx");
- Position[] expected= new Position[] {
- new Position(0, 10)
- };
+ Position[] expected = { new Position(0, 10) };
checkPositions(expected, actual);
}
@Test
- public void testReplace4() {
-
- try {
+ public void testReplace4() throws BadLocationException, BadPositionCategoryException {
- fDocument.replace(19, 1, "xxxxx;");
-
- } catch (BadLocationException x) {
- assertTrue("BadLocationException thrown", false);
- }
+ fDocument.replace(19, 1, "xxxxx;");
Position[] positions= new Position[] {
new Position( 0, 25),
@@ -398,43 +304,27 @@ public void testReplace4() {
}
@Test
- public void testAppend() {
+ public void testAppend() throws BadLocationException {
- Position[] actual= new Position[] {
- new Position(0, 2),
- };
-
- try {
+ Position[] actual = { new Position(0, 2), };
- fDocument.replace(0, 150, "");
- fDocument.replace(fDocument.getLength(), 0, "xx");
- fDocument.addPosition(actual[0]);
- fDocument.replace(fDocument.getLength(), 0, "xxxxxxxx");
-
- } catch (BadLocationException x) {
- assertTrue("BadLocationException thrown", false);
- }
+ fDocument.replace(0, 150, "");
+ fDocument.replace(fDocument.getLength(), 0, "xx");
+ fDocument.addPosition(actual[0]);
+ fDocument.replace(fDocument.getLength(), 0, "xxxxxxxx");
- Position[] expected= new Position[] {
- new Position(0, 2)
- };
+ Position[] expected = { new Position(0, 2) };
checkPositions(expected, actual);
}
@Test
- public void testShiftLeft() {
-
- try {
+ public void testShiftLeft() throws BadLocationException, BadPositionCategoryException {
- fDocument.replace(73, 1, "");
- fDocument.replace(98, 1, "");
+ fDocument.replace(73, 1, "");
+ fDocument.replace(98, 1, "");
- } catch (BadLocationException x) {
- assertTrue("BadLocationException thrown", false);
- }
-
- Position[] positions= new Position[] {
+ Position[] positions = {
new Position( 0, 20),
new Position( 21, 15),
new Position( 38, 109),
@@ -448,18 +338,12 @@ public void testShiftLeft() {
}
@Test
- public void testShiftRight() {
+ public void testShiftRight() throws BadLocationException, BadPositionCategoryException {
- try {
+ fDocument.replace(73, 0, "\t");
+ fDocument.replace(100, 0, "\t");
- fDocument.replace( 73, 0, "\t");
- fDocument.replace(100, 0, "\t");
-
- } catch (BadLocationException x) {
- assertTrue("BadLocationException thrown", false);
- }
-
- Position[] positions= new Position[] {
+ Position[] positions = {
new Position( 0, 20),
new Position( 21, 15),
new Position( 38, 113),
diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/SelectionListenerFactoryTest.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/SelectionListenerFactoryTest.java
index db67043a1eb..2e68d847d09 100644
--- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/SelectionListenerFactoryTest.java
+++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/SelectionListenerFactoryTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2019 Remain Software and others.
+ * Copyright (c) 2019, 2024 Remain Software and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -13,6 +13,10 @@
*******************************************************************************/
package org.eclipse.ui.tests.api;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThrows;
+import static org.junit.Assert.assertTrue;
+
import java.util.function.Predicate;
import org.eclipse.core.runtime.IAdapterFactory;
@@ -30,17 +34,17 @@
import org.eclipse.ui.SelectionListenerFactory.ISelectionModel;
import org.eclipse.ui.SelectionListenerFactory.Predicates;
import org.eclipse.ui.tests.SelectionProviderView;
+import org.eclipse.ui.tests.harness.util.CloseTestWindowsRule;
import org.eclipse.ui.tests.harness.util.UITestCase;
+import org.junit.Before;
import org.junit.Ignore;
+import org.junit.Rule;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
/**
* Tests the ISelectionService class.
*/
-@RunWith(JUnit4.class)
-public class SelectionListenerFactoryTest extends UITestCase implements ISelectionListener {
+public class SelectionListenerFactoryTest implements ISelectionListener {
private static final String KNOCK_KNOCK = "KnockKnock";
private IWorkbenchWindow fWindow;
@@ -50,15 +54,12 @@ public class SelectionListenerFactoryTest extends UITestCase implements ISelecti
private boolean fEventReceived;
private int fCounter;
+ @Rule
+ public final CloseTestWindowsRule closeTestWindows = new CloseTestWindowsRule();
- public SelectionListenerFactoryTest() {
- super(SelectionListenerFactoryTest.class.getSimpleName());
- }
-
- @Override
- protected void doSetUp() throws Exception {
- super.doSetUp();
- fWindow = openTestWindow();
+ @Before
+ public void doSetUp() throws Exception {
+ fWindow = UITestCase.openTestWindow();
fPage = fWindow.getActivePage();
}
@@ -593,12 +594,7 @@ public void testUserPredicateT4() throws Throwable {
@Test
public void testCreateListenerTest() throws Throwable {
SelectionProviderView view = (SelectionProviderView) fPage.showView(SelectionProviderView.ID);
- try {
- SelectionListenerFactory.createListener(view, m -> true);
- assertTrue("ClassCastException expected", false);
- } catch (ClassCastException e) {
- return;
- }
+ assertThrows(ClassCastException.class, () -> SelectionListenerFactory.createListener(view, m -> true));
}
/**
diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/markers/MarkersViewColumnSizeTest.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/markers/MarkersViewColumnSizeTest.java
index b3c6feddcb2..657632ecd44 100644
--- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/markers/MarkersViewColumnSizeTest.java
+++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/markers/MarkersViewColumnSizeTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2012 IBM Corporation and others.
+ * Copyright (c) 2008, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -52,11 +52,11 @@ public void testColumnCreate() {
IWorkbenchWindow window = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow();
if (window == null) {
- assertTrue("Could not get a workbench window", false);
+ fail("Could not get a workbench window");
}
IWorkbenchPage page = window.getActivePage();
if (page == null) {
- assertTrue("Could not get a workbench page", false);
+ fail("Could not get a workbench page");
}
MarkersTestMarkersView problemView;
@@ -64,7 +64,7 @@ public void testColumnCreate() {
problemView = (MarkersTestMarkersView) page
.showView("org.eclipse.ui.tests.markerTests");
} catch (PartInitException e) {
- assertTrue(e.getLocalizedMessage(), false);
+ fail(e.getLocalizedMessage());
return;
}
@@ -77,11 +77,11 @@ public void testColumnRestore() {
IWorkbenchWindow window = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow();
if (window == null) {
- assertTrue("Could not get a workbench window", false);
+ fail("Could not get a workbench window");
}
IWorkbenchPage page = window.getActivePage();
if (page == null) {
- assertTrue("Could not get a workbench page", false);
+ fail("Could not get a workbench page");
}
MarkersTestMarkersView problemView;
@@ -89,7 +89,7 @@ public void testColumnRestore() {
problemView = (MarkersTestMarkersView) page
.showView("org.eclipse.ui.tests.markerTests");
} catch (PartInitException e) {
- assertTrue(e.getLocalizedMessage(), false);
+ fail(e.getLocalizedMessage());
return;
}
diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/markers/ResourceMappingMarkersTest.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/markers/ResourceMappingMarkersTest.java
index bd938b5bf3f..5b985976b4a 100644
--- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/markers/ResourceMappingMarkersTest.java
+++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/markers/ResourceMappingMarkersTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2009 IBM Corporation and others.
+ * Copyright (c) 2005, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -56,7 +56,7 @@ public void testResourceMappings() {
view = (ResourceMappingTestView) page
.showView("org.eclipse.ui.tests.resourceMappingView");
} catch (PartInitException e) {
- assertTrue(e.getLocalizedMessage(), false);
+ fail(e.getLocalizedMessage());
return;
}
@@ -65,7 +65,7 @@ public void testResourceMappings() {
problemView = (MarkersTestMarkersView) page
.showView("org.eclipse.ui.tests.markerTests");
} catch (PartInitException e) {
- assertTrue(e.getLocalizedMessage(), false);
+ fail(e.getLocalizedMessage());
return;
}
diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/operations/OperationsAPITest.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/operations/OperationsAPITest.java
index 24126bf87c4..e8ea646c995 100644
--- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/operations/OperationsAPITest.java
+++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/operations/OperationsAPITest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2006 IBM Corporation and others.
+ * Copyright (c) 2005, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -20,6 +20,7 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.operations.AbstractOperation;
@@ -65,10 +66,6 @@ public class OperationsAPITest {
int preExec, postExec, preUndo, postUndo, preRedo, postRedo, add, remove, notOK, changed = 0;
IOperationHistoryListener listener;
- public OperationsAPITest() {
- super();
- }
-
@Before
public void setUp() throws Exception {
history = new DefaultOperationHistory();
@@ -279,7 +276,7 @@ public IStatus redo(IProgressMonitor monitor, IAdaptable uiInfo) {
history.openOperation(new TriggeredOperations(op3, history), IOperationHistory.EXECUTE);
history.closeOperation(true, true, IOperationHistory.EXECUTE);
} catch (IllegalStateException e) {
- assertTrue("IllegalStateException - trying to open an operation before a close", false);
+ fail("IllegalStateException - trying to open an operation before a close");
}
}
@@ -836,7 +833,7 @@ public IStatus proceedRedoing(IUndoableOperation op, IOperationHistory history,
history.undoOperation(op5, null, null);
assertTrue("Operation approver should run only once for direct undo", approvalCount[0]== 1);
history.redoOperation(op5, null, null);
- assertTrue("Operation approver should run only once for direct redo", approvalCount[0]== 0);
+ assertTrue("Operation approver should run only once for direct redo", approvalCount[0] == 0);
// cleanup
history.removeOperationApprover(approver);
diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/propertyPages/PropertyPageEnablementTest.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/propertyPages/PropertyPageEnablementTest.java
index 463b40db109..a790d408c3e 100644
--- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/propertyPages/PropertyPageEnablementTest.java
+++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/propertyPages/PropertyPageEnablementTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2017 IBM Corporation and others.
+ * Copyright (c) 2006, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -56,7 +56,7 @@ public void testAndPage() {
return;
}
}
- assertTrue("And property page for file not found", false);
+ fail("And property page for file not found");
contributors = PropertyPageContributorManager.getManager().getApplicableContributors(testFolder);
for (RegistryPageContributor element : contributors) {
diff --git a/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/workbench/texteditor/tests/HippieCompletionTest.java b/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/workbench/texteditor/tests/HippieCompletionTest.java
index 2a122a41631..30b5059e2c7 100644
--- a/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/workbench/texteditor/tests/HippieCompletionTest.java
+++ b/tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/workbench/texteditor/tests/HippieCompletionTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2015 IBM Corporation and others.
+ * Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -50,69 +50,72 @@ public class HippieCompletionTest {
@Before
public void setUp() throws Exception {
documents= new IDocument[5];
- documents[0]= new Document("package ui.TestPackage;\n" +
- "\n" +
- "/**\n" +
- " * This is a testing class that tests the hippie completion engine.\n" +
- " * it has a simple main with a print method\n" +
- " */\n" +
- "public class TestClass1 {\n" +
- "\n" +
- " public static void main(String[] args) {\n" +
- " System.out.println(\"I will be printing Hello world!\");\n" +
- " }\n" +
- "}");
+ documents[0]= new Document("""
+ package ui.TestPackage;
+
+ /**
+ * This is a testing class that tests the hippie completion engine.
+ * it has a simple main with a print method
+ */
+ public class TestClass1 {
+
+ public static void main(String[] args) {
+ System.out.println("I will be printing Hello world!");
+ }
+ }""");
documents[1]= new Document("This is a simple text file\n" +
"with some testssome test that is also used in the completion engine tests");
- documents[2]= new Document("\n" +
- "\n" +
- "\n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" +
- "\n" +
- "");
-
- documents[3]= new Document("###############################################################################\n" +
- "# Copyright (c) 2000, 2004 IBM Corporation and others.\n" +
- "\\n"+
- "# This program and the accompanying materials \n" +
- "# are made available under the terms of the Eclipse Public License 2.0\n" +
- "# which accompanies this distribution, and is available at\n" +
- "# https://www.eclipse.org/legal/epl-2.0/"+
- "# \n"+
- "# SPDX-License-Identifier: EPL-2.0\n" +
- "# \n" +
- "# Contributors:\n" +
- "# IBM Corporation - initial API and implementation\n" +
- "###############################################################################\n" +
- "bin.includes= plugin.xml,\\\n" +
- " plugin.properties,\\\n" +
- " test.xml,\\\n" +
- " about.html,\\\n" +
- " *.jar\n" +
- "\n" +
- "src.includes= about.html\n" +
- " \n" +
- "source.workbenchtexteditortests.jar= src/\n" +
- "");
+ documents[2]= new Document("""
+
+
+
+
+
+
+
+
+ \s
+
+
+
+
+
+
+
+
+ \s
+
+ """);
+
+ documents[3]= new Document("""
+ ###############################################################################
+ # Copyright (c) 2000, 2004 IBM Corporation and others.
+ \\n\
+ # This program and the accompanying materials\s
+ # are made available under the terms of the Eclipse Public License 2.0
+ # which accompanies this distribution, and is available at
+ # https://www.eclipse.org/legal/epl-2.0/\
+ #\s
+ # SPDX-License-Identifier: EPL-2.0
+ #\s
+ # Contributors:
+ # IBM Corporation - initial API and implementation
+ ###############################################################################
+ bin.includes= plugin.xml,\\
+ plugin.properties,\\
+ test.xml,\\
+ about.html,\\
+ *.jar
+
+ src.includes= about.html
+ \s
+ source.workbenchtexteditortests.jar= src/
+ """);
documents[4]= new Document("/**\n" +
" * This class tests the hippie completion functionality.\n" +
" * \u05D4\u05DE\u05D7\u05DC\u05E7\u05D4 \u05D4\u05D6\u05D5 \u05D1\u05D5\u05D3\u05E7\u05EA \u05D0\u05EA \u05DE\u05E0\u05D2\u05E0\u05D5\u05DF \u05D4\u05D4\u05E9\u05DC\u05DE\u05D5\u05EA\n" +
@@ -143,74 +146,62 @@ public void setUp() throws Exception {
}
@Test
- public void testSearchBackwards1() {
- try {
- List list= fEngine.getCompletionsBackwards(documents[0],
- "pri", documents[0].get().indexOf("println") + 10);
- assertEquals(list.size(), 2);
- assertEquals(list.get(0), "ntln");
- assertEquals(list.get(1), "nt");
-
- list= fEngine.getCompletionsBackwards(documents[0],
- "pri", documents[0].getLength());
- assertEquals(list.size(), 3);
- assertEquals(list.get(0), "nting");
- assertEquals(list.get(1), "ntln");
- assertEquals(list.get(2), "nt");
-
- list= fEngine.getCompletionsBackwards(documents[0],
- "pri", documents[0].get().indexOf("println") + 1);
- assertEquals(list.size(), 1);
- assertEquals(list.get(0), "nt");
-
- list= fEngine.getCompletionsBackwards(documents[0],
- "pa", 2);
- assertEquals(list.size(), 0);
-
- } catch (BadLocationException e) {
- assertTrue("Got out of document bounds", false);
- }
+ public void testSearchBackwards1() throws BadLocationException {
+ List list= fEngine.getCompletionsBackwards(documents[0],
+ "pri", documents[0].get().indexOf("println") + 10);
+ assertEquals(list.size(), 2);
+ assertEquals(list.get(0), "ntln");
+ assertEquals(list.get(1), "nt");
+
+ list= fEngine.getCompletionsBackwards(documents[0],
+ "pri", documents[0].getLength());
+ assertEquals(list.size(), 3);
+ assertEquals(list.get(0), "nting");
+ assertEquals(list.get(1), "ntln");
+ assertEquals(list.get(2), "nt");
+
+ list= fEngine.getCompletionsBackwards(documents[0],
+ "pri", documents[0].get().indexOf("println") + 1);
+ assertEquals(list.size(), 1);
+ assertEquals(list.get(0), "nt");
+
+ list= fEngine.getCompletionsBackwards(documents[0],
+ "pa", 2);
+ assertEquals(list.size(), 0);
+
}
@Test
- public void testSearchBackwards2() {
- try {
- List list= fEngine.getCompletionsBackwards(documents[2],
- "plugi", documents[2].getLength());
- assertEquals(8, list.size());
- list= fEngine.makeUnique(list);
- assertEquals(1, list.size());
- assertEquals("n", list.get(0));
-
- list= fEngine.getCompletionsBackwards(documents[2],
- "plugin", documents[2].getLength());
- assertEquals(0, list.size()); // empty completions discarded
-
- } catch (BadLocationException e) {
- assertTrue("Got out of document bounds", false);
- }
+ public void testSearchBackwards2() throws BadLocationException {
+ List list= fEngine.getCompletionsBackwards(documents[2],
+ "plugi", documents[2].getLength());
+ assertEquals(8, list.size());
+ list= fEngine.makeUnique(list);
+ assertEquals(1, list.size());
+ assertEquals("n", list.get(0));
+
+ list= fEngine.getCompletionsBackwards(documents[2],
+ "plugin", documents[2].getLength());
+ assertEquals(0, list.size()); // empty completions discarded
+
}
@Test
- public void testSearchBackwards3() {
- try {
- List list= fEngine.getCompletionsBackwards(documents[1],
- "test", documents[1].getLength());
- assertEquals("Number of backwards suggestions does not match", 2, list.size());
- list= fEngine.getCompletionsBackwards(documents[1],
- "tests", documents[1].getLength());
- assertEquals("Number of backwards suggestions does not match", 1, list.size());
-
- list= fEngine.getCompletionsBackwards(documents[1],
- "test", documents[1].getLength() - 1);
- assertEquals("Number of backwards suggestions does not match", 1, list.size());
- } catch (BadLocationException e) {
- assertTrue("Got out of document bounds", false);
- }
+ public void testSearchBackwards3() throws BadLocationException {
+ List list= fEngine.getCompletionsBackwards(documents[1],
+ "test", documents[1].getLength());
+ assertEquals("Number of backwards suggestions does not match", 2, list.size());
+ list= fEngine.getCompletionsBackwards(documents[1],
+ "tests", documents[1].getLength());
+ assertEquals("Number of backwards suggestions does not match", 1, list.size());
+
+ list= fEngine.getCompletionsBackwards(documents[1],
+ "test", documents[1].getLength() - 1);
+ assertEquals("Number of backwards suggestions does not match", 1, list.size());
}
@Test
- public void testSearch() {
+ public void testSearch() throws BadLocationException {
ArrayList docsList= new ArrayList<>(Arrays.asList(this.documents));
List result= createSuggestions("te", docsList);
assertEquals("Number of completions does not match", 15, result.size());
@@ -237,7 +228,7 @@ public void testSearch() {
}
@Test
- public void testSearch2() {
+ public void testSearch2() throws BadLocationException {
ArrayList docsList= new ArrayList<>(Arrays.asList(this.documents));
List result= createSuggestions("printe", docsList);
assertEquals("Number of completions does not match", 0, result.size());
@@ -250,116 +241,102 @@ public void testSearch2() {
}
@Test
- public void testForwardSearch() {
- try {
- List result= fEngine.getCompletionsForward(documents[0],
- "cl", documents[0].get().indexOf("cl"), true);
- assertEquals(2, result.size());
-
- result= fEngine.getCompletionsForward(documents[0],
- "cl", documents[0].get().indexOf("cl") + 1, true);
- assertEquals(1, result.size());
-
- result= fEngine.getCompletionsForward(documents[1],
- "Thi", 0, true);
- assertEquals(1, result.size());
-
- result= fEngine.getCompletionsForward(documents[1],
- "Thi", 1, true);
- assertEquals(0, result.size());
- } catch (BadLocationException e) {
- assertTrue("Got out of document bounds", false);
- }
+ public void testForwardSearch() throws BadLocationException {
+ List result= fEngine.getCompletionsForward(documents[0],
+ "cl", documents[0].get().indexOf("cl"), true);
+ assertEquals(2, result.size());
+
+ result= fEngine.getCompletionsForward(documents[0],
+ "cl", documents[0].get().indexOf("cl") + 1, true);
+ assertEquals(1, result.size());
+
+ result= fEngine.getCompletionsForward(documents[1],
+ "Thi", 0, true);
+ assertEquals(1, result.size());
+
+ result= fEngine.getCompletionsForward(documents[1],
+ "Thi", 1, true);
+ assertEquals(0, result.size());
}
@Test
- public void testForwardSearchInternational() {
- List result;
- try {
- result= fEngine.getCompletionsForward(documents[4],
- "$", documents[4].get().indexOf('$'), true);
- assertEquals(2, result.size());
- assertEquals("arabic\u20AAWord", result.get(0));
- assertEquals("arabic\u20ACDigits", result.get(1));
-
- result= fEngine.getCompletionsForward(documents[4],
- "$", documents[4].get().indexOf('$'), false);
- assertEquals(2, result.size());
- assertEquals("arabic\u20ACDigits", result.get(0));
- assertEquals("arabic\u20AAWord", result.get(1));
-
- result= fEngine.getCompletionsForward(documents[4],
- "$", documents[4].get().indexOf('$') + 1, true);
- assertEquals(1, result.size());
- assertEquals("arabic\u20AAWord", result.get(0));
- } catch (BadLocationException e) {
- assertTrue("Got out of document bounds", false);
- }
+ public void testForwardSearchInternational() throws BadLocationException {
+ List result= fEngine.getCompletionsForward(documents[4],
+ "$", documents[4].get().indexOf('$'), true);
+ assertEquals(2, result.size());
+ assertEquals("arabic\u20AAWord", result.get(0));
+ assertEquals("arabic\u20ACDigits", result.get(1));
+
+ result= fEngine.getCompletionsForward(documents[4],
+ "$", documents[4].get().indexOf('$'), false);
+ assertEquals(2, result.size());
+ assertEquals("arabic\u20ACDigits", result.get(0));
+ assertEquals("arabic\u20AAWord", result.get(1));
+
+ result= fEngine.getCompletionsForward(documents[4],
+ "$", documents[4].get().indexOf('$') + 1, true);
+ assertEquals(1, result.size());
+ assertEquals("arabic\u20AAWord", result.get(0));
}
@Test
- public void testPrefix() {
- try {
- String prefix= fEngine.getPrefixString(documents[0],
- documents[0].get().indexOf("testing") + 3);
- assertEquals(prefix, "tes");
-
- prefix= fEngine.getPrefixString(documents[0],
- documents[0].get().indexOf("public") + 4);
- assertEquals(prefix, "publ");
+ public void testPrefix() throws BadLocationException {
+ String prefix= fEngine.getPrefixString(documents[0],
+ documents[0].get().indexOf("testing") + 3);
+ assertEquals(prefix, "tes");
- prefix= fEngine.getPrefixString(documents[0],
- documents[0].get().indexOf("println") + 7);
- assertEquals(prefix, "println");
+ prefix= fEngine.getPrefixString(documents[0],
+ documents[0].get().indexOf("public") + 4);
+ assertEquals(prefix, "publ");
- prefix= fEngine.getPrefixString(documents[0],
- documents[0].get().indexOf("println") + 8);
- assertEquals(prefix, null);
+ prefix= fEngine.getPrefixString(documents[0],
+ documents[0].get().indexOf("println") + 7);
+ assertEquals(prefix, "println");
- prefix= fEngine.getPrefixString(documents[1], 3);
- assertEquals(prefix, "Thi");
+ prefix= fEngine.getPrefixString(documents[0],
+ documents[0].get().indexOf("println") + 8);
+ assertEquals(prefix, null);
- prefix= fEngine.getPrefixString(documents[1], 0);
- assertEquals(prefix, null);
+ prefix= fEngine.getPrefixString(documents[1], 3);
+ assertEquals(prefix, "Thi");
- prefix= fEngine.getPrefixString(documents[1], documents[1].getLength());
- assertEquals(prefix, "tests");
+ prefix= fEngine.getPrefixString(documents[1], 0);
+ assertEquals(prefix, null);
- prefix= fEngine.getPrefixString(documents[3],
- documents[3].get().indexOf("Copyright") - 2);
- assertEquals(prefix, null);
+ prefix= fEngine.getPrefixString(documents[1], documents[1].getLength());
+ assertEquals(prefix, "tests");
- prefix= fEngine.getPrefixString(documents[4],
- documents[4].get().indexOf("IDE") + 2);
- assertEquals(prefix, "ID");
+ prefix= fEngine.getPrefixString(documents[3],
+ documents[3].get().indexOf("Copyright") - 2);
+ assertEquals(prefix, null);
- prefix= fEngine.getPrefixString(documents[4],
- documents[4].get().indexOf("$arabic\u20ACDigits") + 8);
- assertEquals(prefix, "$arabic\u20AC");
+ prefix= fEngine.getPrefixString(documents[4],
+ documents[4].get().indexOf("IDE") + 2);
+ assertEquals(prefix, "ID");
- prefix= fEngine.getPrefixString(documents[4],
- documents[4].get().indexOf("$arabic\u20AAWord") + 8);
- assertEquals(prefix, "$arabic\u20AA");
+ prefix= fEngine.getPrefixString(documents[4],
+ documents[4].get().indexOf("$arabic\u20ACDigits") + 8);
+ assertEquals(prefix, "$arabic\u20AC");
- prefix= fEngine.getPrefixString(documents[4],
- documents[4].get().indexOf("\u00A3\u0661\u0662\u0663") + 3);
- assertEquals(prefix, "\u00A3\u0661\u0662");
+ prefix= fEngine.getPrefixString(documents[4],
+ documents[4].get().indexOf("$arabic\u20AAWord") + 8);
+ assertEquals(prefix, "$arabic\u20AA");
- prefix= fEngine.getPrefixString(documents[4],
- documents[4].get().indexOf("a\u0300\u0301b") + 3);
- assertEquals(prefix, "a\u0300\u0301");
+ prefix= fEngine.getPrefixString(documents[4],
+ documents[4].get().indexOf("\u00A3\u0661\u0662\u0663") + 3);
+ assertEquals(prefix, "\u00A3\u0661\u0662");
- prefix= fEngine.getPrefixString(documents[4],
- documents[4].get().indexOf("\u0667\u0668\u0669\u0660") + 2);
- assertEquals(prefix, "\u0667\u0668");
+ prefix= fEngine.getPrefixString(documents[4],
+ documents[4].get().indexOf("a\u0300\u0301b") + 3);
+ assertEquals(prefix, "a\u0300\u0301");
- } catch (BadLocationException e) {
- assertTrue("Got out of document bounds", false);
- }
+ prefix= fEngine.getPrefixString(documents[4],
+ documents[4].get().indexOf("\u0667\u0668\u0669\u0660") + 2);
+ assertEquals(prefix, "\u0667\u0668");
}
@Test
- public void testInternational() {
+ public void testInternational() throws BadLocationException {
IDocument intlDoc= documents[4];
List result= createSuggestions("\u05D4", intlDoc); // hebrew letter heh
@@ -426,33 +403,29 @@ public void testInternational() {
}
@Test
- public void testInternationalBackwards() {
+ public void testInternationalBackwards() throws BadLocationException {
IDocument intlDoc= documents[4];
- try {
- List list= fEngine.getCompletionsBackwards(intlDoc,
- "\u043B\u0443", intlDoc.get().indexOf("129"));
- assertEquals(2, list.size());
- assertEquals(list.get(0), "\u0447\u0448");
- assertEquals(list.get(1), "\u0447\u0448\u0438\u0439");
-
- list= fEngine.getCompletionsBackwards(intlDoc,
- "\u05DE", intlDoc.get().lastIndexOf('+'));
- assertEquals(2, list.size());
- assertEquals(list.get(0), "\u05D7");
- assertEquals(list.get(1), "\u05E0\u05D2\u05E0\u05D5\u05DF");
-
- list= fEngine.getCompletionsBackwards(intlDoc,
- "\u0667", intlDoc.get().indexOf("\u2021\u0667") + 1);
- assertEquals(0, list.size());
-
- list= fEngine.getCompletionsBackwards(intlDoc,
- "\u0628", intlDoc.get().lastIndexOf("\u0628"));
- assertEquals(1, list.size());
- assertEquals(list.get(0), "\u064E\u0627\u0628\u0650");
-
- } catch (BadLocationException e) {
- assertTrue("Got out of document bounds", false);
- }
+ List list= fEngine.getCompletionsBackwards(intlDoc,
+ "\u043B\u0443", intlDoc.get().indexOf("129"));
+ assertEquals(2, list.size());
+ assertEquals(list.get(0), "\u0447\u0448");
+ assertEquals(list.get(1), "\u0447\u0448\u0438\u0439");
+
+ list= fEngine.getCompletionsBackwards(intlDoc,
+ "\u05DE", intlDoc.get().lastIndexOf('+'));
+ assertEquals(2, list.size());
+ assertEquals(list.get(0), "\u05D7");
+ assertEquals(list.get(1), "\u05E0\u05D2\u05E0\u05D5\u05DF");
+
+ list= fEngine.getCompletionsBackwards(intlDoc,
+ "\u0667", intlDoc.get().indexOf("\u2021\u0667") + 1);
+ assertEquals(0, list.size());
+
+ list= fEngine.getCompletionsBackwards(intlDoc,
+ "\u0628", intlDoc.get().lastIndexOf("\u0628"));
+ assertEquals(1, list.size());
+ assertEquals(list.get(0), "\u064E\u0627\u0628\u0650");
+
}
private Accessor createAccessor(Iterator suggestions, int startOffset) {
@@ -593,18 +566,14 @@ public void testIteration() throws Exception {
}
- private List createSuggestions(String prefix, IDocument doc) {
+ private List createSuggestions(String prefix, IDocument doc) throws BadLocationException {
return createSuggestions(prefix, Arrays.asList(new IDocument[]{doc}));
}
- private List createSuggestions(String prefix, List docsList) {
+ private List createSuggestions(String prefix, List docsList) throws BadLocationException {
ArrayList results= new ArrayList<>();
for (IDocument doc : docsList) {
- try {
- results.addAll(fEngine.getCompletionsForward(doc, prefix, 0, false));
- } catch (BadLocationException e) {
- assertTrue("No exception should be thrown here", false);
- }
+ results.addAll(fEngine.getCompletionsForward(doc, prefix, 0, false));
}
return results;
}