Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Vogel2018-06-29 06:21:05 -0400
committerLars Vogel2018-07-02 06:45:51 -0400
commitbf9ca91ae4d8e096566a9058fb724ec22a87f27a (patch)
treebe64a9fe95a686dc5d0f8c194b451b154d136fb3
parent5bf1ff45f9e26d792bf179bef4c729021c89a713 (diff)
downloadeclipse.platform.team-bf9ca91ae4d8e096566a9058fb724ec22a87f27a.tar.gz
eclipse.platform.team-bf9ca91ae4d8e096566a9058fb724ec22a87f27a.tar.xz
eclipse.platform.team-bf9ca91ae4d8e096566a9058fb724ec22a87f27a.zip
Migrates compare test suite to JUnit4
Also updates ContentMergeViewerTest.java, LineReaderTest and TextMergeViewer to Junit4. The rest is currently left with JUnit3 due to time constraints. Change-Id: I4569525a7a500ef23251bd304d84a85ee3247f91 Signed-off-by: Lars Vogel <Lars.Vogel@vogella.com>
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/AllTests.java54
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/ContentMergeViewerTest.java88
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/LineReaderTest.java11
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/TextMergeViewerTest.java57
4 files changed, 105 insertions, 105 deletions
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/AllTests.java b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/AllTests.java
index 83f2c44cc..e4bab73d1 100644
--- a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/AllTests.java
+++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/AllTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2013 IBM Corporation and others.
+ * Copyright (c) 2000, 2018 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,35 +10,33 @@
*******************************************************************************/
package org.eclipse.compare.tests;
-import junit.framework.Test;
-import junit.framework.TestSuite;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
/**
- * Test some non-UI areas of the compare plugin.
+ * Test some non-UI areas of the compare plug-in.
*/
-public class AllTests {
- public static Test suite() {
- TestSuite suite = new TestSuite("Test for org.eclipse.compare.tests"); //$NON-NLS-1$
- // $JUnit-BEGIN$
- suite.addTestSuite(TextMergeViewerTest.class);
- suite.addTestSuite(LineReaderTest.class);
- suite.addTestSuite(StreamMergerTest.class);
- suite.addTestSuite(DocLineComparatorTest.class);
- suite.addTestSuite(FilterTest.class);
- suite.addTestSuite(PatchTest.class);
- suite.addTestSuite(PatchBuilderTest.class);
- suite.addTestSuite(AsyncExecTests.class);
- suite.addTestSuite(DiffTest.class);
- suite.addTestSuite(FileDiffResultTest.class);
- suite.addTestSuite(ContentMergeViewerTest.class);
- suite.addTestSuite(PatchLinesTest.class);
- suite.addTestSuite(PatchUITest.class);
- suite.addTestSuite(RangeDifferencerThreeWayDiffTest.class);
- suite.addTestSuite(CompareUIPluginTest.class);
- suite.addTestSuite(StructureCreatorTest.class);
- suite.addTestSuite(CompareFileRevisionEditorInputTest.class);
- // $JUnit-END$
- return suite;
- }
+@RunWith(Suite.class)
+@SuiteClasses({
+ TextMergeViewerTest.class,
+ LineReaderTest.class,
+ StreamMergerTest.class,
+ DocLineComparatorTest.class,
+ FilterTest.class,
+ PatchTest.class,
+ PatchBuilderTest.class,
+ AsyncExecTests.class,
+ DiffTest.class,
+ FileDiffResultTest.class,
+ ContentMergeViewerTest.class,
+ PatchLinesTest.class,
+ PatchUITest.class,
+ RangeDifferencerThreeWayDiffTest.class,
+ CompareUIPluginTest.class,
+ StructureCreatorTest.class,
+ CompareFileRevisionEditorInputTest.class})
+public class AllTests {
+ // test suite
}
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/ContentMergeViewerTest.java b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/ContentMergeViewerTest.java
index 48924ac93..12be7d1b0 100644
--- a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/ContentMergeViewerTest.java
+++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/ContentMergeViewerTest.java
@@ -10,27 +10,21 @@
*******************************************************************************/
package org.eclipse.compare.tests;
+import static org.junit.Assert.assertEquals;
+
import org.eclipse.compare.CompareConfiguration;
import org.eclipse.compare.contentmergeviewer.ContentMergeViewer;
import org.eclipse.swt.widgets.Composite;
-import org.junit.Assert;
-
-import junit.framework.TestCase;
+import org.junit.Before;
+import org.junit.Test;
-public class ContentMergeViewerTest extends TestCase {
+public class ContentMergeViewerTest {
private MyContentMergeViewer myContentMergeViewer;
/**
* result[0]-event occurred or not; result[1]-new state that was set
*/
boolean[] result = new boolean[] { false, false };
- public ContentMergeViewerTest() {
- super();
- }
-
- public ContentMergeViewerTest(String name) {
- super(name);
- }
private class MyContentMergeViewer extends ContentMergeViewer {
@@ -93,8 +87,8 @@ public class ContentMergeViewerTest extends TestCase {
}
}
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() {
result = new boolean[] { false, false };
myContentMergeViewer = new MyContentMergeViewer();
myContentMergeViewer.addPropertyChangeListener(event -> {
@@ -104,146 +98,158 @@ public class ContentMergeViewerTest extends TestCase {
}
// set left to true
-
+ @Test
public void testFFTX() {
myContentMergeViewer.leftDirty = false;
myContentMergeViewer.rightDirty = false;
myContentMergeViewer.setLeftDirty(true);
- Assert.assertEquals(true, result[0]);
- Assert.assertEquals(true, result[1]);
+ assertEquals(true, result[0]);
+ assertEquals(true, result[1]);
}
+ @Test
public void testFTTX() {
myContentMergeViewer.leftDirty = false;
myContentMergeViewer.rightDirty = true;
myContentMergeViewer.setLeftDirty(true);
- Assert.assertEquals(true, result[0]);
- Assert.assertEquals(true, result[1]);
+ assertEquals(true, result[0]);
+ assertEquals(true, result[1]);
}
+ @Test
public void testTFTX() {
myContentMergeViewer.leftDirty = true;
myContentMergeViewer.rightDirty = false;
myContentMergeViewer.setLeftDirty(true);
- Assert.assertEquals(false, result[0]);
+ assertEquals(false, result[0]);
}
+ @Test
public void testTTTX() {
myContentMergeViewer.leftDirty = true;
myContentMergeViewer.rightDirty = true;
myContentMergeViewer.setLeftDirty(true);
- Assert.assertEquals(false, result[0]);
+ assertEquals(false, result[0]);
}
// set left to false
-
+ @Test
public void testFFFX() {
myContentMergeViewer.leftDirty = false;
myContentMergeViewer.rightDirty = false;
myContentMergeViewer.setLeftDirty(false);
- Assert.assertEquals(false, result[0]);
+ assertEquals(false, result[0]);
}
+ @Test
public void testFTFX() {
myContentMergeViewer.leftDirty = false;
myContentMergeViewer.rightDirty = true;
myContentMergeViewer.setLeftDirty(false);
- Assert.assertEquals(false, result[0]);
+ assertEquals(false, result[0]);
}
+ @Test
public void testTFFX() {
myContentMergeViewer.leftDirty = true;
myContentMergeViewer.rightDirty = false;
myContentMergeViewer.setLeftDirty(false);
- Assert.assertEquals(true, result[0]);
- Assert.assertEquals(false, result[1]);
+ assertEquals(true, result[0]);
+ assertEquals(false, result[1]);
}
+ @Test
public void testTTFX() {
myContentMergeViewer.leftDirty = true;
myContentMergeViewer.rightDirty = true;
myContentMergeViewer.setLeftDirty(false);
- Assert.assertEquals(true, result[0]);
- Assert.assertEquals(false, result[1]);
+ assertEquals(true, result[0]);
+ assertEquals(false, result[1]);
}
// set right to true
-
+ @Test
public void testFFXT() {
myContentMergeViewer.leftDirty = false;
myContentMergeViewer.rightDirty = false;
myContentMergeViewer.setRightDirty(true);
- Assert.assertEquals(true, result[0]);
- Assert.assertEquals(true, result[1]);
+ assertEquals(true, result[0]);
+ assertEquals(true, result[1]);
}
+ @Test
public void testFTXT() {
myContentMergeViewer.leftDirty = false;
myContentMergeViewer.rightDirty = true;
myContentMergeViewer.setRightDirty(true);
- Assert.assertEquals(false, result[0]);
+ assertEquals(false, result[0]);
}
+ @Test
public void testTFXT() {
myContentMergeViewer.leftDirty = true;
myContentMergeViewer.rightDirty = false;
myContentMergeViewer.setRightDirty(true);
- Assert.assertEquals(true, result[0]);
- Assert.assertEquals(true, result[1]);
+ assertEquals(true, result[0]);
+ assertEquals(true, result[1]);
}
+ @Test
public void testTTXT() {
myContentMergeViewer.leftDirty = true;
myContentMergeViewer.rightDirty = true;
myContentMergeViewer.setRightDirty(true);
- Assert.assertEquals(false, result[0]);
+ assertEquals(false, result[0]);
}
// set right to false
-
+ @Test
public void testFFXF() {
myContentMergeViewer.leftDirty = false;
myContentMergeViewer.rightDirty = false;
myContentMergeViewer.setRightDirty(false);
- Assert.assertEquals(false, result[0]);
+ assertEquals(false, result[0]);
}
+ @Test
public void testFTXF() {
myContentMergeViewer.leftDirty = false;
myContentMergeViewer.rightDirty = true;
myContentMergeViewer.setRightDirty(false);
- Assert.assertEquals(true, result[0]);
- Assert.assertEquals(false, result[1]);
+ assertEquals(true, result[0]);
+ assertEquals(false, result[1]);
}
+ @Test
public void testTFXF() {
myContentMergeViewer.leftDirty = true;
myContentMergeViewer.rightDirty = false;
myContentMergeViewer.setRightDirty(false);
- Assert.assertEquals(false, result[0]);
+ assertEquals(false, result[0]);
}
+ @Test
public void testTTXF() {
myContentMergeViewer.leftDirty = true;
myContentMergeViewer.rightDirty = true;
myContentMergeViewer.setRightDirty(false);
- Assert.assertEquals(true, result[0]);
- Assert.assertEquals(false, result[1]);
+ assertEquals(true, result[0]);
+ assertEquals(false, result[1]);
}
}
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/LineReaderTest.java b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/LineReaderTest.java
index e46fad3f8..ac4665f33 100644
--- a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/LineReaderTest.java
+++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/LineReaderTest.java
@@ -10,6 +10,9 @@
*******************************************************************************/
package org.eclipse.compare.tests;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
import java.io.*;
import java.net.URL;
import java.util.List;
@@ -17,17 +20,18 @@ import java.util.List;
import org.eclipse.compare.internal.core.patch.LineReader;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
+import org.junit.Test;
-import junit.framework.TestCase;
-
-public class LineReaderTest extends TestCase {
+public class LineReaderTest {
+ @Test
public void testReadEmpty() {
LineReader lr= new LineReader(getReader("empty.txt")); //$NON-NLS-1$
List<String> inLines= lr.readLines();
assertEquals(0, inLines.size());
}
+ @Test
public void testReadNormal() {
LineReader lr= new LineReader(getReader("normal.txt")); //$NON-NLS-1$
List<String> inLines= lr.readLines();
@@ -44,6 +48,7 @@ public class LineReaderTest extends TestCase {
return line;
}
+ @Test
public void testReadUnterminatedLastLine() {
LineReader lr= new LineReader(getReader("unterminated.txt")); //$NON-NLS-1$
List<String> inLines= lr.readLines();
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/TextMergeViewerTest.java b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/TextMergeViewerTest.java
index b62ff25cf..4ef07618e 100644
--- a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/TextMergeViewerTest.java
+++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/TextMergeViewerTest.java
@@ -10,43 +10,30 @@
*******************************************************************************/
package org.eclipse.compare.tests;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.*;
import java.util.HashMap;
import java.util.Map;
-import junit.framework.TestCase;
-
-import org.eclipse.compare.CompareConfiguration;
-import org.eclipse.compare.ICompareFilter;
-import org.eclipse.compare.IEditableContent;
-import org.eclipse.compare.IStreamContentAccessor;
-import org.eclipse.compare.ITypedElement;
+import org.eclipse.compare.*;
import org.eclipse.compare.contentmergeviewer.TextMergeViewer;
-import org.eclipse.compare.internal.ChangeCompareFilterPropertyAction;
-import org.eclipse.compare.internal.IMergeViewerTestAdapter;
-import org.eclipse.compare.internal.MergeViewerContentProvider;
-import org.eclipse.compare.internal.Utilities;
+import org.eclipse.compare.internal.*;
import org.eclipse.compare.structuremergeviewer.DiffNode;
import org.eclipse.compare.structuremergeviewer.Differencer;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.text.Document;
-import org.eclipse.jface.text.DocumentEvent;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IDocumentPartitioner;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITypedRegion;
-import org.eclipse.jface.text.Region;
+import org.eclipse.jface.text.*;
import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.*;
import org.eclipse.ui.PlatformUI;
+import org.junit.Test;
-public class TextMergeViewerTest extends TestCase {
+public class TextMergeViewerTest {
/**
* Returns a boolean value indicating whether or not the contents
@@ -200,13 +187,6 @@ public class TextMergeViewerTest extends TestCase {
TestMergeViewer viewer;
- public TextMergeViewerTest() {
- super();
- }
-
- public TextMergeViewerTest(String name) {
- super(name);
- }
private void runInDialog(Object input, Runnable runnable) throws Exception {
runInDialog(input, runnable, new CompareConfiguration());
@@ -247,6 +227,7 @@ public class TextMergeViewerTest extends TestCase {
return document;
}
+ @Test
public void testCopyRightToLeft() throws Exception {
DiffNode parentNode = new DiffNode(new ParentTestElement(), new ParentTestElement());
String copiedText = "hi there";
@@ -258,6 +239,7 @@ public class TextMergeViewerTest extends TestCase {
assertEquals(copiedText, ((EditableTestElement)testNode.getLeft()).getContentsAsString());
}
+ @Test
public void testCopyLeftToRight() throws Exception {
DiffNode parentNode = new DiffNode(new ParentTestElement(), new ParentTestElement());
String copiedText = "hi there";
@@ -269,6 +251,7 @@ public class TextMergeViewerTest extends TestCase {
assertEquals(copiedText, ((EditableTestElement)testNode.getRight()).getContentsAsString());
}
+ @Test
public void testCopyRightToEmptyLeft() throws Exception {
DiffNode parentNode = new DiffNode(new ParentTestElement(), new ParentTestElement());
DiffNode testNode = new DiffNode(parentNode, Differencer.ADDITION, null, null, new EditableTestElement("hi there".getBytes()));
@@ -279,6 +262,7 @@ public class TextMergeViewerTest extends TestCase {
assertEquals(testNode.getRight(), testNode.getLeft());
}
+ @Test
public void testCopyLeftToEmptyRight() throws Exception {
DiffNode parentNode = new DiffNode(new ParentTestElement(), new ParentTestElement());
DiffNode testNode = new DiffNode(parentNode, Differencer.DELETION, null, new EditableTestElement("hi there".getBytes()), null);
@@ -289,6 +273,7 @@ public class TextMergeViewerTest extends TestCase {
assertEquals(testNode.getRight(), testNode.getLeft());
}
+ @Test
public void testCopyEmptyLeftToRight() throws Exception {
DiffNode parentNode = new DiffNode(new ParentTestElement(), new ParentTestElement());
DiffNode testNode = new DiffNode(parentNode, Differencer.ADDITION, null, null, new EditableTestElement("hi there".getBytes()));
@@ -300,6 +285,7 @@ public class TextMergeViewerTest extends TestCase {
assertNull(testNode.getRight());
}
+ @Test
public void testCopyEmptyRightToLeft() throws Exception {
DiffNode parentNode = new DiffNode(new ParentTestElement(), new ParentTestElement());
DiffNode testNode = new DiffNode(parentNode, Differencer.DELETION, null, new EditableTestElement("hi there".getBytes()), null);
@@ -311,6 +297,7 @@ public class TextMergeViewerTest extends TestCase {
assertNull(testNode.getRight());
}
+ @Test
public void testModifyLeft() throws Exception {
DiffNode testNode = new DiffNode(new EditableTestElement("hi there".getBytes()), null);
final String newText = "New text";
@@ -322,6 +309,7 @@ public class TextMergeViewerTest extends TestCase {
assertEquals(newText, ((EditableTestElement)testNode.getLeft()).getContentsAsString());
}
+ @Test
public void testModifyRight() throws Exception {
DiffNode testNode = new DiffNode(null, new EditableTestElement("hi there".getBytes()));
final String newText = "New text";
@@ -333,6 +321,7 @@ public class TextMergeViewerTest extends TestCase {
assertEquals(newText, ((EditableTestElement)testNode.getRight()).getContentsAsString());
}
+ @Test
public void testCopyEmptyRightToLeftAndModify() throws Exception {
DiffNode parentNode = new DiffNode(new ParentTestElement(), new ParentTestElement());
DiffNode testNode = new DiffNode(parentNode, Differencer.ADDITION, null, null, new EditableTestElement("hi there".getBytes()));
@@ -346,6 +335,7 @@ public class TextMergeViewerTest extends TestCase {
assertEquals(newText, ((EditableTestElement)testNode.getLeft()).getContentsAsString());
}
+ @Test
public void testCopyEmptyLeftToRightAndModify() throws Exception {
DiffNode parentNode = new DiffNode(new ParentTestElement(), new ParentTestElement());
DiffNode testNode = new DiffNode(parentNode, Differencer.DELETION, null, new EditableTestElement("hi there".getBytes()), null);
@@ -359,6 +349,7 @@ public class TextMergeViewerTest extends TestCase {
assertEquals(newText, ((EditableTestElement)testNode.getRight()).getContentsAsString());
}
+ @Test
public void testCompareFilter() throws Exception {
DiffNode parentNode = new DiffNode(new ParentTestElement(),
new ParentTestElement());
@@ -438,7 +429,7 @@ public class TextMergeViewerTest extends TestCase {
}, cc);
}
-
+ @Test
public void testDocumentAsTypedElement() throws Exception {
class DocumentAsTypedElement extends Document implements ITypedElement {

Back to the top