Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kurtakov2020-02-10 10:13:28 +0000
committerAlexander Kurtakov2020-02-10 21:19:06 +0000
commit3f839bb8f50d453ebe2112549b93a1c41342207c (patch)
tree651df8811f381f0a022dcd05a10d7a6b9346acad
parent83e3ecbc3b9842bb8cc66a1b15852475d66ea474 (diff)
downloadeclipse.platform.text-3f839bb8f50d453ebe2112549b93a1c41342207c.tar.gz
eclipse.platform.text-3f839bb8f50d453ebe2112549b93a1c41342207c.tar.xz
eclipse.platform.text-3f839bb8f50d453ebe2112549b93a1c41342207c.zip
Convert JUnit 3.x style tests to 4.x
Change-Id: Id92946c5fc43ce53ebf362ee986fa986543686fc Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
-rw-r--r--org.eclipse.search.tests/src/org/eclipse/search/core/tests/LineConversionTest.java33
-rw-r--r--org.eclipse.text.tests/src/org/eclipse/text/tests/DefaultLineTrackerTest.java40
-rw-r--r--org.eclipse.text.tests/src/org/eclipse/text/tests/DocumentUndoManagerTest.java321
3 files changed, 181 insertions, 213 deletions
diff --git a/org.eclipse.search.tests/src/org/eclipse/search/core/tests/LineConversionTest.java b/org.eclipse.search.tests/src/org/eclipse/search/core/tests/LineConversionTest.java
index 03096f20919..5f11f009ded 100644
--- a/org.eclipse.search.tests/src/org/eclipse/search/core/tests/LineConversionTest.java
+++ b/org.eclipse.search.tests/src/org/eclipse/search/core/tests/LineConversionTest.java
@@ -14,8 +14,15 @@
package org.eclipse.search.core.tests;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
+
import java.io.ByteArrayInputStream;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
@@ -33,38 +40,37 @@ import org.eclipse.search.tests.SearchTestPlugin;
import org.eclipse.search2.internal.ui.text.PositionTracker;
-import junit.framework.TestCase;
-
/**
*/
-public class LineConversionTest extends TestCase {
+public class LineConversionTest {
private IFile fFile;
private static final String LINE_TWO= "This is the second line\n";
+
private static final String LINE_ONE= "This is the first line\n";
+
private static final String LINE_THREE= "This is the third line";
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
IProject project= ResourcesPlugin.getWorkspace().getRoot().getProject("Test");
project.create(null);
project.open(null);
fFile= project.getFile("/test.txt");
fFile.create(new ByteArrayInputStream(getFileContents().getBytes()), true, null);
- super.setUp();
}
- @Override
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() throws Exception {
SearchPlugin.getActivePage().closeAllEditors(false);
fFile.getProject().delete(true, true, null);
- super.tearDown();
}
private String getFileContents() {
- return LINE_ONE+LINE_TWO+LINE_THREE;
+ return LINE_ONE + LINE_TWO + LINE_THREE;
}
+ @Test
public void testConvertToCharacter() throws Exception {
SearchTestPlugin.openTextEditor(SearchPlugin.getActivePage(), fFile);
ITextFileBuffer fb= FileBuffers.getTextFileBufferManager().getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE);
@@ -91,17 +97,14 @@ public class LineConversionTest extends TestCase {
assertEquals(p1, PositionTracker.convertToLinePosition(p2, doc));
}
+ @Test
public void testBogusLines() throws Exception {
SearchTestPlugin.openTextEditor(SearchPlugin.getActivePage(), fFile);
ITextFileBuffer fb= FileBuffers.getTextFileBufferManager().getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE);
IDocument doc= fb.getDocument();
Position p1= new Position(2, 67);
- try {
- PositionTracker.convertToCharacterPosition(p1, doc);
- assertTrue("shouldn't happen", false);
- } catch (BadLocationException e) {
- }
+ assertThrows(BadLocationException.class, () -> PositionTracker.convertToCharacterPosition(p1, doc));
}
public void atestLineOffsets() throws Exception {
diff --git a/org.eclipse.text.tests/src/org/eclipse/text/tests/DefaultLineTrackerTest.java b/org.eclipse.text.tests/src/org/eclipse/text/tests/DefaultLineTrackerTest.java
index d9ff36adb52..92a2cc21c88 100644
--- a/org.eclipse.text.tests/src/org/eclipse/text/tests/DefaultLineTrackerTest.java
+++ b/org.eclipse.text.tests/src/org/eclipse/text/tests/DefaultLineTrackerTest.java
@@ -13,42 +13,28 @@
*******************************************************************************/
package org.eclipse.text.tests;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
+import static org.junit.Assert.assertEquals;
-import org.junit.Assert;
+import org.junit.Test;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
-public class DefaultLineTrackerTest extends TestCase {
+public class DefaultLineTrackerTest {
- public DefaultLineTrackerTest(String name) {
- super(name);
- }
-
- public static Test suite() {
- return new TestSuite(DefaultLineTrackerTest.class);
- }
-
- public void testLineDelimiter() {
- IDocument document= new Document("abc\r\n123\r\nxyz");
- Assert.assertTrue(document.getNumberOfLines() == 3);
+ @Test
+ public void testLineDelimiter() throws BadLocationException {
+ IDocument document = new Document("abc\r\n123\r\nxyz");
+ assertEquals(3, document.getNumberOfLines());
- try {
-
- for (int i= 0; i < 2; i++) {
- Assert.assertTrue(document.getLineLength(i) == 5);
- Assert.assertEquals(document.getLineDelimiter(i), "\r\n");
- }
+ for (int i = 0; i < 2; i++) {
+ assertEquals(5, document.getLineLength(i));
+ assertEquals(document.getLineDelimiter(i), "\r\n");
+ }
- Assert.assertTrue(document.getLineLength(2) == 3);
- Assert.assertEquals(document.getLineDelimiter(2), null);
+ assertEquals(3, document.getLineLength(2));
+ assertEquals(document.getLineDelimiter(2), null);
- } catch (BadLocationException x) {
- Assert.fail();
- }
}
}
diff --git a/org.eclipse.text.tests/src/org/eclipse/text/tests/DocumentUndoManagerTest.java b/org.eclipse.text.tests/src/org/eclipse/text/tests/DocumentUndoManagerTest.java
index 95c26b4c9ef..1a32a77353e 100644
--- a/org.eclipse.text.tests/src/org/eclipse/text/tests/DocumentUndoManagerTest.java
+++ b/org.eclipse.text.tests/src/org/eclipse/text/tests/DocumentUndoManagerTest.java
@@ -13,7 +13,14 @@
*******************************************************************************/
package org.eclipse.text.tests;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
import org.eclipse.core.commands.ExecutionException;
@@ -28,82 +35,80 @@ import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.Position;
-
/**
* Tests for DefaultUndoManager.
*
* @since 3.5
*/
-public class DocumentUndoManagerTest extends TestCase {
-
+public class DocumentUndoManagerTest {
/** The maximum undo level. */
- private static final int MAX_UNDO_LEVEL= 256;
+ private static final int MAX_UNDO_LEVEL = 256;
-
- //--- Static data sets for comparing scenarios - obtained from capturing random data ---
+ // --- Static data sets for comparing scenarios - obtained from capturing random
+ // data ---
/** Original document */
- private static final String INITIAL_DOCUMENT_CONTENT= "+7cyg:/F!T4KnW;0+au$t1G%(`Z|u'7'_!-k?<c\"2Y.]CwsO.r";
+ private static final String INITIAL_DOCUMENT_CONTENT = "+7cyg:/F!T4KnW;0+au$t1G%(`Z|u'7'_!-k?<c\"2Y.]CwsO.r";
/** Replacement string */
- private static final String[] REPLACEMENTS= { ">", "F", "M/r-*", "-", "bl", "", "}%/#", "", "k&", "f", "\\g", "c!x", "TLG-", "NPO", "Rp9u", "", "X", "W(", ")z", "oe", "", "h*", "t", "I", "X=N>",
- "2yt", "&Z", "2)W=", ":K", "P9S", "s8t8o", "", "", "5{7", "%", "", "v3", "Wz", "sH", "3c", "8", "ol", ",6$", "94[#", ".~", "n", ">", "9", "W", ",(FW", "Q", "^", "Bq", "$", "re", "", "9",
- "8[", "Mx", "4b", "$6", "F", "8s]", "o", "-", "E&6", "S\\", "/", "z.a", "4ai", "b", ")", "", "l", "VU", "7M+Ql", "xZ?x", "xx", "lc", "b", "A", "!", "4pSU", "", "{J", "H", "l>_", "n&9",
- "", "&`", ";igQxq", "", ">", ";\"", "k\\`]G", "o{?", "", "K", "_6", "=" };
+ private static final String[] REPLACEMENTS = { ">", "F", "M/r-*", "-", "bl", "", "}%/#", "", "k&", "f", "\\g",
+ "c!x", "TLG-", "NPO", "Rp9u", "", "X", "W(", ")z", "oe", "", "h*", "t", "I", "X=N>", "2yt", "&Z", "2)W=",
+ ":K", "P9S", "s8t8o", "", "", "5{7", "%", "", "v3", "Wz", "sH", "3c", "8", "ol", ",6$", "94[#", ".~", "n",
+ ">", "9", "W", ",(FW", "Q", "^", "Bq", "$", "re", "", "9", "8[", "Mx", "4b", "$6", "F", "8s]", "o", "-",
+ "E&6", "S\\", "/", "z.a", "4ai", "b", ")", "", "l", "VU", "7M+Ql", "xZ?x", "xx", "lc", "b", "A", "!",
+ "4pSU", "", "{J", "H", "l>_", "n&9", "", "&`", ";igQxq", "", ">", ";\"", "k\\`]G", "o{?", "", "K", "_6",
+ "=" };
/** Position/offset pairs */
- private static final int[] POSITIONS= { 18, 2, 43, 1, 3, 2, 28, 3, 35, 1, 23, 5, 32, 2, 30, 1, 22, 1, 37, 0, 23, 3, 43, 2, 46, 1, 17, 1, 36, 6, 17, 5, 30, 4, 25, 1, 2, 2, 30, 0, 37, 3, 28, 1, 30,
- 2, 20, 5, 33, 1, 29, 1, 15, 2, 21, 2, 24, 4, 38, 3, 8, 0, 33, 2, 15, 2, 25, 0, 8, 2, 20, 3, 43, 2, 44, 1, 44, 2, 32, 2, 40, 2, 32, 3, 12, 2, 38, 3, 33, 2, 46, 0, 13, 3, 45, 0, 16, 2, 3,
- 2, 44, 0, 48, 0, 18, 5, 7, 6, 7, 3, 40, 0, 9, 1, 16, 3, 28, 3, 36, 1, 35, 2, 0, 3, 6, 1, 10, 4, 14, 2, 15, 3, 33, 1, 36, 0, 37, 0, 4, 3, 31, 3, 33, 3, 11, 3, 20, 2, 25, 3, 4, 3, 7, 3, 17,
- 0, 3, 1, 31, 3, 34, 1, 21, 0, 33, 1, 17, 4, 9, 1, 26, 3, 2, 3, 12, 1, 26, 3, 9, 5, 5, 0, 31, 3, 0, 3, 12, 1, 1, 1, 3, 0, 39, 0, 9, 2, 2, 0, 28, 2 };
-
- private static final boolean DEBUG= false;
+ private static final int[] POSITIONS = { 18, 2, 43, 1, 3, 2, 28, 3, 35, 1, 23, 5, 32, 2, 30, 1, 22, 1, 37, 0, 23, 3,
+ 43, 2, 46, 1, 17, 1, 36, 6, 17, 5, 30, 4, 25, 1, 2, 2, 30, 0, 37, 3, 28, 1, 30, 2, 20, 5, 33, 1, 29, 1, 15,
+ 2, 21, 2, 24, 4, 38, 3, 8, 0, 33, 2, 15, 2, 25, 0, 8, 2, 20, 3, 43, 2, 44, 1, 44, 2, 32, 2, 40, 2, 32, 3,
+ 12, 2, 38, 3, 33, 2, 46, 0, 13, 3, 45, 0, 16, 2, 3, 2, 44, 0, 48, 0, 18, 5, 7, 6, 7, 3, 40, 0, 9, 1, 16, 3,
+ 28, 3, 36, 1, 35, 2, 0, 3, 6, 1, 10, 4, 14, 2, 15, 3, 33, 1, 36, 0, 37, 0, 4, 3, 31, 3, 33, 3, 11, 3, 20, 2,
+ 25, 3, 4, 3, 7, 3, 17, 0, 3, 1, 31, 3, 34, 1, 21, 0, 33, 1, 17, 4, 9, 1, 26, 3, 2, 3, 12, 1, 26, 3, 9, 5, 5,
+ 0, 31, 3, 0, 3, 12, 1, 1, 1, 3, 0, 39, 0, 9, 2, 2, 0, 28, 2 };
/** The undo manager. */
private IDocumentUndoManager fUndoManager;
- @Override
- protected void setUp() {
- fUndoManager= null;
+ @Before
+ public void setUp() {
+ fUndoManager = null;
}
-
- @Override
- protected void tearDown() {
+ @After
+ public void tearDown() {
fUndoManager.disconnect(this);
- fUndoManager= null;
+ fUndoManager = null;
}
/**
* Test for line delimiter conversion.
*
- * @throws ExecutionException if undo fails
+ * @throws ExecutionException if undo fails
+ * @throws BadLocationException if document change fails
*/
- public void testConvertLineDelimiters() throws ExecutionException {
- final String original= "a\r\nb\r\n";
- final IDocument document= new Document(original);
+ @Test
+ public void testConvertLineDelimiters() throws ExecutionException, BadLocationException {
+ final String original = "a\r\nb\r\n";
+ final IDocument document = new Document(original);
createUndoManager(document);
- try {
- document.replace(1, 2, "\n");
- document.replace(3, 2, "\n");
- } catch (BadLocationException e) {
- assertTrue(false);
- }
+ document.replace(1, 2, "\n");
+ document.replace(3, 2, "\n");
assertTrue(fUndoManager.undoable());
fUndoManager.undo();
assertTrue(fUndoManager.undoable());
fUndoManager.undo();
- final String reverted= document.get();
+ final String reverted = document.get();
assertEquals(original, reverted);
}
-
private void createUndoManager(final IDocument document) {
- fUndoManager= new DocumentUndoManager(document);
+ fUndoManager = new DocumentUndoManager(document);
fUndoManager.connect(this);
fUndoManager.setMaximalUndoLevel(MAX_UNDO_LEVEL);
}
@@ -111,129 +116,101 @@ public class DocumentUndoManagerTest extends TestCase {
/**
* Randomly applies document changes.
*
- * @throws ExecutionException if undo fails
+ * @throws ExecutionException if undo fails
+ * @throws BadLocationException if document change fails
*/
- public void testRandomAccess() throws ExecutionException {
- final int RANDOM_STRING_LENGTH= 50;
- final int RANDOM_REPLACE_COUNT= 100;
+ @Test
+ public void testRandomAccess() throws ExecutionException, BadLocationException {
+ final int RANDOM_STRING_LENGTH = 50;
+ final int RANDOM_REPLACE_COUNT = 100;
assertTrue(RANDOM_REPLACE_COUNT >= 1);
assertTrue(RANDOM_REPLACE_COUNT <= MAX_UNDO_LEVEL);
- String original= createRandomString(RANDOM_STRING_LENGTH);
- final IDocument document= new Document(original);
+ String original = createRandomString(RANDOM_STRING_LENGTH);
+ final IDocument document = new Document(original);
createUndoManager(document);
-
doChange(document, RANDOM_REPLACE_COUNT);
assertTrue(fUndoManager.undoable());
while (fUndoManager.undoable())
fUndoManager.undo();
- final String reverted= document.get();
+ final String reverted = document.get();
assertEquals(original, reverted);
}
- private void doChange(IDocument document, int count) {
- try {
-
- if (DEBUG)
- System.out.println(document.get());
-
- Position[] positions= new Position[count];
- String[] strings= new String[count];
- for (int i= 0; i < count; i++) {
- final Position position= createRandomPositionPoisson(document.getLength());
- final String string= createRandomStringPoisson();
- document.replace(position.getOffset(), position.getLength(), string);
- positions[i]= position;
- strings[i]= string;
- }
+ private void doChange(IDocument document, int count) throws BadLocationException {
- if (DEBUG) {
- System.out.print("{ ");
- for (int i= 0; i < count; i++) {
- System.out.print(positions[i].getOffset());
- System.out.print(", ");
- System.out.print(positions[i].getLength());
- System.out.print(", ");
- }
- System.out.println(" }");
- System.out.print("{ ");
- for (int i= 0; i < count; i++) {
- System.out.print("\"");
- System.out.print(strings[i]);
- System.out.print("\", ");
- }
- System.out.println(" }");
- }
- } catch (BadLocationException e) {
- assertTrue(false);
+ Position[] positions = new Position[count];
+ String[] strings = new String[count];
+ for (int i = 0; i < count; i++) {
+ final Position position = createRandomPositionPoisson(document.getLength());
+ final String string = createRandomStringPoisson();
+ document.replace(position.getOffset(), position.getLength(), string);
+ positions[i] = position;
+ strings[i] = string;
}
}
// repeatable test case for comparing success/failure among different tests
- private void doRepeatableChange(IDocument document) {
+ private void doRepeatableChange(IDocument document) throws BadLocationException {
assertTrue(POSITIONS.length >= (2 * REPLACEMENTS.length));
- try {
- for (int i= 0; i < REPLACEMENTS.length; i++) {
- int offset= POSITIONS[i * 2];
- int length= POSITIONS[i * 2 + 1];
- if (document.getLength() > offset + length)
- document.replace(offset, length, REPLACEMENTS[i]);
- else
- document.replace(0, 0, REPLACEMENTS[i]);
- }
- } catch (BadLocationException e) {
- assertTrue(false);
+ for (int i = 0; i < REPLACEMENTS.length; i++) {
+ int offset = POSITIONS[i * 2];
+ int length = POSITIONS[i * 2 + 1];
+ if (document.getLength() > offset + length)
+ document.replace(offset, length, REPLACEMENTS[i]);
+ else
+ document.replace(0, 0, REPLACEMENTS[i]);
}
}
+ @Test
public void testCompoundTextEdit() throws ExecutionException, BadLocationException {
- final int RANDOM_STRING_LENGTH= 50;
- final int RANDOM_REPLACE_COUNT= 100;
+ final int RANDOM_STRING_LENGTH = 50;
+ final int RANDOM_REPLACE_COUNT = 100;
assertTrue(RANDOM_REPLACE_COUNT >= 1);
assertTrue(RANDOM_REPLACE_COUNT <= MAX_UNDO_LEVEL);
- String original= createRandomString(RANDOM_STRING_LENGTH);
- final IDocument document= new Document(original);
+ String original = createRandomString(RANDOM_STRING_LENGTH);
+ final IDocument document = new Document(original);
createUndoManager(document);
// fUndoManager.beginCompoundChange();
- MultiTextEdit fRoot= new MultiTextEdit();
- TextEdit e1= new DeleteEdit(3, 1);
+ MultiTextEdit fRoot = new MultiTextEdit();
+ TextEdit e1 = new DeleteEdit(3, 1);
fRoot.addChild(e1);
fRoot.apply(document);
- fRoot= new MultiTextEdit();
- TextEdit e2= new DeleteEdit(3, 1);
+ fRoot = new MultiTextEdit();
+ TextEdit e2 = new DeleteEdit(3, 1);
fRoot.addChild(e2);
fRoot.apply(document);
-// fUndoManager.endCompoundChange();
assertTrue(fUndoManager.undoable());
-// while (fUndoManager.undoable())
- fUndoManager.undo();
- assertTrue(!fUndoManager.undoable());
+ fUndoManager.undo();
+ assertFalse(fUndoManager.undoable());
- final String reverted= document.get();
+ final String reverted = document.get();
assertEquals(original, reverted);
}
- public void testRandomAccessAsCompound() throws ExecutionException {
- final int RANDOM_STRING_LENGTH= 50;
- final int RANDOM_REPLACE_COUNT= 100;
+ @Test
+ public void testRandomAccessAsCompound() throws ExecutionException, BadLocationException {
+ final int RANDOM_STRING_LENGTH = 50;
+ final int RANDOM_REPLACE_COUNT = 100;
assertTrue(RANDOM_REPLACE_COUNT >= 1);
assertTrue(RANDOM_REPLACE_COUNT <= MAX_UNDO_LEVEL);
- String original= createRandomString(RANDOM_STRING_LENGTH);
- final IDocument document= new Document(original);
+ String original = createRandomString(RANDOM_STRING_LENGTH);
+ final IDocument document = new Document(original);
createUndoManager(document);
fUndoManager.beginCompoundChange();
@@ -243,9 +220,9 @@ public class DocumentUndoManagerTest extends TestCase {
assertTrue(fUndoManager.undoable());
while (fUndoManager.undoable())
fUndoManager.undo();
- assertTrue(!fUndoManager.undoable());
+ assertFalse(fUndoManager.undoable());
- final String reverted= document.get();
+ final String reverted = document.get();
assertEquals(original, reverted);
}
@@ -253,21 +230,22 @@ public class DocumentUndoManagerTest extends TestCase {
/**
* Test case for https://bugs.eclipse.org/bugs/show_bug.cgi?id=88172
*
- * @throws ExecutionException if undo fails
+ * @throws ExecutionException if undo fails
+ * @throws BadLocationException if document change fails
*/
- public void testRandomAccessAsUnclosedCompound() throws ExecutionException {
+ @Test
+ public void testRandomAccessAsUnclosedCompound() throws ExecutionException, BadLocationException {
- final int RANDOM_STRING_LENGTH= 50;
- final int RANDOM_REPLACE_COUNT= 100;
+ final int RANDOM_STRING_LENGTH = 50;
+ final int RANDOM_REPLACE_COUNT = 100;
assertTrue(RANDOM_REPLACE_COUNT >= 1);
assertTrue(RANDOM_REPLACE_COUNT <= MAX_UNDO_LEVEL);
- String original= createRandomString(RANDOM_STRING_LENGTH);
- final IDocument document= new Document(original);
+ String original = createRandomString(RANDOM_STRING_LENGTH);
+ final IDocument document = new Document(original);
createUndoManager(document);
-
fUndoManager.beginCompoundChange();
doChange(document, RANDOM_REPLACE_COUNT);
// do not close the compound.
@@ -276,34 +254,34 @@ public class DocumentUndoManagerTest extends TestCase {
assertTrue(fUndoManager.undoable());
while (fUndoManager.undoable())
fUndoManager.undo();
- assertTrue(!fUndoManager.undoable());
+ assertFalse(fUndoManager.undoable());
- final String reverted= document.get();
+ final String reverted = document.get();
assertEquals(original, reverted);
}
- public void testRandomAccessWithMixedCompound() throws ExecutionException {
+ @Test
+ public void testRandomAccessWithMixedCompound() throws ExecutionException, BadLocationException {
- final int RANDOM_STRING_LENGTH= 50;
- final int RANDOM_REPLACE_COUNT= 10;
- final int NUMBER_COMPOUNDS= 5;
- final int NUMBER_ATOMIC_PER_COMPOUND= 3;
+ final int RANDOM_STRING_LENGTH = 50;
+ final int RANDOM_REPLACE_COUNT = 10;
+ final int NUMBER_COMPOUNDS = 5;
+ final int NUMBER_ATOMIC_PER_COMPOUND = 3;
assertTrue(RANDOM_REPLACE_COUNT >= 1);
assertTrue(NUMBER_COMPOUNDS * (1 + NUMBER_ATOMIC_PER_COMPOUND) * RANDOM_REPLACE_COUNT <= MAX_UNDO_LEVEL);
- String original= createRandomString(RANDOM_STRING_LENGTH);
- final IDocument document= new Document(original);
+ String original = createRandomString(RANDOM_STRING_LENGTH);
+ final IDocument document = new Document(original);
createUndoManager(document);
-
- for (int i= 0; i < NUMBER_COMPOUNDS; i++) {
+ for (int i = 0; i < NUMBER_COMPOUNDS; i++) {
fUndoManager.beginCompoundChange();
doChange(document, RANDOM_REPLACE_COUNT);
fUndoManager.endCompoundChange();
assertTrue(fUndoManager.undoable());
- for (int j= 0; j < NUMBER_ATOMIC_PER_COMPOUND; j++) {
+ for (int j = 0; j < NUMBER_ATOMIC_PER_COMPOUND; j++) {
doChange(document, RANDOM_REPLACE_COUNT);
assertTrue(fUndoManager.undoable());
}
@@ -312,17 +290,18 @@ public class DocumentUndoManagerTest extends TestCase {
assertTrue(fUndoManager.undoable());
while (fUndoManager.undoable())
fUndoManager.undo();
- assertTrue(!fUndoManager.undoable());
+ assertFalse(fUndoManager.undoable());
- final String reverted= document.get();
+ final String reverted = document.get();
assertEquals(original, reverted);
}
- public void testRepeatableAccess() throws ExecutionException {
+ @Test
+ public void testRepeatableAccess() throws ExecutionException, BadLocationException {
assertTrue(REPLACEMENTS.length <= MAX_UNDO_LEVEL);
- final IDocument document= new Document(INITIAL_DOCUMENT_CONTENT);
+ final IDocument document = new Document(INITIAL_DOCUMENT_CONTENT);
createUndoManager(document);
doRepeatableChange(document);
@@ -331,15 +310,16 @@ public class DocumentUndoManagerTest extends TestCase {
while (fUndoManager.undoable())
fUndoManager.undo();
- final String reverted= document.get();
+ final String reverted = document.get();
assertEquals(INITIAL_DOCUMENT_CONTENT, reverted);
}
- public void testRepeatableAccessAsCompound() throws ExecutionException {
+ @Test
+ public void testRepeatableAccessAsCompound() throws ExecutionException, BadLocationException {
assertTrue(REPLACEMENTS.length <= MAX_UNDO_LEVEL);
- final IDocument document= new Document(INITIAL_DOCUMENT_CONTENT);
+ final IDocument document = new Document(INITIAL_DOCUMENT_CONTENT);
createUndoManager(document);
fUndoManager.beginCompoundChange();
@@ -351,18 +331,18 @@ public class DocumentUndoManagerTest extends TestCase {
// with a single compound, there should be only one undo
assertFalse(fUndoManager.undoable());
- final String reverted= document.get();
+ final String reverted = document.get();
assertEquals(INITIAL_DOCUMENT_CONTENT, reverted);
}
- public void testRepeatableAccessAsUnclosedCompound() throws ExecutionException {
+ @Test
+ public void testRepeatableAccessAsUnclosedCompound() throws ExecutionException, BadLocationException {
assertTrue(REPLACEMENTS.length <= MAX_UNDO_LEVEL);
- final IDocument document= new Document(INITIAL_DOCUMENT_CONTENT);
+ final IDocument document = new Document(INITIAL_DOCUMENT_CONTENT);
createUndoManager(document);
-
fUndoManager.beginCompoundChange();
doRepeatableChange(document);
@@ -370,17 +350,18 @@ public class DocumentUndoManagerTest extends TestCase {
while (fUndoManager.undoable())
fUndoManager.undo();
- final String reverted= document.get();
+ final String reverted = document.get();
assertEquals(INITIAL_DOCUMENT_CONTENT, reverted);
}
- public void testDocumentStamp() throws ExecutionException {
- final Document document= new Document(INITIAL_DOCUMENT_CONTENT);
- fUndoManager= new DocumentUndoManager(document);
+ @Test
+ public void testDocumentStamp() throws ExecutionException, BadLocationException {
+ final Document document = new Document(INITIAL_DOCUMENT_CONTENT);
+ fUndoManager = new DocumentUndoManager(document);
fUndoManager.connect(this);
- long stamp= document.getModificationStamp();
+ long stamp = document.getModificationStamp();
doChange(document, 1);
fUndoManager.undo();
assertEquals(stamp, document.getModificationStamp());
@@ -388,24 +369,25 @@ public class DocumentUndoManagerTest extends TestCase {
}
// See https://bugs.eclipse.org/bugs/show_bug.cgi?id=109104
+ @Test
public void testDocumentStamp2() throws BadLocationException, ExecutionException {
- final Document document= new Document("");
- fUndoManager= new DocumentUndoManager(document);
+ final Document document = new Document("");
+ fUndoManager = new DocumentUndoManager(document);
fUndoManager.connect(this);
- final int stringLength= 13;
+ final int stringLength = 13;
document.replace(0, 0, createRandomString(stringLength));
- long stamp= document.getModificationStamp();
+ long stamp = document.getModificationStamp();
fUndoManager.undo();
document.replace(0, 0, createRandomString(stringLength));
- assertFalse(stamp == document.getModificationStamp());
+ assertNotEquals(stamp, document.getModificationStamp());
}
private static String createRandomString(int length) {
- final StringBuilder buffer= new StringBuilder();
+ final StringBuilder buffer = new StringBuilder();
- for (int i= 0; i < length; i++)
+ for (int i = 0; i < length; i++)
buffer.append(getRandomCharacter());
return buffer.toString();
@@ -413,38 +395,38 @@ public class DocumentUndoManagerTest extends TestCase {
private static final char getRandomCharacter() {
// XXX should include \t
- return (char)(32 + 95 * Math.random());
+ return (char) (32 + 95 * Math.random());
}
private static String createRandomStringPoisson() {
- final int length= getRandomPoissonValue(2);
+ final int length = getRandomPoissonValue(2);
return createRandomString(length);
}
private static Position createRandomPositionPoisson(int documentLength) {
- float random= (float)Math.random();
- int offset= (int)(random * (documentLength + 1));
+ float random = (float) Math.random();
+ int offset = (int) (random * (documentLength + 1));
// Catch potential rounding issue
if (offset == documentLength + 1)
- offset= documentLength;
+ offset = documentLength;
- int length= getRandomPoissonValue(2);
+ int length = getRandomPoissonValue(2);
if (offset + length > documentLength)
- length= documentLength - offset;
+ length = documentLength - offset;
return new Position(offset, length);
}
private static int getRandomPoissonValue(int mean) {
- final int MAX_VALUE= 10;
+ final int MAX_VALUE = 10;
- final float random= (float)Math.random();
- float probability= 0;
- int i= 0;
+ final float random = (float) Math.random();
+ float probability = 0;
+ int i = 0;
while (probability < 1 && i < MAX_VALUE) {
- probability+= getPoissonDistribution(mean, i);
+ probability += getPoissonDistribution(mean, i);
if (random <= probability)
break;
i++;
@@ -453,7 +435,7 @@ public class DocumentUndoManagerTest extends TestCase {
}
private static float getPoissonDistribution(float lambda, int k) {
- return (float)(Math.exp(-lambda) * Math.pow(lambda, k) / faculty(k));
+ return (float) (Math.exp(-lambda) * Math.pow(lambda, k) / faculty(k));
}
/**
@@ -463,10 +445,7 @@ public class DocumentUndoManagerTest extends TestCase {
* @return the faculty
*/
private static final int faculty(int k) {
- return k == 0
- ? 1
- : k * faculty(k - 1);
+ return k == 0 ? 1 : k * faculty(k - 1);
}
}
-

Back to the top