Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kurtakov2020-02-12 12:42:28 +0000
committerAlexander Kurtakov2020-02-12 14:26:55 +0000
commit932c6095358ec0eca5bd16d591c1174ae7f2df36 (patch)
tree89fdc664aab295fb0d9efb1c3a3ea6ef5a4da724
parent673682248b2d7b18ecf828d7caf2e9db03321888 (diff)
downloadeclipse.platform.team-932c6095358ec0eca5bd16d591c1174ae7f2df36.tar.gz
eclipse.platform.team-932c6095358ec0eca5bd16d591c1174ae7f2df36.tar.xz
eclipse.platform.team-932c6095358ec0eca5bd16d591c1174ae7f2df36.zip
Convert o.e.core.tests.net and o.e.compare.tests to JUnit4
Had to drop apitooling as it caused errors but API on test bundles is pure insanity. Change-Id: Iffa4a8617a388d094fc9147ea1e17688738361fe Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/AsyncExecTests.java25
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/CompareFileRevisionEditorInputTest.java7
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/CompareUIPluginTest.java35
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/DiffTest.java111
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/DocLineComparatorTest.java227
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/FilterTest.java28
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchBuilderTest.java78
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchLinesTest.java25
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchTest.java213
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchUITest.java29
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/RangeDifferencerThreeWayDiffTest.java64
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/StreamMergerTest.java125
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/StructureCreatorTest.java26
-rw-r--r--tests/org.eclipse.core.tests.net/.cvsignore1
-rw-r--r--tests/org.eclipse.core.tests.net/.project6
-rw-r--r--tests/org.eclipse.core.tests.net/META-INF/MANIFEST.MF2
-rw-r--r--tests/org.eclipse.core.tests.net/pom.xml2
-rw-r--r--tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/AllNetTests.java4
-rw-r--r--tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/SystemProxyTest.java100
19 files changed, 537 insertions, 571 deletions
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/AsyncExecTests.java b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/AsyncExecTests.java
index 79d1c6944..9028f8369 100644
--- a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/AsyncExecTests.java
+++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/AsyncExecTests.java
@@ -13,29 +13,22 @@
*******************************************************************************/
package org.eclipse.compare.tests;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
import java.util.ArrayList;
import java.util.List;
import org.eclipse.compare.internal.WorkQueue;
import org.eclipse.compare.internal.Worker;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.*;
import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.junit.Test;
-import junit.framework.TestCase;
-
-
-public class AsyncExecTests extends TestCase {
-
- public AsyncExecTests() {
- super();
- }
-
- public AsyncExecTests(String name) {
- super(name);
- }
+public class AsyncExecTests {
+ @Test
public void testQueueAdd() {
WorkQueue q = new WorkQueue();
assertTrue(q.isEmpty());
@@ -78,6 +71,7 @@ public class AsyncExecTests extends TestCase {
assertTrue(q.isEmpty());
}
+ @Test
public void testWorker() {
final Worker w = new Worker("");
final List<IRunnableWithProgress> worked = new ArrayList<>();
@@ -140,6 +134,7 @@ public class AsyncExecTests extends TestCase {
assertEquals(r2, worked.get(0));
}
+ @Test
public void testCancelOnRequeue() {
final Worker w = new Worker("");
final List<IRunnableWithProgress> worked = new ArrayList<>();
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/CompareFileRevisionEditorInputTest.java b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/CompareFileRevisionEditorInputTest.java
index 4efd43153..44347c748 100644
--- a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/CompareFileRevisionEditorInputTest.java
+++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/CompareFileRevisionEditorInputTest.java
@@ -21,11 +21,10 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.swt.graphics.Image;
import org.eclipse.team.internal.ui.history.CompareFileRevisionEditorInput;
import org.eclipse.ui.IWorkbenchPage;
+import org.junit.Test;
-import junit.framework.TestCase;
-
-public class CompareFileRevisionEditorInputTest extends TestCase {
-
+public class CompareFileRevisionEditorInputTest {
+ @Test
public void testPrepareCompareInputWithNonLocalResourceTypedElements()
throws InvocationTargetException, InterruptedException {
TestFriendlyCompareFileRevisionEditorInput input = new TestFriendlyCompareFileRevisionEditorInput(
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/CompareUIPluginTest.java b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/CompareUIPluginTest.java
index 708a00cb3..f531b7e14 100644
--- a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/CompareUIPluginTest.java
+++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/CompareUIPluginTest.java
@@ -13,21 +13,22 @@
*******************************************************************************/
package org.eclipse.compare.tests;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
import java.io.ByteArrayInputStream;
import java.io.InputStream;
-import junit.framework.TestCase;
-
-import org.eclipse.compare.CompareConfiguration;
-import org.eclipse.compare.IStreamContentAccessor;
-import org.eclipse.compare.ITypedElement;
+import org.eclipse.compare.*;
import org.eclipse.compare.internal.CompareUIPlugin;
import org.eclipse.compare.internal.ViewerDescriptor;
import org.eclipse.compare.structuremergeviewer.DiffNode;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.swt.graphics.Image;
+import org.junit.Test;
-public class CompareUIPluginTest extends TestCase {
+public class CompareUIPluginTest {
private static class UnknownTypedElement implements ITypedElement {
@Override
@@ -82,43 +83,49 @@ public class CompareUIPluginTest extends TestCase {
@Override
public InputStream getContents() throws CoreException {
/*
- * Whatever we return has no importance as long as it is not "null", this is only to make
- * CompareUIPlugin#guessType happy. However, it is only happy if what we return resembles a text.
+ * Whatever we return has no importance as long as it is not "null", this is
+ * only to make CompareUIPlugin#guessType happy. However, it is only happy if
+ * what we return resembles a text.
*/
- return new ByteArrayInputStream(new byte[] {' '});
+ return new ByteArrayInputStream(new byte[] { ' ' });
}
}
+ @Test
public void testFindContentViewerDescriptor_UnknownType() {
CompareConfiguration cc = new CompareConfiguration();
DiffNode in = new DiffNode(new UnknownTypedElement(), new UnknownTypedElement());
ViewerDescriptor[] result = CompareUIPlugin.getDefault().findContentViewerDescriptor(null, in, cc);
- // API Compatibility : "no descriptor found" should return a null array instead of a 0-lengthed one.
+ // API Compatibility : "no descriptor found" should return a null array instead
+ // of a 0-lengthed one.
assertNull(result);
}
+ @Test
public void testFindContentViewerDescriptor_TextType_NotStreamAccessor() {
CompareConfiguration cc = new CompareConfiguration();
DiffNode in = new DiffNode(new TextTypedElement(), new TextTypedElement());
ViewerDescriptor[] result = CompareUIPlugin.getDefault().findContentViewerDescriptor(null, in, cc);
/*
- * "TextTypedElement" is "text" typed : it thus has a Content Viewer attached. However, this content
- * viewer is currently NOT returned because of bug 293926
+ * "TextTypedElement" is "text" typed : it thus has a Content Viewer attached.
+ * However, this content viewer is currently NOT returned because of bug 293926
*/
assertNotNull(result);
assertEquals(1, result.length);
}
+ @Test
public void testFindContentViewerDescriptorForTextType_StreamAccessor() {
CompareConfiguration cc = new CompareConfiguration();
DiffNode in = new DiffNode(new TextTypedElementStreamAccessor(), new TextTypedElementStreamAccessor());
ViewerDescriptor[] result = CompareUIPlugin.getDefault().findContentViewerDescriptor(null, in, cc);
/*
- * "TextTypedElement" is "text" typed : it thus has a Content Viewer attached. However, the content
- * viewer will only be returned because we made our "ITypedElement" be an IStreamContentAccessor.
+ * "TextTypedElement" is "text" typed : it thus has a Content Viewer attached.
+ * However, the content viewer will only be returned because we made our
+ * "ITypedElement" be an IStreamContentAccessor.
*/
assertNotNull(result);
assertEquals(1, result.length);
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/DiffTest.java b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/DiffTest.java
index 1882bbfb6..43babda70 100644
--- a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/DiffTest.java
+++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/DiffTest.java
@@ -13,45 +13,33 @@
*******************************************************************************/
package org.eclipse.compare.tests;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertTrue;
import org.eclipse.compare.internal.DocLineComparator;
import org.eclipse.compare.internal.core.TextLineLCS;
-import org.eclipse.compare.rangedifferencer.IRangeComparator;
-import org.eclipse.compare.rangedifferencer.RangeDifference;
-import org.eclipse.compare.rangedifferencer.RangeDifferencer;
+import org.eclipse.compare.rangedifferencer.*;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
+import org.junit.Test;
-public class DiffTest extends TestCase {
+public class DiffTest {
- private static final String ABC= "abc"; //$NON-NLS-1$
- private static final String DEF= "def"; //$NON-NLS-1$
- //private static final String BAR= "bar"; //$NON-NLS-1$
- //private static final String FOO= "foo"; //$NON-NLS-1$
- private static final String XYZ= "xyz"; //$NON-NLS-1$
- private static final String _123= "123"; //$NON-NLS-1$
- //private static final String _456= "456"; //$NON-NLS-1$
+ private static final String ABC = "abc"; //$NON-NLS-1$
+ private static final String DEF = "def"; //$NON-NLS-1$
+ // private static final String BAR= "bar"; //$NON-NLS-1$
+ // private static final String FOO= "foo"; //$NON-NLS-1$
+ private static final String XYZ = "xyz"; //$NON-NLS-1$
+ private static final String _123 = "123"; //$NON-NLS-1$
+ // private static final String _456= "456"; //$NON-NLS-1$
- static final String SEPARATOR= System.getProperty("line.separator"); //$NON-NLS-1$
-
- public DiffTest() {
- super();
- }
-
- public DiffTest(String name) {
- super(name);
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
+ static final String SEPARATOR = System.getProperty("line.separator"); //$NON-NLS-1$
+ @Test
public void testLineAddition() {
- String s1= ABC + SEPARATOR + DEF + SEPARATOR + XYZ;
- String s2= ABC + SEPARATOR + DEF + SEPARATOR + _123 + SEPARATOR + XYZ;
+ String s1 = ABC + SEPARATOR + DEF + SEPARATOR + XYZ;
+ String s2 = ABC + SEPARATOR + DEF + SEPARATOR + _123 + SEPARATOR + XYZ;
TextLineLCS.TextLine[] l1 = TextLineLCS.getTextLines(s1);
TextLineLCS.TextLine[] l2 = TextLineLCS.getTextLines(s2);
TextLineLCS lcs = new TextLineLCS(l1, l2);
@@ -70,9 +58,10 @@ public class DiffTest extends TestCase {
assertTrue(result[1][2].lineNumber() == 3);
}
+ @Test
public void testLineDeletion() {
- String s1= ABC + SEPARATOR + DEF + SEPARATOR + _123 + SEPARATOR + XYZ;
- String s2= ABC + SEPARATOR + DEF + SEPARATOR + XYZ;
+ String s1 = ABC + SEPARATOR + DEF + SEPARATOR + _123 + SEPARATOR + XYZ;
+ String s2 = ABC + SEPARATOR + DEF + SEPARATOR + XYZ;
TextLineLCS.TextLine[] l1 = TextLineLCS.getTextLines(s1);
TextLineLCS.TextLine[] l2 = TextLineLCS.getTextLines(s2);
TextLineLCS lcs = new TextLineLCS(l1, l2);
@@ -90,9 +79,10 @@ public class DiffTest extends TestCase {
assertTrue(result[1][2].lineNumber() == 2);
}
+ @Test
public void testLineAppendEnd() {
- String s1= ABC + SEPARATOR + DEF;
- String s2= ABC + SEPARATOR + DEF + SEPARATOR + _123;
+ String s1 = ABC + SEPARATOR + DEF;
+ String s2 = ABC + SEPARATOR + DEF + SEPARATOR + _123;
TextLineLCS.TextLine[] l1 = TextLineLCS.getTextLines(s1);
TextLineLCS.TextLine[] l2 = TextLineLCS.getTextLines(s2);
TextLineLCS lcs = new TextLineLCS(l1, l2);
@@ -109,9 +99,10 @@ public class DiffTest extends TestCase {
assertTrue(result[1][1].lineNumber() == 1);
}
+ @Test
public void testLineDeleteEnd() {
- String s1= ABC + SEPARATOR + DEF + SEPARATOR + _123;
- String s2= ABC + SEPARATOR + DEF;
+ String s1 = ABC + SEPARATOR + DEF + SEPARATOR + _123;
+ String s2 = ABC + SEPARATOR + DEF;
TextLineLCS.TextLine[] l1 = TextLineLCS.getTextLines(s1);
TextLineLCS.TextLine[] l2 = TextLineLCS.getTextLines(s2);
TextLineLCS lcs = new TextLineLCS(l1, l2);
@@ -128,9 +119,10 @@ public class DiffTest extends TestCase {
assertTrue(result[1][1].lineNumber() == 1);
}
+ @Test
public void testLineAppendStart() {
- String s1= ABC + SEPARATOR + DEF;
- String s2= _123 + SEPARATOR + ABC + SEPARATOR + DEF;
+ String s1 = ABC + SEPARATOR + DEF;
+ String s2 = _123 + SEPARATOR + ABC + SEPARATOR + DEF;
TextLineLCS.TextLine[] l1 = TextLineLCS.getTextLines(s1);
TextLineLCS.TextLine[] l2 = TextLineLCS.getTextLines(s2);
TextLineLCS lcs = new TextLineLCS(l1, l2);
@@ -147,9 +139,10 @@ public class DiffTest extends TestCase {
assertTrue(result[1][1].lineNumber() == 2);
}
+ @Test
public void testLineDeleteStart() {
- String s1= _123 + SEPARATOR + ABC + SEPARATOR + DEF;
- String s2= ABC + SEPARATOR + DEF;
+ String s1 = _123 + SEPARATOR + ABC + SEPARATOR + DEF;
+ String s2 = ABC + SEPARATOR + DEF;
TextLineLCS.TextLine[] l1 = TextLineLCS.getTextLines(s1);
TextLineLCS.TextLine[] l2 = TextLineLCS.getTextLines(s2);
TextLineLCS lcs = new TextLineLCS(l1, l2);
@@ -167,27 +160,24 @@ public class DiffTest extends TestCase {
}
private IRangeComparator toRangeComparator(String s) {
- IDocument doc1= new Document();
+ IDocument doc1 = new Document();
doc1.set(s);
return new DocLineComparator(doc1, null, true);
}
private RangeDifference[] getDifferences(String s1, String s2) {
- IRangeComparator comp1= toRangeComparator(s1);
- IRangeComparator comp2= toRangeComparator(s2);
+ IRangeComparator comp1 = toRangeComparator(s1);
+ IRangeComparator comp2 = toRangeComparator(s2);
RangeDifference[] differences = RangeDifferencer.findDifferences(comp1, comp2);
RangeDifference[] oldDifferences = RangeDifferencer.findDifferences(comp1, comp2);
- assertTrue(differences.length == oldDifferences.length);
- for (int i = 0; i < oldDifferences.length; i++) {
- assertEquals(oldDifferences[i], differences[i]);
-
- }
+ assertArrayEquals(differences, oldDifferences);
return differences;
}
+ @Test
public void testDocAddition() {
- String s1= ABC + SEPARATOR + DEF + SEPARATOR + XYZ;
- String s2= ABC + SEPARATOR + DEF + SEPARATOR + _123 + SEPARATOR + XYZ;
+ String s1 = ABC + SEPARATOR + DEF + SEPARATOR + XYZ;
+ String s2 = ABC + SEPARATOR + DEF + SEPARATOR + _123 + SEPARATOR + XYZ;
RangeDifference[] result = getDifferences(s1, s2);
@@ -198,9 +188,10 @@ public class DiffTest extends TestCase {
assertTrue(result[0].rightLength() == 1);
}
+ @Test
public void testDocDeletion() {
- String s1= ABC + SEPARATOR + DEF + SEPARATOR + _123 + SEPARATOR + XYZ;
- String s2= ABC + SEPARATOR + DEF + SEPARATOR + XYZ;
+ String s1 = ABC + SEPARATOR + DEF + SEPARATOR + _123 + SEPARATOR + XYZ;
+ String s2 = ABC + SEPARATOR + DEF + SEPARATOR + XYZ;
RangeDifference[] result = getDifferences(s1, s2);
@@ -211,9 +202,10 @@ public class DiffTest extends TestCase {
assertTrue(result[0].rightLength() == 0);
}
+ @Test
public void testDocAppendStart() {
- String s1= ABC + SEPARATOR + DEF;
- String s2= _123 + SEPARATOR + ABC + SEPARATOR + DEF;
+ String s1 = ABC + SEPARATOR + DEF;
+ String s2 = _123 + SEPARATOR + ABC + SEPARATOR + DEF;
RangeDifference[] result = getDifferences(s1, s2);
@@ -224,9 +216,10 @@ public class DiffTest extends TestCase {
assertTrue(result[0].rightLength() == 1);
}
+ @Test
public void testDocDeleteStart() {
- String s1= _123 + SEPARATOR + ABC + SEPARATOR + DEF;
- String s2= ABC + SEPARATOR + DEF;
+ String s1 = _123 + SEPARATOR + ABC + SEPARATOR + DEF;
+ String s2 = ABC + SEPARATOR + DEF;
RangeDifference[] result = getDifferences(s1, s2);
@@ -237,9 +230,10 @@ public class DiffTest extends TestCase {
assertTrue(result[0].rightLength() == 0);
}
+ @Test
public void testDocAppendEnd() {
- String s1= ABC + SEPARATOR + DEF;
- String s2= ABC + SEPARATOR + DEF + SEPARATOR + _123;
+ String s1 = ABC + SEPARATOR + DEF;
+ String s2 = ABC + SEPARATOR + DEF + SEPARATOR + _123;
RangeDifference[] result = getDifferences(s1, s2);
@@ -250,9 +244,10 @@ public class DiffTest extends TestCase {
assertTrue(result[0].rightLength() == 1);
}
+ @Test
public void testDocDeleteEnd() {
- String s1= ABC + SEPARATOR + DEF + SEPARATOR + _123;
- String s2= ABC + SEPARATOR + DEF;
+ String s1 = ABC + SEPARATOR + DEF + SEPARATOR + _123;
+ String s2 = ABC + SEPARATOR + DEF;
RangeDifference[] result = getDifferences(s1, s2);
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/DocLineComparatorTest.java b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/DocLineComparatorTest.java
index 4b5046739..842743b33 100644
--- a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/DocLineComparatorTest.java
+++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/DocLineComparatorTest.java
@@ -15,59 +15,44 @@ package org.eclipse.compare.tests;
import java.util.HashMap;
-import junit.framework.TestCase;
-
import org.eclipse.compare.ICompareFilter;
import org.eclipse.compare.internal.DocLineComparator;
import org.eclipse.compare.rangedifferencer.IRangeComparator;
-import org.eclipse.jface.text.Document;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.Region;
+import org.eclipse.jface.text.*;
import org.junit.Assert;
+import org.junit.Test;
-public class DocLineComparatorTest extends TestCase {
-
- public DocLineComparatorTest(String name) {
- super(name);
- }
-
- @Override
- protected void setUp() throws Exception {
- // empty
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
+public class DocLineComparatorTest {
+ @Test
public void testRangesEqual() {
- IDocument doc1= new Document();
+ IDocument doc1 = new Document();
doc1.set("if (s.strip))"); //$NON-NLS-1$
- IDocument doc2= new Document();
+ IDocument doc2 = new Document();
doc2.set("if (s.strip)"); //$NON-NLS-1$
- IRangeComparator comp1= new DocLineComparator(doc1, null, true);
- IRangeComparator comp2= new DocLineComparator(doc2, null, true);
+ IRangeComparator comp1 = new DocLineComparator(doc1, null, true);
+ IRangeComparator comp2 = new DocLineComparator(doc2, null, true);
Assert.assertFalse(comp1.rangesEqual(0, comp2, 0));
}
+ @Test
public void testWhitespaceAtEnd() {
- IDocument doc1= new Document();
+ IDocument doc1 = new Document();
doc1.set("if (s.strip))"); //$NON-NLS-1$
- IDocument doc2= new Document();
+ IDocument doc2 = new Document();
doc2.set("if (s.strip)) "); //$NON-NLS-1$
- IRangeComparator comp1= new DocLineComparator(doc1, null, true);
- IRangeComparator comp2= new DocLineComparator(doc2, null, true);
+ IRangeComparator comp1 = new DocLineComparator(doc1, null, true);
+ IRangeComparator comp2 = new DocLineComparator(doc2, null, true);
Assert.assertTrue(comp1.rangesEqual(0, comp2, 0));
}
+ @Test
public void testOneCompareFilter() {
IDocument doc1 = new Document();
doc1.set("if (s.strip))"); //$NON-NLS-1$
@@ -81,15 +66,13 @@ public class DocLineComparatorTest extends TestCase {
ICompareFilter filter = new ICompareFilter() {
@Override
- public void setInput(Object input, Object ancestor, Object left,
- Object right) {
+ public void setInput(Object input, Object ancestor, Object left, Object right) {
// EMPTY
}
@Override
public IRegion[] getFilteredRegions(HashMap lineComparison) {
- return new IRegion[] { new Region(0, 2), new Region(4, 1),
- new Region(8, 2) };
+ return new IRegion[] { new Region(0, 2), new Region(4, 1), new Region(8, 2) };
}
@Override
@@ -103,25 +86,20 @@ public class DocLineComparatorTest extends TestCase {
}
};
- IRangeComparator comp1 = new DocLineComparator(doc1, null, false,
- new ICompareFilter[] { filter }, 'L');
- IRangeComparator comp2 = new DocLineComparator(doc2, null, false,
- new ICompareFilter[] { filter }, 'R');
+ IRangeComparator comp1 = new DocLineComparator(doc1, null, false, new ICompareFilter[] { filter }, 'L');
+ IRangeComparator comp2 = new DocLineComparator(doc2, null, false, new ICompareFilter[] { filter }, 'R');
Assert.assertTrue(comp1.rangesEqual(0, comp2, 0));
- IRangeComparator comp3 = new DocLineComparator(doc1, null, true,
- new ICompareFilter[] { filter }, 'L');
- IRangeComparator comp4 = new DocLineComparator(doc3, null, true,
- new ICompareFilter[] { filter }, 'R');
+ IRangeComparator comp3 = new DocLineComparator(doc1, null, true, new ICompareFilter[] { filter }, 'L');
+ IRangeComparator comp4 = new DocLineComparator(doc3, null, true, new ICompareFilter[] { filter }, 'R');
Assert.assertTrue(comp3.rangesEqual(0, comp4, 0));
- IRangeComparator comp5 = new DocLineComparator(doc1, null, false,
- new ICompareFilter[] { filter }, 'L');
- IRangeComparator comp6 = new DocLineComparator(doc3, null, false,
- new ICompareFilter[] { filter }, 'R');
+ IRangeComparator comp5 = new DocLineComparator(doc1, null, false, new ICompareFilter[] { filter }, 'L');
+ IRangeComparator comp6 = new DocLineComparator(doc3, null, false, new ICompareFilter[] { filter }, 'R');
Assert.assertFalse(comp5.rangesEqual(0, comp6, 0));
}
+ @Test
public void testMultipleCompareFilters() {
IDocument doc1 = new Document();
doc1.set("if (s.strip))"); //$NON-NLS-1$
@@ -132,8 +110,7 @@ public class DocLineComparatorTest extends TestCase {
ICompareFilter filter1 = new ICompareFilter() {
@Override
- public void setInput(Object input, Object ancestor, Object left,
- Object right) {
+ public void setInput(Object input, Object ancestor, Object left, Object right) {
// EMPTY
}
@@ -156,8 +133,7 @@ public class DocLineComparatorTest extends TestCase {
ICompareFilter filter2 = new ICompareFilter() {
@Override
- public void setInput(Object input, Object ancestor, Object left,
- Object right) {
+ public void setInput(Object input, Object ancestor, Object left, Object right) {
// EMPTY
}
@@ -180,8 +156,7 @@ public class DocLineComparatorTest extends TestCase {
ICompareFilter filter3 = new ICompareFilter() {
@Override
- public void setInput(Object input, Object ancestor, Object left,
- Object right) {
+ public void setInput(Object input, Object ancestor, Object left, Object right) {
// EMPTY
}
@@ -207,13 +182,14 @@ public class DocLineComparatorTest extends TestCase {
new ICompareFilter[] { filter1, filter2, filter3 }, 'R');
Assert.assertTrue(comp1.rangesEqual(0, comp2, 0));
- IRangeComparator comp3 = new DocLineComparator(doc1, null, false,
- new ICompareFilter[] { filter2, filter3 }, 'L');
- IRangeComparator comp4 = new DocLineComparator(doc2, null, false,
- new ICompareFilter[] { filter2, filter3 }, 'R');
+ IRangeComparator comp3 = new DocLineComparator(doc1, null, false, new ICompareFilter[] { filter2, filter3 },
+ 'L');
+ IRangeComparator comp4 = new DocLineComparator(doc2, null, false, new ICompareFilter[] { filter2, filter3 },
+ 'R');
Assert.assertFalse(comp3.rangesEqual(0, comp4, 0));
}
+ @Test
public void testWhitespace() {
IDocument[] docs = new IDocument[6];
docs[0] = new Document();
@@ -224,69 +200,63 @@ public class DocLineComparatorTest extends TestCase {
docs[5] = new Document();
docs[0].set("if (s.strip))\r\n");//$NON-NLS-1$
- docs[1].set("if (s.strip))\n"); //$NON-NLS-1$
+ docs[1].set("if (s.strip))\n"); //$NON-NLS-1$
docs[2].set("if (s .strip))\n"); //$NON-NLS-1$
docs[3].set("if (s.str ip))\r"); //$NON-NLS-1$
- docs[4].set("if (s.strip))"); //$NON-NLS-1$
- docs[5].set("if (s.stri p))"); //$NON-NLS-1$
+ docs[4].set("if (s.strip))"); //$NON-NLS-1$
+ docs[5].set("if (s.stri p))"); //$NON-NLS-1$
ICompareFilter[][] filters = new ICompareFilter[3][];
filters[0] = null;
- filters[1] = new ICompareFilter[]{
- new ICompareFilter() {
-
- @Override
- public void setInput(Object input, Object ancestor, Object left,
- Object right) {
- // EMPTY
- }
-
- @Override
- public IRegion[] getFilteredRegions(HashMap lineComparison) {
- return new IRegion[] { new Region(0, 2) };
- }
-
- @Override
- public boolean isEnabledInitially() {
- return false;
- }
-
- @Override
- public boolean canCacheFilteredRegions() {
- return true; // cache-able
- }
- }
- };
+ filters[1] = new ICompareFilter[] { new ICompareFilter() {
- filters[2] = new ICompareFilter[]{
- new ICompareFilter() {
-
- @Override
- public void setInput(Object input, Object ancestor, Object left,
- Object right) {
- // EMPTY
- }
-
- @Override
- public IRegion[] getFilteredRegions(HashMap lineComparison) {
- return new IRegion[] { new Region(0, 2) };
- }
-
- @Override
- public boolean isEnabledInitially() {
- return false;
- }
-
- @Override
- public boolean canCacheFilteredRegions() {
- return false; // not cache-able
- }
- }
- };
+ @Override
+ public void setInput(Object input, Object ancestor, Object left, Object right) {
+ // EMPTY
+ }
+
+ @Override
+ public IRegion[] getFilteredRegions(HashMap lineComparison) {
+ return new IRegion[] { new Region(0, 2) };
+ }
+
+ @Override
+ public boolean isEnabledInitially() {
+ return false;
+ }
+
+ @Override
+ public boolean canCacheFilteredRegions() {
+ return true; // cache-able
+ }
+ } };
+
+ filters[2] = new ICompareFilter[] { new ICompareFilter() {
+
+ @Override
+ public void setInput(Object input, Object ancestor, Object left, Object right) {
+ // EMPTY
+ }
+
+ @Override
+ public IRegion[] getFilteredRegions(HashMap lineComparison) {
+ return new IRegion[] { new Region(0, 2) };
+ }
+
+ @Override
+ public boolean isEnabledInitially() {
+ return false;
+ }
+
+ @Override
+ public boolean canCacheFilteredRegions() {
+ return false; // not cache-able
+ }
+ } };
IRangeComparator l, r;
- for (int i=0;i<docs.length;i++)
- for (int j=i+1;j<docs.length;j++)
+ for (int i = 0; i < docs.length; i++)
+ for (int j = i + 1; j < docs.length; j++)
for (ICompareFilter[] filter : filters) {
l = new DocLineComparator(docs[i], null, false, filter, 'L');
r = new DocLineComparator(docs[j], null, false, filter, 'R');
@@ -294,67 +264,72 @@ public class DocLineComparatorTest extends TestCase {
l = new DocLineComparator(docs[i], null, true, filter, 'L');
r = new DocLineComparator(docs[j], null, true, filter, 'R');
Assert.assertTrue(l.rangesEqual(0, r, 0));
- }
+ }
}
+ @Test
public void testEmpty() {
- IDocument doc1= new Document();
+ IDocument doc1 = new Document();
doc1.set(""); //$NON-NLS-1$
- IDocument doc2= new Document();
+ IDocument doc2 = new Document();
doc2.set(" "); //$NON-NLS-1$
- IRangeComparator comp1= new DocLineComparator(doc1, null, true);
- IRangeComparator comp2= new DocLineComparator(doc2, null, true);
+ IRangeComparator comp1 = new DocLineComparator(doc1, null, true);
+ IRangeComparator comp2 = new DocLineComparator(doc2, null, true);
Assert.assertTrue(comp1.rangesEqual(0, comp2, 0));
}
+ @Test
public void testNoContent() {
- IDocument doc= new Document();
+ IDocument doc = new Document();
- IRangeComparator comp1= new DocLineComparator(doc, null, true);
- IRangeComparator comp2= new DocLineComparator(doc, new Region(0, doc.getLength()), true);
+ IRangeComparator comp1 = new DocLineComparator(doc, null, true);
+ IRangeComparator comp2 = new DocLineComparator(doc, new Region(0, doc.getLength()), true);
Assert.assertTrue(comp1.rangesEqual(0, comp2, 0));
Assert.assertEquals(comp1.getRangeCount(), comp2.getRangeCount());
Assert.assertEquals(1, comp2.getRangeCount());
}
+ @Test
public void testOneLine() {
IDocument doc = new Document();
doc.set("line1"); //$NON-NLS-1$
- IRangeComparator comp1= new DocLineComparator(doc, null, true);
- IRangeComparator comp2= new DocLineComparator(doc, new Region(0, doc.getLength()), true);
+ IRangeComparator comp1 = new DocLineComparator(doc, null, true);
+ IRangeComparator comp2 = new DocLineComparator(doc, new Region(0, doc.getLength()), true);
Assert.assertEquals(comp1.getRangeCount(), comp2.getRangeCount());
Assert.assertEquals(1, comp2.getRangeCount());
}
+ @Test
public void testTwoLines() {
IDocument doc = new Document();
doc.set("line1\nline2"); //$NON-NLS-1$
- IRangeComparator comp1= new DocLineComparator(doc, null, true);
- IRangeComparator comp2= new DocLineComparator(doc, new Region(0, doc.getLength()), true);
+ IRangeComparator comp1 = new DocLineComparator(doc, null, true);
+ IRangeComparator comp2 = new DocLineComparator(doc, new Region(0, doc.getLength()), true);
Assert.assertEquals(comp1.getRangeCount(), comp2.getRangeCount());
Assert.assertEquals(2, comp2.getRangeCount());
- IRangeComparator comp3= new DocLineComparator(doc, new Region(0, "line1".length()), true);
+ IRangeComparator comp3 = new DocLineComparator(doc, new Region(0, "line1".length()), true);
Assert.assertEquals(1, comp3.getRangeCount());
- comp3= new DocLineComparator(doc, new Region(0, "line1".length()+1), true);
+ comp3 = new DocLineComparator(doc, new Region(0, "line1".length() + 1), true);
Assert.assertEquals(2, comp3.getRangeCount()); // two lines
}
+ @Test
public void testBug259422() {
IDocument doc = new Document();
doc.set(""); //$NON-NLS-1$
- IRangeComparator comp1= new DocLineComparator(doc, null, true);
- IRangeComparator comp2= new DocLineComparator(doc, new Region(0, doc.getLength()), true);
+ IRangeComparator comp1 = new DocLineComparator(doc, null, true);
+ IRangeComparator comp2 = new DocLineComparator(doc, new Region(0, doc.getLength()), true);
Assert.assertEquals(comp1.getRangeCount(), comp2.getRangeCount());
}
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/FilterTest.java b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/FilterTest.java
index 6867ef719..88e4b46a1 100644
--- a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/FilterTest.java
+++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/FilterTest.java
@@ -15,40 +15,39 @@ package org.eclipse.compare.tests;
import org.eclipse.compare.internal.CompareResourceFilter;
import org.junit.Assert;
+import org.junit.Test;
-import junit.framework.TestCase;
-
-public class FilterTest extends TestCase {
+public class FilterTest {
CompareResourceFilter fFilter;
- public FilterTest(String name) {
- super(name);
- }
-
+ @Test
public void testFilterFile() {
- CompareResourceFilter f= new CompareResourceFilter();
+ CompareResourceFilter f = new CompareResourceFilter();
f.setFilters("*.class"); //$NON-NLS-1$
Assert.assertTrue("file foo.class should be filtered", f.filter("foo.class", false, false)); //$NON-NLS-1$ //$NON-NLS-2$
Assert.assertFalse("file foo.java shouldn't be filtered", f.filter("foo.java", false, false)); //$NON-NLS-1$ //$NON-NLS-2$
}
+ @Test
public void testFilterDotFile() {
- CompareResourceFilter f= new CompareResourceFilter();
+ CompareResourceFilter f = new CompareResourceFilter();
f.setFilters(".cvsignore"); //$NON-NLS-1$
Assert.assertTrue("file .cvsignore should be filtered", f.filter(".cvsignore", false, false)); //$NON-NLS-1$ //$NON-NLS-2$
Assert.assertFalse("file foo.cvsignore shouldn't be filtered", f.filter("foo.cvsignore", false, false)); //$NON-NLS-1$ //$NON-NLS-2$
}
+ @Test
public void testFilterFolder() {
- CompareResourceFilter f= new CompareResourceFilter();
+ CompareResourceFilter f = new CompareResourceFilter();
f.setFilters("bin/"); //$NON-NLS-1$
Assert.assertTrue("folder bin should be filtered", f.filter("bin", true, false)); //$NON-NLS-1$ //$NON-NLS-2$
Assert.assertFalse("file bin shouldn't be filtered", f.filter("bin", false, false)); //$NON-NLS-1$ //$NON-NLS-2$
}
+ @Test
public void testMultiFilter() {
- CompareResourceFilter f= new CompareResourceFilter();
+ CompareResourceFilter f = new CompareResourceFilter();
f.setFilters("*.class, .cvsignore, bin/, src/"); //$NON-NLS-1$
Assert.assertTrue("file foo.class should be filtered", f.filter("foo.class", false, false)); //$NON-NLS-1$ //$NON-NLS-2$
Assert.assertFalse("file foo.java shouldn't be filtered", f.filter("foo.java", false, false)); //$NON-NLS-1$ //$NON-NLS-2$
@@ -60,8 +59,11 @@ public class FilterTest extends TestCase {
Assert.assertFalse("file src shouldn't be filtered", f.filter("src", false, false)); //$NON-NLS-1$ //$NON-NLS-2$
}
+ @Test
public void testVerify() {
- //Assert.assertNull("filters don't verify", Filter.validateResourceFilters("*.class, .cvsignore, bin/"));
- //Assert.assertNotNull("filters shouldn't verify", Filter.validateResourceFilters("bin//"));
+ // Assert.assertNull("filters don't verify",
+ // Filter.validateResourceFilters("*.class, .cvsignore, bin/"));
+ // Assert.assertNotNull("filters shouldn't verify",
+ // Filter.validateResourceFilters("bin//"));
}
}
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchBuilderTest.java b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchBuilderTest.java
index 49dbd83be..6f753333d 100644
--- a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchBuilderTest.java
+++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchBuilderTest.java
@@ -13,6 +13,10 @@
*******************************************************************************/
package org.eclipse.compare.tests;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
@@ -25,25 +29,10 @@ import org.eclipse.compare.tests.PatchUtils.StringStorage;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.*;
import org.junit.Assert;
+import org.junit.Test;
-import junit.framework.TestCase;
-
-public class PatchBuilderTest extends TestCase {
-
- public PatchBuilderTest() {
-
- }
-
- @Override
- protected void setUp() throws Exception {
- // Nothing to do
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
+public class PatchBuilderTest {
+ @Test
public void testModifyHunks() throws CoreException, IOException {
IStorage patchStorage = new StringStorage("patch_modifyHunks.txt");
IStorage contextStorage = new StringStorage("context.txt");
@@ -52,8 +41,7 @@ public class PatchBuilderTest extends TestCase {
IHunk[] hunksBefore = patches[0].getHunks();
assertEquals(5, hunksBefore.length);
- String[] lines = new String[] { " [d]", "+[d1]", "+[d2]", "+[d3]",
- "+[d4]", " [e]" };
+ String[] lines = new String[] { " [d]", "+[d1]", "+[d2]", "+[d3]", "+[d4]", " [e]" };
String lineDelimiter = getLineDelimiter(patchStorage);
addLineDelimiters(lines, lineDelimiter);
IHunk[] toAdd = new IHunk[] { PatchBuilder.createHunk(3, lines) };
@@ -73,8 +61,7 @@ public class PatchBuilderTest extends TestCase {
assertEquals(28, ((Hunk) hunksAfter[3]).getStart(false));
assertEquals(33, ((Hunk) hunksAfter[3]).getStart(true));
- IFilePatchResult result = filePatch.apply(Utilities
- .getReaderCreator(contextStorage), new PatchConfiguration(),
+ IFilePatchResult result = filePatch.apply(Utilities.getReaderCreator(contextStorage), new PatchConfiguration(),
new NullProgressMonitor());
IHunk[] rejects = result.getRejects();
@@ -82,14 +69,14 @@ public class PatchBuilderTest extends TestCase {
InputStream actual = result.getPatchedContents();
- LineReader lr = new LineReader(PatchUtils
- .getReader("exp_modifyHunks.txt"));
+ LineReader lr = new LineReader(PatchUtils.getReader("exp_modifyHunks.txt"));
List<String> inLines = lr.readLines();
String expected = LineReader.createString(false, inLines);
assertEquals(expected, PatchUtils.asString(actual));
}
+ @Test
public void testAddHunks() throws CoreException, IOException {
IStorage patchStorage = new StringStorage("patch_addHunks.txt");
IStorage contextStorage = new StringStorage("context_full.txt");
@@ -98,14 +85,12 @@ public class PatchBuilderTest extends TestCase {
IHunk[] hunksBefore = patches[0].getHunks();
assertEquals(3, hunksBefore.length);
- String[] lines0 = new String[] { " [d]", "+[d1]", "+[d2]", "+[d3]",
- "+[d4]", " [e]" };
+ String[] lines0 = new String[] { " [d]", "+[d1]", "+[d2]", "+[d3]", "+[d4]", " [e]" };
String lineDelimiter = getLineDelimiter(patchStorage);
addLineDelimiters(lines0, lineDelimiter);
IHunk hunk0 = PatchBuilder.createHunk(3, lines0);
- String[] lines1 = new String[] { " [K]", " [L]", "-[M]", " [N]",
- "+[N1]", "+[N2]", " [O]", " [P]" };
+ String[] lines1 = new String[] { " [K]", " [L]", "-[M]", " [N]", "+[N1]", "+[N2]", " [O]", " [P]" };
addLineDelimiters(lines1, lineDelimiter);
IHunk hunk1 = PatchBuilder.createHunk(36, lines1);
@@ -125,8 +110,7 @@ public class PatchBuilderTest extends TestCase {
assertEquals(46, ((Hunk) hunksAfter[4]).getStart(false));
assertEquals(51, ((Hunk) hunksAfter[4]).getStart(true));
- IFilePatchResult result = filePatch.apply(Utilities
- .getReaderCreator(contextStorage), new PatchConfiguration(),
+ IFilePatchResult result = filePatch.apply(Utilities.getReaderCreator(contextStorage), new PatchConfiguration(),
new NullProgressMonitor());
IHunk[] rejects = result.getRejects();
@@ -141,6 +125,7 @@ public class PatchBuilderTest extends TestCase {
assertEquals(expected, PatchUtils.asString(actual));
}
+ @Test
public void testRemoveHunks() throws CoreException, IOException {
IStorage patchStorage = new StringStorage("patch_removeHunks.txt");
IStorage contextStorage = new StringStorage("context_full.txt");
@@ -161,8 +146,7 @@ public class PatchBuilderTest extends TestCase {
assertEquals(46, ((Hunk) hunksAfter[2]).getStart(false));
assertEquals(43, ((Hunk) hunksAfter[2]).getStart(true));
- IFilePatchResult result = filePatch.apply(Utilities
- .getReaderCreator(contextStorage), new PatchConfiguration(),
+ IFilePatchResult result = filePatch.apply(Utilities.getReaderCreator(contextStorage), new PatchConfiguration(),
new NullProgressMonitor());
IHunk[] rejects = result.getRejects();
@@ -170,14 +154,14 @@ public class PatchBuilderTest extends TestCase {
InputStream actual = result.getPatchedContents();
- LineReader lr = new LineReader(PatchUtils
- .getReader("exp_removeHunks.txt"));
+ LineReader lr = new LineReader(PatchUtils.getReader("exp_removeHunks.txt"));
List<String> inLines = lr.readLines();
String expected = LineReader.createString(false, inLines);
assertEquals(expected, PatchUtils.asString(actual));
}
+ @Test
public void testCreateFilePatch() throws CoreException, IOException {
IStorage contextStorage = new StringStorage("context.txt");
@@ -186,44 +170,40 @@ public class PatchBuilderTest extends TestCase {
addLineDelimiters(lines0, lineDelimiter);
Hunk hunk0 = (Hunk) PatchBuilder.createHunk(0, lines0);
- String[] lines1 = new String[] { " [b]", " [c]", "-[d]", "-[e]",
- " [f]", " [g]", " [h]", "+[h1]", " [i]", " [j]", "+[j1]",
- "+[j2]", " [k]", " [l]" };
+ String[] lines1 = new String[] { " [b]", " [c]", "-[d]", "-[e]", " [f]", " [g]", " [h]", "+[h1]", " [i]",
+ " [j]", "+[j1]", "+[j2]", " [k]", " [l]" };
addLineDelimiters(lines1, lineDelimiter);
Hunk hunk1 = (Hunk) PatchBuilder.createHunk(1, lines1);
IHunk[] hunks = new IHunk[] { hunk1, hunk0 };
- IFilePatch2 filePatch = PatchBuilder.createFilePatch(new Path(""),
- IFilePatch2.DATE_UNKNOWN, new Path(""),
+ IFilePatch2 filePatch = PatchBuilder.createFilePatch(new Path(""), IFilePatch2.DATE_UNKNOWN, new Path(""),
IFilePatch2.DATE_UNKNOWN, hunks);
assertEquals(2, filePatch.getHunks().length);
assertEquals(hunk0, filePatch.getHunks()[0]);
assertEquals(hunk1, filePatch.getHunks()[1]);
- IFilePatchResult result = filePatch.apply(Utilities
- .getReaderCreator(contextStorage), new PatchConfiguration(),
+ IFilePatchResult result = filePatch.apply(Utilities.getReaderCreator(contextStorage), new PatchConfiguration(),
new NullProgressMonitor());
InputStream actual = result.getPatchedContents();
- LineReader lr = new LineReader(PatchUtils
- .getReader("exp_createFilePatch.txt"));
+ LineReader lr = new LineReader(PatchUtils.getReader("exp_createFilePatch.txt"));
List<String> inLines = lr.readLines();
String expected = LineReader.createString(false, inLines);
assertEquals(expected, PatchUtils.asString(actual));
}
+ @Test
public void testCreateHunk0() throws CoreException, IOException {
IStorage patch = new StringStorage("patch_createHunk0.txt");
IFilePatch[] filePatches = ApplyPatchOperation.parsePatch(patch);
assertEquals(1, filePatches.length);
assertEquals(1, filePatches[0].getHunks().length);
- String[] lines = new String[] { "+[a1]", "+[a2]", "+[a3]", " [a]",
- " [b]", "-[c]", " [d]", " [e]", " [f]" };
+ String[] lines = new String[] { "+[a1]", "+[a2]", "+[a3]", " [a]", " [b]", "-[c]", " [d]", " [e]", " [f]" };
String lineDelimiter = getLineDelimiter(patch);
addLineDelimiters(lines, lineDelimiter);
Hunk hunk = (Hunk) PatchBuilder.createHunk(0, lines);
@@ -234,15 +214,15 @@ public class PatchBuilderTest extends TestCase {
assertHunkEquals(hunk, (Hunk) filePatches[0].getHunks()[0]);
}
+ @Test
public void testCreateHunk1() throws CoreException, IOException {
IStorage patch = new StringStorage("patch_createHunk1.txt");
IFilePatch[] filePatches = ApplyPatchOperation.parsePatch(patch);
assertEquals(1, filePatches.length);
assertEquals(1, filePatches[0].getHunks().length);
- String[] lines = new String[] { " [a]", " [b]", "-[c]", " [d]", "-[e]",
- " [f]", " [g]", " [h]", "+[h1]", " [i]", " [j]", "+[j1]",
- "+[j2]", " [k]", " [l]", " [m]" };
+ String[] lines = new String[] { " [a]", " [b]", "-[c]", " [d]", "-[e]", " [f]", " [g]", " [h]", "+[h1]", " [i]",
+ " [j]", "+[j1]", "+[j2]", " [k]", " [l]", " [m]" };
String lineDelimiter = getLineDelimiter(patch);
addLineDelimiters(lines, lineDelimiter);
Hunk hunk = (Hunk) PatchBuilder.createHunk(0, lines);
@@ -253,6 +233,7 @@ public class PatchBuilderTest extends TestCase {
assertHunkEquals(hunk, (Hunk) filePatches[0].getHunks()[0]);
}
+ @Test
public void testCreateHunk2() throws CoreException, IOException {
IStorage patch = new StringStorage("patch_createHunk2.txt");
IFilePatch[] filePatches = ApplyPatchOperation.parsePatch(patch);
@@ -270,6 +251,7 @@ public class PatchBuilderTest extends TestCase {
assertHunkEquals(hunk, (Hunk) filePatches[0].getHunks()[0]);
}
+ @Test
public void testCreateHunk3() throws CoreException, IOException {
IStorage patch = new StringStorage("patch_createHunk3.txt");
IFilePatch[] filePatches = ApplyPatchOperation.parsePatch(patch);
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchLinesTest.java b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchLinesTest.java
index 2f08d7731..86809c7e7 100644
--- a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchLinesTest.java
+++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchLinesTest.java
@@ -13,66 +13,71 @@
*******************************************************************************/
package org.eclipse.compare.tests;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
import java.io.BufferedReader;
import java.io.IOException;
import java.lang.reflect.Field;
-import junit.framework.TestCase;
-
import org.eclipse.compare.internal.core.patch.FilePatch2;
import org.eclipse.compare.internal.patch.WorkspacePatcher;
import org.eclipse.compare.patch.IHunk;
+import org.junit.Test;
-public class PatchLinesTest extends TestCase {
-
- public PatchLinesTest(String name) {
- super(name);
- }
+public class PatchLinesTest {
// unified diff format
-
+ @Test
public void test_196847() throws Exception {
int[] lines = parsePatch("196847/stuff_patch.txt");
assertEquals(6, lines[0]);
assertEquals(5, lines[1]);
}
+ @Test
public void test_deletion_autofuzz() throws Exception {
int[] lines = parsePatch("deletion_autofuzz/patch.txt");
assertEquals(0, lines[0]);
assertEquals(1, lines[1]);
}
+ @Test
public void test_patch_addition() throws Exception {
int[] lines = parsePatch("patch_addition.txt");
assertEquals(9, lines[0]);
assertEquals(0, lines[1]);
}
+ @Test
public void test_patch_context1() throws Exception {
int[] lines = parsePatch("patch_context1.txt");
assertEquals(4, lines[0]);
assertEquals(2, lines[1]);
}
+ @Test
public void test_patch_context3() throws Exception {
int[] lines = parsePatch("patch_context3.txt");
assertEquals(4, lines[0]);
assertEquals(2, lines[1]);
}
+ @Test
public void test_patch_workspacePatchAddition() throws Exception {
int[] lines = parsePatch("patch_workspacePatchAddition.txt");
assertEquals(31, lines[0]);
assertEquals(0, lines[1]);
}
+ @Test
public void test_patch_workspacePatchDelete() throws Exception {
int[] lines = parsePatch("patch_workspacePatchDelete.txt");
assertEquals(29, lines[0]);
assertEquals(46, lines[1]);
}
+ @Test
public void test_patch_workspacePatchMod() throws Exception {
int[] lines = parsePatch("patch_workspacePatchMod.txt");
assertEquals(33, lines[0]);
@@ -80,19 +85,21 @@ public class PatchLinesTest extends TestCase {
}
// context diff format
-
+ @Test
public void test_patch_addition_context() throws Exception {
int[] lines = parsePatch("patch_addition_context.txt");
assertEquals(9, lines[0]);
assertEquals(0, lines[1]);
}
+ @Test
public void test_patch_oneline_context() throws Exception {
int[] lines = parsePatch("patch_oneline_context.txt");
assertEquals(1, lines[0]);
assertEquals(0, lines[1]);
}
+ @Test
public void test_patch_context3_context() throws Exception {
int[] lines = parsePatch("patch_context3_context.txt");
assertEquals(4, lines[0]);
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchTest.java b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchTest.java
index ae03b254c..a94304124 100644
--- a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchTest.java
+++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchTest.java
@@ -13,6 +13,12 @@
*******************************************************************************/
package org.eclipse.compare.tests;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.io.*;
import java.net.JarURLConnection;
import java.net.URL;
@@ -29,18 +35,17 @@ import org.eclipse.compare.tests.PatchUtils.*;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.*;
import org.junit.Assert;
+import org.junit.Test;
import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
-public class PatchTest extends TestCase {
+public class PatchTest {
private static final String PATCH_CONFIGURATION = "patchConfiguration.properties";
Properties defaultPatchProperties;
- public PatchTest(String name) {
- super(name);
+ public PatchTest() {
defaultPatchProperties = new Properties();
defaultPatchProperties.setProperty("patchFile", "patch.txt");
defaultPatchProperties.setProperty("contextFile", "context.txt");
@@ -48,36 +53,32 @@ public class PatchTest extends TestCase {
defaultPatchProperties.setProperty("fuzzFactor", "-1");
}
- @Override
- protected void setUp() throws Exception {
- // empty
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
+ @Test
public void testCreatePatch() throws CoreException, IOException {
patch("addition.txt", "patch_addition.txt", "exp_addition.txt"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
+ @Test
public void testUnterminatedCreatePatch() throws CoreException, IOException {
patch("addition.txt", "patch_addition2.txt", "exp_addition2.txt"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
+ @Test
public void testContext0Patch() throws CoreException, IOException {
patch("context.txt", "patch_context0.txt", "exp_context.txt"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
+ @Test
public void testContext1Patch() throws CoreException, IOException {
patch("context.txt", "patch_context1.txt", "exp_context.txt"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
+ @Test
public void testContext3Patch() throws CoreException, IOException {
patch("context.txt", "patch_context3.txt", "exp_context.txt"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
+ @Test
public void testHunkFilter() throws CoreException, IOException {
IStorage patchStorage = new StringStorage("patch_hunkFilter.txt");
IStorage expStorage = new StringStorage("context.txt");
@@ -88,8 +89,7 @@ public class PatchTest extends TestCase {
PatchConfiguration pc = new PatchConfiguration();
final IHunk toFilterOut = hunks[3];
pc.addHunkFilter(hunk -> hunk != toFilterOut);
- IFilePatchResult result = patches[0].apply(expStorage, pc,
- new NullProgressMonitor());
+ IFilePatchResult result = patches[0].apply(expStorage, pc, new NullProgressMonitor());
IHunk[] rejects = result.getRejects();
assertEquals(2, rejects.length);
boolean aFiltered = pc.getHunkFilters()[0].select(rejects[0]);
@@ -105,12 +105,14 @@ public class PatchTest extends TestCase {
assertEquals(expected, PatchUtils.asString(actual));
}
+ @Test
public void testContext3PatchWithHeader() throws CoreException, IOException {
patch("context.txt", "patch_context3_header.txt", "exp_context.txt"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
IStorage patchStorage = new StringStorage("patch_context3_header.txt");
IFilePatch[] patches = ApplyPatchOperation.parsePatch(patchStorage);
String header = patches[0].getHeader();
- LineReader reader = new LineReader(new BufferedReader(new InputStreamReader(new ByteArrayInputStream(header.getBytes()))));
+ LineReader reader = new LineReader(
+ new BufferedReader(new InputStreamReader(new ByteArrayInputStream(header.getBytes()))));
List<String> lines = reader.readLines();
List<String> expected = new ArrayList<>();
expected.add("Index: old.txt\n");
@@ -118,6 +120,7 @@ public class PatchTest extends TestCase {
assertEquals(LineReader.createString(false, expected), LineReader.createString(false, lines));
}
+ @Test
public void testDateUnknown() throws CoreException {
IStorage patchStorage = new StringStorage("patch_dateunknown.txt");
IFilePatch[] patches = ApplyPatchOperation.parsePatch(patchStorage);
@@ -125,6 +128,7 @@ public class PatchTest extends TestCase {
assertEquals(IFilePatch.DATE_UNKNOWN, patches[0].getAfterDate());
}
+ @Test
public void testDateError() throws CoreException {
IStorage patchStorage = new StringStorage("patch_dateerror.txt");
IFilePatch[] patches = ApplyPatchOperation.parsePatch(patchStorage);
@@ -132,6 +136,7 @@ public class PatchTest extends TestCase {
assertEquals(IFilePatch.DATE_UNKNOWN, patches[0].getAfterDate());
}
+ @Test
public void testDateKnown() throws CoreException {
IStorage patchStorage = new StringStorage("patch_datevalid.txt");
IFilePatch[] patches = ApplyPatchOperation.parsePatch(patchStorage);
@@ -139,48 +144,83 @@ public class PatchTest extends TestCase {
assertFalse(IFilePatch.DATE_UNKNOWN == patches[0].getAfterDate());
}
- //Test creation of new workspace patch
- public void testWorkspacePatch_Create(){
- //Note the order that exists in the array of expected results is based purely on the order of the files in the patch
- patchWorkspace(new String[]{"addition.txt", "addition.txt"}, "patch_workspacePatchAddition.txt", new String[] { "exp_workspacePatchAddition2.txt","exp_workspacePatchAddition.txt"}, false, 0); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ // Test creation of new workspace patch
+ @Test
+ public void testWorkspacePatch_Create() {
+ // Note the order that exists in the array of expected results is based purely
+ // on the order of the files in the patch
+ patchWorkspace(new String[] { "addition.txt", "addition.txt" }, "patch_workspacePatchAddition.txt", //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
+ new String[] { "exp_workspacePatchAddition2.txt", "exp_workspacePatchAddition.txt" }, false, 0); //$NON-NLS-1$ //$NON-NLS-2$
}
- //Test applying the reverse of workspace creation patch
- public void testWorkspacePatch_Create_Reverse(){
- //Note the order that exists in the array of expected results is based purely on the order of the files in the patch
- patchWorkspace(new String[]{"exp_workspacePatchAddition2.txt","exp_workspacePatchAddition.txt"}, "patch_workspacePatchAddition.txt", new String[] {"addition.txt", "addition.txt"}, true, 0); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ // Test applying the reverse of workspace creation patch
+ @Test
+ public void testWorkspacePatch_Create_Reverse() {
+ // Note the order that exists in the array of expected results is based purely
+ // on the order of the files in the patch
+ patchWorkspace(new String[] { "exp_workspacePatchAddition2.txt", "exp_workspacePatchAddition.txt" }, //$NON-NLS-1$//$NON-NLS-2$
+ "patch_workspacePatchAddition.txt", new String[] { "addition.txt", "addition.txt" }, true, 0); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
- //Test the patching of an already existing file, the creation of a new one and the deletion of elements in a file
- public void testWorkspacePatch_Modify(){
- //Note the order that exists in the array of expected results is based purely on the order of the files in the patch
- patchWorkspace(new String[]{"exp_workspacePatchAddition2.txt","exp_workspacePatchAddition.txt", "addition.txt"}, "patch_workspacePatchMod.txt", new String[] { "exp_workspacePatchMod1.txt","exp_workspacePatchMod2.txt", "exp_workspacePatchMod3.txt"}, false, 0 ); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
+ // Test the patching of an already existing file, the creation of a new one and
+ // the deletion of elements in a file
+ @Test
+ public void testWorkspacePatch_Modify() {
+ // Note the order that exists in the array of expected results is based purely
+ // on the order of the files in the patch
+ patchWorkspace(
+ new String[] { "exp_workspacePatchAddition2.txt", "exp_workspacePatchAddition.txt", "addition.txt" }, //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
+ "patch_workspacePatchMod.txt", new String[] { "exp_workspacePatchMod1.txt", //$NON-NLS-1$ //$NON-NLS-2$
+ "exp_workspacePatchMod2.txt", "exp_workspacePatchMod3.txt" }, //$NON-NLS-1$ //$NON-NLS-2$
+ false, 0);
}
- //Test applying the reverse of a workspace modify patch
- public void testWorkspacePatch_Modify_Reverse(){
- //Note the order that exists in the array of expected results is based purely on the order of the files in the patch
- patchWorkspace(new String[]{ "exp_workspacePatchMod1.txt","exp_workspacePatchMod2.txt", "exp_workspacePatchMod3.txt"}, "patch_workspacePatchMod.txt", new String[] {"exp_workspacePatchAddition2.txt","exp_workspacePatchAddition.txt", "addition.txt"}, true, 0 ); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
+ // Test applying the reverse of a workspace modify patch
+ @Test
+ public void testWorkspacePatch_Modify_Reverse() {
+ // Note the order that exists in the array of expected results is based purely
+ // on the order of the files in the patch
+ patchWorkspace(
+ new String[] { "exp_workspacePatchMod1.txt", "exp_workspacePatchMod2.txt", //$NON-NLS-1$//$NON-NLS-2$
+ "exp_workspacePatchMod3.txt" }, //$NON-NLS-1$
+ "patch_workspacePatchMod.txt", //$NON-NLS-1$
+ new String[] { "exp_workspacePatchAddition2.txt", "exp_workspacePatchAddition.txt", "addition.txt" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ true, 0);
}
- //Tests the deletion of an already existing file, and the modification of another file
- public void testWorkspacePatch_Delete(){
- //Note the order that exists in the array of expected results is based purely on the order of the files in the patch
- patchWorkspace(new String[]{"exp_workspacePatchMod2.txt","addition.txt", "exp_workspacePatchMod1.txt","addition.txt"}, "patch_workspacePatchDelete.txt", new String[] { "addition.txt","exp_workspacePatchDelete2.txt", "addition.txt", "exp_workspacePatchDelete1.txt"}, false, 0 ); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$
+ // Tests the deletion of an already existing file, and the modification of
+ // another file
+ @Test
+ public void testWorkspacePatch_Delete() {
+ // Note the order that exists in the array of expected results is based purely
+ // on the order of the files in the patch
+ patchWorkspace(
+ new String[] { "exp_workspacePatchMod2.txt", "addition.txt", "exp_workspacePatchMod1.txt", //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
+ "addition.txt" }, //$NON-NLS-1$
+ "patch_workspacePatchDelete.txt", new String[] { "addition.txt", "exp_workspacePatchDelete2.txt", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ "addition.txt", "exp_workspacePatchDelete1.txt" }, //$NON-NLS-1$ //$NON-NLS-2$
+ false, 0);
}
- //Test applying the reverse of a workspace deletion patch
- public void testWorkspacePatch_Delete_Reverse(){
- //Note the order that exists in the array of expected results is based purely on the order of the files in the patch
- patchWorkspace(new String[]{"addition.txt","exp_workspacePatchDelete2.txt", "addition.txt", "exp_workspacePatchDelete1.txt" }, "patch_workspacePatchDelete.txt", new String[] {"exp_workspacePatchMod2.txt","addition.txt", "exp_workspacePatchMod1.txt","addition.txt"}, true, 0 ); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$
+ // Test applying the reverse of a workspace deletion patch
+ @Test
+ public void testWorkspacePatch_Delete_Reverse() {
+ // Note the order that exists in the array of expected results is based purely
+ // on the order of the files in the patch
+ patchWorkspace(
+ new String[] { "addition.txt", "exp_workspacePatchDelete2.txt", "addition.txt", //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
+ "exp_workspacePatchDelete1.txt" }, //$NON-NLS-1$
+ "patch_workspacePatchDelete.txt", new String[] { "exp_workspacePatchMod2.txt", "addition.txt", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ "exp_workspacePatchMod1.txt", "addition.txt" }, //$NON-NLS-1$ //$NON-NLS-2$
+ true, 0);
}
// Keeps track of the failures
private List<AssertionError> failures = new ArrayList<>();
+ @Test
public void testPatchdataSubfolders() throws IOException, CoreException {
- URL patchdataUrl = new URL(PatchUtils.getBundle().getEntry("/"),
- new Path(PatchUtils.PATCHDATA).toString());
+ URL patchdataUrl = new URL(PatchUtils.getBundle().getEntry("/"), new Path(PatchUtils.PATCHDATA).toString());
patchdataUrl = FileLocator.resolve(patchdataUrl);
Map<String, PatchTestConfiguration> map = null;
@@ -203,8 +243,7 @@ public class PatchTest extends TestCase {
PatchConfiguration pc = ptc.pc;
// create a message to distinguish tests from different subfolders
- String msg = "Test for subfolder [" + PatchUtils.PATCHDATA + "/"
- + sf + "] failed.";
+ String msg = "Test for subfolder [" + PatchUtils.PATCHDATA + "/" + sf + "] failed.";
try {
// test with expected result
@@ -222,8 +261,7 @@ public class PatchTest extends TestCase {
continue; // continue with a next subfolder
}
failures.add(new AssertionError(
- "\npatchWorkspace should fail for folder ["
- + PatchUtils.PATCHDATA + "/" + sf + "]."));
+ "\npatchWorkspace should fail for folder [" + PatchUtils.PATCHDATA + "/" + sf + "]."));
}
}
@@ -255,16 +293,16 @@ public class PatchTest extends TestCase {
/**
* @param patchdataUrl
* @return A map with subfolder name as a key and an array of objects as a
- * value. The first object in the array is another array (of
- * Strings) containing file names for the test. The last value in
- * this array can be <code>null</code> as testing against actual
- * result is optional. The second object is an instance of
- * <code>PatchConfiguration</code> class.
+ * value. The first object in the array is another array (of Strings)
+ * containing file names for the test. The last value in this array can
+ * be <code>null</code> as testing against actual result is optional.
+ * The second object is an instance of <code>PatchConfiguration</code>
+ * class.
* @throws IOException
* @throws CoreException
*/
- private Map<String, PatchTestConfiguration> extractNamesForJarProtocol(URL patchdataUrl) throws IOException,
- CoreException {
+ private Map<String, PatchTestConfiguration> extractNamesForJarProtocol(URL patchdataUrl)
+ throws IOException, CoreException {
JarFile jarFile = ((JarURLConnection) patchdataUrl.openConnection()).getJarFile();
// look for the patchdata folder entry
@@ -292,12 +330,13 @@ public class PatchTest extends TestCase {
// a subfolder found
ZipEntry patchConf = jarFile.getEntry(entryName + "/" + PATCH_CONFIGURATION);
if (patchConf != null) {
- JarEntryStorage jes = new JarEntryStorage(entry,jarFile);
+ JarEntryStorage jes = new JarEntryStorage(entry, jarFile);
Properties properties = new Properties();
try {
properties.load(jes.getContents());
} catch (IOException e) {
- fail("IOException occured while loading the Patch Configuration file for "+entryName.toString());
+ fail("IOException occured while loading the Patch Configuration file for "
+ + entryName.toString());
}
processProperties(result, properties, entryName);
} else {
@@ -309,16 +348,14 @@ public class PatchTest extends TestCase {
return result;
}
- private Map<String, PatchTestConfiguration> extractNamesForFileProtocol(URL patchdataUrl)
- throws CoreException {
+ private Map<String, PatchTestConfiguration> extractNamesForFileProtocol(URL patchdataUrl) throws CoreException {
Map<String, PatchTestConfiguration> result = new HashMap<>(); // configuration map
IPath patchdataFolderPath = new Path(patchdataUrl.getPath());
File patchdataFolderFile = patchdataFolderPath.toFile();
assertTrue(patchdataFolderFile.isDirectory());
- File[] listOfSubfolders = patchdataFolderFile
- .listFiles((FileFilter) File::isDirectory);
+ File[] listOfSubfolders = patchdataFolderFile.listFiles((FileFilter) File::isDirectory);
for (File subfolder : listOfSubfolders) {
Path pcPath = new Path(subfolder.getPath() + "/" + PATCH_CONFIGURATION);
File pcFile = pcPath.toFile();
@@ -330,8 +367,7 @@ public class PatchTest extends TestCase {
try {
properties.load(new FileInputStream(pcFile));
} catch (IOException e) {
- fail("IOException occured while loading the Patch Configuration file for "
- + subfolder.toString());
+ fail("IOException occured while loading the Patch Configuration file for " + subfolder.toString());
}
processProperties(result, properties, subfolder.getName());
} else {
@@ -382,7 +418,7 @@ public class PatchTest extends TestCase {
tpc.originalFileNames = cf;
tpc.patchFileName = pf;
tpc.subfolderName = subfolderName;
- tpc.expectedFileNames= erf;
+ tpc.expectedFileNames = erf;
tpc.actualFileNames = arf;
tpc.pc = pc;
@@ -395,8 +431,8 @@ public class PatchTest extends TestCase {
}
private void filePatch(final String old, String patch, String expt) throws CoreException, IOException {
- LineReader lr= new LineReader(PatchUtils.getReader(expt));
- List<String> inLines= lr.readLines();
+ LineReader lr = new LineReader(PatchUtils.getReader(expt));
+ List<String> inLines = lr.readLines();
String expected = LineReader.createString(false, inLines);
IStorage oldStorage = new StringStorage(old);
@@ -412,30 +448,29 @@ public class PatchTest extends TestCase {
}
private void patcherPatch(String old, String patch, String expt) {
- LineReader lr= new LineReader(PatchUtils.getReader(old));
- List<String> inLines= lr.readLines();
+ LineReader lr = new LineReader(PatchUtils.getReader(old));
+ List<String> inLines = lr.readLines();
- WorkspacePatcher patcher= new WorkspacePatcher();
+ WorkspacePatcher patcher = new WorkspacePatcher();
try {
patcher.parse(PatchUtils.getReader(patch));
} catch (IOException e) {
e.printStackTrace();
}
- FilePatch2[] diffs= patcher.getDiffs();
+ FilePatch2[] diffs = patcher.getDiffs();
Assert.assertEquals(diffs.length, 1);
FileDiffResult diffResult = patcher.getDiffResult(diffs[0]);
diffResult.patch(inLines, null);
- LineReader expectedContents= new LineReader(PatchUtils.getReader(expt));
- List<String> expectedLines= expectedContents.readLines();
+ LineReader expectedContents = new LineReader(PatchUtils.getReader(expt));
+ List<String> expectedLines = expectedContents.readLines();
Assert.assertArrayEquals(expectedLines.toArray(), inLines.toArray());
}
- private void patchWorkspace(String[] originalFiles, String patch,
- String[] expectedOutcomeFiles, boolean reverse,
+ private void patchWorkspace(String[] originalFiles, String patch, String[] expectedOutcomeFiles, boolean reverse,
int fuzzFactor) {
PatchConfiguration pc = new PatchConfiguration();
pc.setReversed(reverse);
@@ -450,14 +485,15 @@ public class PatchTest extends TestCase {
* @param originalFiles
* @param patch
* @param expectedOutcomeFiles
- * @param patchConfiguration
- * The patch configuration to use. One of its parameters is fuzz
- * factor. If it equals <code>-1</code> it means that the fuzz
- * should be calculated automatically.
+ * @param patchConfiguration The patch configuration to use. One of its
+ * parameters is fuzz factor. If it equals
+ * <code>-1</code> it means that the fuzz should be
+ * calculated automatically.
*/
- private void patchWorkspace(String msg, String[] originalFiles, String patch, String[] expectedOutcomeFiles, PatchConfiguration patchConfiguration) {
+ private void patchWorkspace(String msg, String[] originalFiles, String patch, String[] expectedOutcomeFiles,
+ PatchConfiguration patchConfiguration) {
- //ensure that we have the same number of input files as we have expected files
+ // ensure that we have the same number of input files as we have expected files
Assert.assertEquals(originalFiles.length, expectedOutcomeFiles.length);
// Parse the passed in patch and extract all the Diffs
@@ -472,22 +508,23 @@ public class PatchTest extends TestCase {
e.printStackTrace();
}
- //Sort the diffs by project
- FilePatch2[] diffs= patcher.getDiffs();
+ // Sort the diffs by project
+ FilePatch2[] diffs = patcher.getDiffs();
- //Iterate through all of the original files, apply the diffs that belong to the file and compare
- //with the corresponding outcome file
+ // Iterate through all of the original files, apply the diffs that belong to the
+ // file and compare
+ // with the corresponding outcome file
for (int i = 0; i < originalFiles.length; i++) {
- LineReader lr= new LineReader(PatchUtils.getReader(originalFiles[i]));
- List<String> inLines= lr.readLines();
+ LineReader lr = new LineReader(PatchUtils.getReader(originalFiles[i]));
+ List<String> inLines = lr.readLines();
FileDiffResult diffResult = patcher.getDiffResult(diffs[i]);
diffResult.patch(inLines, null);
- LineReader expectedContents= new LineReader(PatchUtils.getReader(expectedOutcomeFiles[i]));
- List<String> expectedLines= expectedContents.readLines();
+ LineReader expectedContents = new LineReader(PatchUtils.getReader(expectedOutcomeFiles[i]));
+ List<String> expectedLines = expectedContents.readLines();
- Object[] expected= expectedLines.toArray();
+ Object[] expected = expectedLines.toArray();
String resultString = LineReader.createString(patcher.isPreserveLineDelimeters(), inLines);
LineReader resultReader = new LineReader(new BufferedReader(new StringReader(resultString)));
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchUITest.java b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchUITest.java
index af8f79534..69c16203d 100644
--- a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchUITest.java
+++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchUITest.java
@@ -13,6 +13,10 @@
*******************************************************************************/
package org.eclipse.compare.tests;
+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.InputStream;
import java.lang.reflect.InvocationTargetException;
@@ -31,12 +35,11 @@ import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.swt.dnd.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.ui.PlatformUI;
+import org.junit.*;
import org.osgi.service.prefs.BackingStoreException;
import org.osgi.service.prefs.Preferences;
-import junit.framework.TestCase;
-
-public class PatchUITest extends TestCase {
+public class PatchUITest {
private static final String TEST_PROJECT = "ApplyPatchTest";
@@ -46,25 +49,19 @@ public class PatchUITest extends TestCase {
private PatchWizardDialog wizardDialog = null;
private PatchWizard wizard = null;
- public PatchUITest(String name) {
- super(name);
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
testProject = workspaceRoot.getProject(TEST_PROJECT);
testProject.create(null);
testProject.open(null);
}
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
+ @After
+ public void tearDown() throws Exception {
testProject.delete(true, null);
}
-
+@Test
public void testApplyClipboardPatch() throws CoreException {
// Clipboard support on Mac OS is not reliable when tests are run
// through an SSH session, see bug 272870 for details
@@ -92,7 +89,7 @@ public class PatchUITest extends TestCase {
InputStream actual = testProject.getFile("context.txt").getContents();
compareStreams(expected, actual);
}
-
+@Test
public void testApplyWorkspacePatch() throws CoreException {
copyIntoWorkspace("patch_addition.txt");
@@ -121,7 +118,7 @@ public class PatchUITest extends TestCase {
.getContents();
compareStreams(expected, actual);
}
-
+@Test
public void testApplyClipboardPatch_AdditionWithWindowsLD() throws Exception {
// Clipboard support on Mac OS is not reliable when tests are run
// through an SSH session, see bug 272870 for details
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/RangeDifferencerThreeWayDiffTest.java b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/RangeDifferencerThreeWayDiffTest.java
index 59d990d75..4e770df19 100644
--- a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/RangeDifferencerThreeWayDiffTest.java
+++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/RangeDifferencerThreeWayDiffTest.java
@@ -13,7 +13,7 @@
*******************************************************************************/
package org.eclipse.compare.tests;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
import org.eclipse.compare.contentmergeviewer.ITokenComparator;
import org.eclipse.compare.internal.DocLineComparator;
@@ -21,22 +21,19 @@ import org.eclipse.compare.rangedifferencer.RangeDifference;
import org.eclipse.compare.rangedifferencer.RangeDifferencer;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jface.text.Document;
+import org.junit.Test;
+public class RangeDifferencerThreeWayDiffTest {
-public class RangeDifferencerThreeWayDiffTest extends TestCase {
-
- static final String S= System.getProperty("line.separator"); //$NON-NLS-1$
-
- public RangeDifferencerThreeWayDiffTest(String name) {
- super(name);
- }
+ static final String S = System.lineSeparator();
+ @Test
public void testInsertConflict() {
- String a = "A" + S + "B" + S + "C" + S + "D"; //$NON-NLS-1$
+ String a = "A" + S + "B" + S + "C" + S + "D"; //$NON-NLS-1$
String l = "A" + S + "B" + S + "x" + S + "C" + S + "D"; //$NON-NLS-1$
String r = "A" + S + "B" + S + "y" + S + "C" + S + "D"; //$NON-NLS-1$
- RangeDifference[] diffs= findRange(a, l, r);
+ RangeDifference[] diffs = findRange(a, l, r);
assertEquals(3, diffs.length);
assertEquals(RangeDifference.NOCHANGE, diffs[0].kind());
@@ -44,12 +41,13 @@ public class RangeDifferencerThreeWayDiffTest extends TestCase {
assertEquals(RangeDifference.NOCHANGE, diffs[2].kind());
}
+ @Test
public void testChangeConflict() {
- String a = "A" + S + "B" + S + "C" + S + "D"; //$NON-NLS-1$
+ String a = "A" + S + "B" + S + "C" + S + "D"; //$NON-NLS-1$
String l = "A" + S + "b1" + S + "C" + S + "D"; //$NON-NLS-1$
String r = "A" + S + "b2" + S + "C" + S + "D"; //$NON-NLS-1$
- RangeDifference[] diffs= findRange(a, l, r);
+ RangeDifference[] diffs = findRange(a, l, r);
assertEquals(3, diffs.length);
assertEquals(RangeDifference.NOCHANGE, diffs[0].kind());
@@ -57,12 +55,13 @@ public class RangeDifferencerThreeWayDiffTest extends TestCase {
assertEquals(RangeDifference.NOCHANGE, diffs[2].kind());
}
+ @Test
public void testDeleteAndChangeConflict() {
- String a = "A" + S + "B" + S + "C"; //$NON-NLS-1$
- String l = "A" + S + "C"; //$NON-NLS-1$
+ String a = "A" + S + "B" + S + "C"; //$NON-NLS-1$
+ String l = "A" + S + "C"; //$NON-NLS-1$
String r = "A" + S + "b1" + S + "C"; //$NON-NLS-1$
- RangeDifference[] diffs= findRange(a, l, r);
+ RangeDifference[] diffs = findRange(a, l, r);
assertEquals(3, diffs.length);
assertEquals(RangeDifference.NOCHANGE, diffs[0].kind());
@@ -70,12 +69,13 @@ public class RangeDifferencerThreeWayDiffTest extends TestCase {
assertEquals(RangeDifference.NOCHANGE, diffs[2].kind());
}
+ @Test
public void testInsertWithinMultilineChangeConflict() {
- String a = "A" + S + "B" + S + "C" + S + "D"; //$NON-NLS-1$
+ String a = "A" + S + "B" + S + "C" + S + "D"; //$NON-NLS-1$
String l = "A" + S + "B" + S + "x" + S + "C" + S + "D"; //$NON-NLS-1$
- String r = "A" + S + "x" + S + "y" + S + "D"; //$NON-NLS-1$
+ String r = "A" + S + "x" + S + "y" + S + "D"; //$NON-NLS-1$
- RangeDifference[] diffs= findRange(a, l, r);
+ RangeDifference[] diffs = findRange(a, l, r);
assertEquals(3, diffs.length);
assertEquals(RangeDifference.NOCHANGE, diffs[0].kind());
@@ -83,12 +83,13 @@ public class RangeDifferencerThreeWayDiffTest extends TestCase {
assertEquals(RangeDifference.NOCHANGE, diffs[2].kind());
}
+ @Test
public void testAdjoiningChangesNoConflict() {
- String a = "A" + S + "B" + S + "C" + S + "D"; //$NON-NLS-1$
- String l = "A" + S + "b1" + S + "C" + S + "D"; //$NON-NLS-1$
- String r = "A" + S + "B" + S + "c1" + S + "D"; //$NON-NLS-1$
+ String a = "A" + S + "B" + S + "C" + S + "D"; //$NON-NLS-1$
+ String l = "A" + S + "b1" + S + "C" + S + "D"; //$NON-NLS-1$
+ String r = "A" + S + "B" + S + "c1" + S + "D"; //$NON-NLS-1$
- RangeDifference[] diffs= findRange(a, l, r);
+ RangeDifference[] diffs = findRange(a, l, r);
assertEquals(4, diffs.length);
assertEquals(RangeDifference.NOCHANGE, diffs[0].kind());
@@ -97,12 +98,13 @@ public class RangeDifferencerThreeWayDiffTest extends TestCase {
assertEquals(RangeDifference.NOCHANGE, diffs[3].kind());
}
+ @Test
public void testAdjoiningInsertAndChangeNoConflict() {
- String a = "A" + S + "B" + S + "C" + S + "D"; //$NON-NLS-1$
- String l = "A" + S + "B" + S + "x" + S + "C" + S + "D"; //$NON-NLS-1$
- String r = "A" + S + "B" + S + "c1" + S + "D"; //$NON-NLS-1$
+ String a = "A" + S + "B" + S + "C" + S + "D"; //$NON-NLS-1$
+ String l = "A" + S + "B" + S + "x" + S + "C" + S + "D"; //$NON-NLS-1$
+ String r = "A" + S + "B" + S + "c1" + S + "D"; //$NON-NLS-1$
- RangeDifference[] diffs= findRange(a, l, r);
+ RangeDifference[] diffs = findRange(a, l, r);
assertEquals(4, diffs.length);
assertEquals(RangeDifference.NOCHANGE, diffs[0].kind());
@@ -111,13 +113,13 @@ public class RangeDifferencerThreeWayDiffTest extends TestCase {
assertEquals(RangeDifference.NOCHANGE, diffs[3].kind());
}
-
+ @Test
public void testAdjoiningMultilineChangeNoConflict() {
String a = "A" + S + "B" + S + "C" + S + "D"; //$NON-NLS-1$
String l = "A" + S + "x" + S + "y" + S + "D"; //$NON-NLS-1$
String r = "A" + S + "B" + S + "C" + S + "d1"; //$NON-NLS-1$
- RangeDifference[] diffs= findRange(a, l, r);
+ RangeDifference[] diffs = findRange(a, l, r);
assertEquals(3, diffs.length);
assertEquals(RangeDifference.NOCHANGE, diffs[0].kind());
@@ -126,9 +128,9 @@ public class RangeDifferencerThreeWayDiffTest extends TestCase {
}
private RangeDifference[] findRange(String a, String l, String r) {
- ITokenComparator ancestor= new DocLineComparator(new Document(a), null, false);
- ITokenComparator left= new DocLineComparator(new Document(l), null, false);
- ITokenComparator right= new DocLineComparator(new Document(r), null, false);
+ ITokenComparator ancestor = new DocLineComparator(new Document(a), null, false);
+ ITokenComparator left = new DocLineComparator(new Document(l), null, false);
+ ITokenComparator right = new DocLineComparator(new Document(r), null, false);
return RangeDifferencer.findRanges(new NullProgressMonitor(), ancestor, left, right);
}
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/StreamMergerTest.java b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/StreamMergerTest.java
index 2f7baea22..d20e24960 100644
--- a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/StreamMergerTest.java
+++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/StreamMergerTest.java
@@ -13,6 +13,8 @@
*******************************************************************************/
package org.eclipse.compare.tests;
+import static org.junit.Assert.assertEquals;
+
import java.io.*;
import java.nio.charset.StandardCharsets;
@@ -20,124 +22,127 @@ import org.eclipse.compare.IStreamMerger;
import org.eclipse.compare.internal.merge.TextStreamMerger;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.junit.Test;
-import junit.framework.TestCase;
-
-public class StreamMergerTest extends TestCase {
+public class StreamMergerTest {
- private static final String ABC= "abc"; //$NON-NLS-1$
- private static final String DEF= "def"; //$NON-NLS-1$
- private static final String BAR= "bar"; //$NON-NLS-1$
- private static final String FOO= "foo"; //$NON-NLS-1$
- private static final String XYZ= "xyz"; //$NON-NLS-1$
- private static final String _123= "123"; //$NON-NLS-1$
- private static final String _456= "456"; //$NON-NLS-1$
+ private static final String ABC = "abc"; //$NON-NLS-1$
+ private static final String DEF = "def"; //$NON-NLS-1$
+ private static final String BAR = "bar"; //$NON-NLS-1$
+ private static final String FOO = "foo"; //$NON-NLS-1$
+ private static final String XYZ = "xyz"; //$NON-NLS-1$
+ private static final String _123 = "123"; //$NON-NLS-1$
+ private static final String _456 = "456"; //$NON-NLS-1$
- String encoding= "UTF-8"; //$NON-NLS-1$
- static final String SEPARATOR= System.getProperty("line.separator"); //$NON-NLS-1$
-
- public StreamMergerTest(String name) {
- super(name);
- }
+ String encoding = "UTF-8"; //$NON-NLS-1$
+ static final String SEPARATOR = System.lineSeparator();
+ @Test
public void testIncomingAddition() {
- String a= ABC + SEPARATOR + DEF + SEPARATOR + XYZ;
- String t= ABC + SEPARATOR + DEF + SEPARATOR + XYZ;
- String o= ABC + SEPARATOR + DEF + SEPARATOR + _123 + SEPARATOR + XYZ;
+ String a = ABC + SEPARATOR + DEF + SEPARATOR + XYZ;
+ String t = ABC + SEPARATOR + DEF + SEPARATOR + XYZ;
+ String o = ABC + SEPARATOR + DEF + SEPARATOR + _123 + SEPARATOR + XYZ;
- StringBuilder output= new StringBuilder();
+ StringBuilder output = new StringBuilder();
- IStatus status= merge(output, a, t, o);
+ IStatus status = merge(output, a, t, o);
assertEquals(status.getSeverity(), IStatus.OK);
assertEquals(status.getCode(), IStatus.OK);
assertEquals(output.toString(), ABC + SEPARATOR + DEF + SEPARATOR + _123 + SEPARATOR + XYZ + SEPARATOR);
}
+ @Test
public void testIncomingDeletion() {
- String a= ABC + SEPARATOR + DEF + SEPARATOR + XYZ;
- String t= ABC + SEPARATOR + DEF + SEPARATOR + XYZ;
- String o= ABC + SEPARATOR + XYZ;
+ String a = ABC + SEPARATOR + DEF + SEPARATOR + XYZ;
+ String t = ABC + SEPARATOR + DEF + SEPARATOR + XYZ;
+ String o = ABC + SEPARATOR + XYZ;
- StringBuilder output= new StringBuilder();
+ StringBuilder output = new StringBuilder();
- IStatus status= merge(output, a, t, o);
+ IStatus status = merge(output, a, t, o);
assertEquals(status.getSeverity(), IStatus.OK);
assertEquals(status.getCode(), IStatus.OK);
assertEquals(output.toString(), ABC + SEPARATOR + XYZ + SEPARATOR);
}
+ @Test
public void testIncomingReplacement() {
- String a= ABC + SEPARATOR + DEF + SEPARATOR + XYZ;
- String t= ABC + SEPARATOR + DEF + SEPARATOR + XYZ;
- String o= ABC + SEPARATOR + _123 + SEPARATOR + XYZ;
+ String a = ABC + SEPARATOR + DEF + SEPARATOR + XYZ;
+ String t = ABC + SEPARATOR + DEF + SEPARATOR + XYZ;
+ String o = ABC + SEPARATOR + _123 + SEPARATOR + XYZ;
- StringBuilder output= new StringBuilder();
+ StringBuilder output = new StringBuilder();
- IStatus status= merge(output, a, t, o);
+ IStatus status = merge(output, a, t, o);
assertEquals(status.getSeverity(), IStatus.OK);
assertEquals(status.getCode(), IStatus.OK);
assertEquals(output.toString(), ABC + SEPARATOR + _123 + SEPARATOR + XYZ + SEPARATOR);
}
+ @Test
public void testNonConflictingMerge() {
- String a= ABC + SEPARATOR + DEF + SEPARATOR + XYZ;
- String t= ABC + SEPARATOR + DEF + SEPARATOR + XYZ + SEPARATOR + FOO;
- String o= ABC + SEPARATOR + _123 + SEPARATOR + _456 + SEPARATOR + XYZ;
+ String a = ABC + SEPARATOR + DEF + SEPARATOR + XYZ;
+ String t = ABC + SEPARATOR + DEF + SEPARATOR + XYZ + SEPARATOR + FOO;
+ String o = ABC + SEPARATOR + _123 + SEPARATOR + _456 + SEPARATOR + XYZ;
- StringBuilder output= new StringBuilder();
+ StringBuilder output = new StringBuilder();
- IStatus status= merge(output, a, t, o);
+ IStatus status = merge(output, a, t, o);
assertEquals(status.getSeverity(), IStatus.OK);
assertEquals(status.getCode(), IStatus.OK);
- assertEquals(output.toString(), ABC + SEPARATOR + _123 + SEPARATOR + _456 + SEPARATOR + XYZ + SEPARATOR + FOO + SEPARATOR);
+ assertEquals(output.toString(),
+ ABC + SEPARATOR + _123 + SEPARATOR + _456 + SEPARATOR + XYZ + SEPARATOR + FOO + SEPARATOR);
}
+ @Test
public void testConflictingReplacement() {
- String a= ABC + SEPARATOR + DEF + SEPARATOR + XYZ;
- String t= ABC + SEPARATOR + FOO + SEPARATOR + XYZ;
- String o= ABC + SEPARATOR + BAR + SEPARATOR + XYZ;
+ String a = ABC + SEPARATOR + DEF + SEPARATOR + XYZ;
+ String t = ABC + SEPARATOR + FOO + SEPARATOR + XYZ;
+ String o = ABC + SEPARATOR + BAR + SEPARATOR + XYZ;
- StringBuilder output= new StringBuilder();
+ StringBuilder output = new StringBuilder();
- IStatus status= merge(output, a, t, o);
+ IStatus status = merge(output, a, t, o);
assertEquals(status.getSeverity(), IStatus.ERROR);
assertEquals(status.getCode(), IStreamMerger.CONFLICT);
}
+ @Test
public void testConflictingAddition() {
- String a= ABC + SEPARATOR + DEF + SEPARATOR + XYZ;
- String t= ABC + SEPARATOR + DEF + SEPARATOR + _123 + SEPARATOR + XYZ;
- String o= ABC + SEPARATOR + DEF + SEPARATOR + _123 + SEPARATOR + XYZ;
+ String a = ABC + SEPARATOR + DEF + SEPARATOR + XYZ;
+ String t = ABC + SEPARATOR + DEF + SEPARATOR + _123 + SEPARATOR + XYZ;
+ String o = ABC + SEPARATOR + DEF + SEPARATOR + _123 + SEPARATOR + XYZ;
- StringBuilder output= new StringBuilder();
+ StringBuilder output = new StringBuilder();
- IStatus status= merge(output, a, t, o);
+ IStatus status = merge(output, a, t, o);
assertEquals(status.getSeverity(), IStatus.OK);
assertEquals(status.getCode(), IStatus.OK);
assertEquals(output.toString(), ABC + SEPARATOR + DEF + SEPARATOR + _123 + SEPARATOR + XYZ + SEPARATOR);
}
+ @Test
public void testConflictingDeletion() {
- String a= ABC + SEPARATOR + DEF + SEPARATOR + XYZ;
- String t= ABC + SEPARATOR + XYZ;
- String o= ABC + SEPARATOR + XYZ;
+ String a = ABC + SEPARATOR + DEF + SEPARATOR + XYZ;
+ String t = ABC + SEPARATOR + XYZ;
+ String o = ABC + SEPARATOR + XYZ;
- StringBuilder output= new StringBuilder();
+ StringBuilder output = new StringBuilder();
- IStatus status= merge(output, a, t, o);
+ IStatus status = merge(output, a, t, o);
assertEquals(status.getSeverity(), IStatus.OK);
assertEquals(status.getCode(), IStatus.OK);
@@ -145,19 +150,19 @@ public class StreamMergerTest extends TestCase {
}
private IStatus merge(StringBuilder output, String a, String m, String y) {
- InputStream ancestor= new ByteArrayInputStream(a.getBytes(StandardCharsets.UTF_8));
- InputStream target= new ByteArrayInputStream(m.getBytes(StandardCharsets.UTF_8));
- InputStream other= new ByteArrayInputStream(y.getBytes(StandardCharsets.UTF_8));
+ InputStream ancestor = new ByteArrayInputStream(a.getBytes(StandardCharsets.UTF_8));
+ InputStream target = new ByteArrayInputStream(m.getBytes(StandardCharsets.UTF_8));
+ InputStream other = new ByteArrayInputStream(y.getBytes(StandardCharsets.UTF_8));
return merge(output, ancestor, target, other);
}
- private IStatus merge(StringBuilder output, InputStream ancestor,
- InputStream target, InputStream other) {
- ByteArrayOutputStream os= new ByteArrayOutputStream();
+ private IStatus merge(StringBuilder output, InputStream ancestor, InputStream target, InputStream other) {
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
- IStreamMerger merger= new TextStreamMerger();
- IStatus status= merger.merge(os, encoding, ancestor, encoding, target, encoding, other, encoding, (IProgressMonitor) null);
+ IStreamMerger merger = new TextStreamMerger();
+ IStatus status = merger.merge(os, encoding, ancestor, encoding, target, encoding, other, encoding,
+ (IProgressMonitor) null);
output.append(new String(os.toByteArray(), StandardCharsets.UTF_8));
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/StructureCreatorTest.java b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/StructureCreatorTest.java
index 96d66a35b..5d8e70bd3 100644
--- a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/StructureCreatorTest.java
+++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/StructureCreatorTest.java
@@ -13,36 +13,24 @@
*******************************************************************************/
package org.eclipse.compare.tests;
+import static org.junit.Assert.assertNull;
+
import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import junit.framework.TestCase;
-
import org.eclipse.compare.ICompareFilter;
import org.eclipse.compare.ISharedDocumentAdapter;
-import org.eclipse.compare.structuremergeviewer.DocumentRangeNode;
-import org.eclipse.compare.structuremergeviewer.IStructureComparator;
-import org.eclipse.compare.structuremergeviewer.StructureCreator;
+import org.eclipse.compare.structuremergeviewer.*;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.Document;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.Region;
+import org.eclipse.jface.text.*;
import org.junit.Assert;
+import org.junit.Test;
-public class StructureCreatorTest extends TestCase {
-
- public StructureCreatorTest() {
- super();
- }
-
- public StructureCreatorTest(String name) {
- super(name);
- }
+public class StructureCreatorTest {
+@Test
public void testIgnoreWhitespace() {
IDocument[] docs = new IDocument[15];
docs[0] = new Document();
diff --git a/tests/org.eclipse.core.tests.net/.cvsignore b/tests/org.eclipse.core.tests.net/.cvsignore
deleted file mode 100644
index ba077a403..000000000
--- a/tests/org.eclipse.core.tests.net/.cvsignore
+++ /dev/null
@@ -1 +0,0 @@
-bin
diff --git a/tests/org.eclipse.core.tests.net/.project b/tests/org.eclipse.core.tests.net/.project
index 1b93d51e2..bb53ef766 100644
--- a/tests/org.eclipse.core.tests.net/.project
+++ b/tests/org.eclipse.core.tests.net/.project
@@ -20,15 +20,9 @@
<arguments>
</arguments>
</buildCommand>
- <buildCommand>
- <name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
- <nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature>
</natures>
</projectDescription>
diff --git a/tests/org.eclipse.core.tests.net/META-INF/MANIFEST.MF b/tests/org.eclipse.core.tests.net/META-INF/MANIFEST.MF
index 920e27320..b7e5f9a10 100644
--- a/tests/org.eclipse.core.tests.net/META-INF/MANIFEST.MF
+++ b/tests/org.eclipse.core.tests.net/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Net Tests Plug-in
Bundle-SymbolicName: org.eclipse.core.tests.net
-Bundle-Version: 1.4.500.qualifier
+Bundle-Version: 1.4.600.qualifier
Bundle-Activator: org.eclipse.core.tests.net.Activator
Bundle-Vendor: Eclipse.org
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.3.0,4.0.0)",
diff --git a/tests/org.eclipse.core.tests.net/pom.xml b/tests/org.eclipse.core.tests.net/pom.xml
index fd6a72a1a..bd197d3ab 100644
--- a/tests/org.eclipse.core.tests.net/pom.xml
+++ b/tests/org.eclipse.core.tests.net/pom.xml
@@ -18,7 +18,7 @@
</parent>
<groupId>org.eclipse.core</groupId>
<artifactId>org.eclipse.core.tests.net</artifactId>
- <version>1.4.500-SNAPSHOT</version>
+ <version>1.4.600-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
<properties>
diff --git a/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/AllNetTests.java b/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/AllNetTests.java
index 65a5f3e82..ec48f311b 100644
--- a/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/AllNetTests.java
+++ b/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/AllNetTests.java
@@ -16,10 +16,8 @@ package org.eclipse.core.tests.net;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
-import junit.framework.*;
-
@RunWith(Suite.class)
@Suite.SuiteClasses({ NetTest.class, PreferenceModifyListenerTest.class })
-public class AllNetTests extends TestCase {
+public class AllNetTests {
}
diff --git a/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/SystemProxyTest.java b/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/SystemProxyTest.java
index 918fee7b0..e5718e65b 100644
--- a/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/SystemProxyTest.java
+++ b/tests/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/SystemProxyTest.java
@@ -13,49 +13,38 @@
*******************************************************************************/
package org.eclipse.core.tests.net;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
import org.eclipse.core.internal.net.ProxyData;
import org.eclipse.core.internal.net.ProxySelector;
import org.eclipse.core.net.proxy.IProxyData;
import org.eclipse.core.net.proxy.IProxyService;
+import org.junit.*;
-public class SystemProxyTest extends TestCase {
+public class SystemProxyTest {
private boolean isProxiesDefault;
private boolean isSystemProxiesDefault;
private Map<String, IProxyData> proxyDataMap = new HashMap<>();
- public SystemProxyTest() {
- super();
- }
-
- public SystemProxyTest(String name) {
- super(name);
- }
-
- public static Test suite() {
- return new TestSuite(SystemProxyTest.class);
- }
-
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
isSystemProxiesDefault = isSystemProxiesEnabled();
setSystemProxiesEnabled(true);
isProxiesDefault = isProxiesEnabled();
setProxiesEnabled(true);
}
- protected void tearDown() throws Exception {
- super.tearDown();
+ @After
+ public void tearDown() throws Exception {
setProxiesEnabled(isProxiesDefault);
setSystemProxiesEnabled(isSystemProxiesDefault);
IProxyData[] data = getProxyManager().getProxyData();
@@ -79,8 +68,7 @@ public class SystemProxyTest extends TestCase {
private void setProxiesEnabled(boolean enabled) {
this.getProxyManager().setProxiesEnabled(enabled);
- if (enabled && this.getProxyManager().isSystemProxiesEnabled()
- && !this.getProxyManager().hasSystemProxies()) {
+ if (enabled && this.getProxyManager().isSystemProxiesEnabled() && !this.getProxyManager().hasSystemProxies()) {
assertEquals(false, this.getProxyManager().isProxiesEnabled());
} else {
assertEquals(enabled, this.getProxyManager().isProxiesEnabled());
@@ -100,8 +88,7 @@ public class SystemProxyTest extends TestCase {
assertEquals(expectedData.getPort(), data.getPort());
assertEquals(expectedData.getUserId(), data.getUserId());
assertEquals(expectedData.getPassword(), data.getPassword());
- assertEquals(expectedData.isRequiresAuthentication(), data
- .isRequiresAuthentication());
+ assertEquals(expectedData.isRequiresAuthentication(), data.isRequiresAuthentication());
assertEquals(expectedData.getSource(), data.getSource());
}
@@ -139,36 +126,40 @@ public class SystemProxyTest extends TestCase {
}
/**
- * This test needs system env set. See {@link #initializeTestProxyData()}
- * for values.
+ * This test needs system env set. See {@link #initializeTestProxyData()} for
+ * values.
*/
+ @Test
public void testGetProxyDataForHost_LinuxEnvSettings() {
initializeTestProxyData("LINUX_ENV");
checkGetProxyDataForHost();
}
/**
- * This test needs system env set. See {@link #initializeTestProxyData()}
- * for values.
+ * This test needs system env set. See {@link #initializeTestProxyData()} for
+ * values.
*/
+ @Test
public void testProxySelector_LinuxEnvSettings() {
initializeTestProxyData("LINUX_ENV");
checkProxySelector();
}
/**
- * This test needs Gnome settings set. See
- * {@link #initializeTestProxyData()} for values.
+ * This test needs Gnome settings set. See {@link #initializeTestProxyData()}
+ * for values.
*/
+ @Test
public void testGetProxyDataForHost_LinuxGnomeSettings() {
initializeTestProxyData("LINUX_GNOME");
checkGetProxyDataForHost();
}
/**
- * This test needs Gnome settings set. See
- * {@link #initializeTestProxyData()} for values.
+ * This test needs Gnome settings set. See {@link #initializeTestProxyData()}
+ * for values.
*/
+ @Test
public void testProxySelector_LinuxGnomeSettings() {
initializeTestProxyData("LINUX_GNOME");
checkProxySelector();
@@ -178,6 +169,7 @@ public class SystemProxyTest extends TestCase {
* This test needs Windows IE settings manually set. See
* {@link #initializeTestProxyData()} for values.
*/
+ @Test
public void testGetProxyDataForHost_WindowsIEManualSettings() {
initializeTestProxyData("WINDOWS_IE");
checkGetProxyDataForHost();
@@ -187,6 +179,7 @@ public class SystemProxyTest extends TestCase {
* This test needs Windows IE settings manually set. See
* {@link #initializeTestProxyData()} for values.
*/
+ @Test
public void testProxySelector_WindowsIEManualSettings() {
initializeTestProxyData("WINDOWS_IE");
checkProxySelector();
@@ -195,47 +188,38 @@ public class SystemProxyTest extends TestCase {
/**
* This test needs Windows IE settings manually set. See
* {@link #initializeTestProxyData()} for values. Additionally set
- * <code>"eclipse.*;nonexisting.com;*.eclipse.org;www.*.com;*.test.*"</code>
- * as proxy bypass in the IE settings.
+ * <code>"eclipse.*;nonexisting.com;*.eclipse.org;www.*.com;*.test.*"</code> as
+ * proxy bypass in the IE settings.
*
* @throws URISyntaxException
*/
- public void testNonProxiedHosts_WindowsIEManualSettings()
- throws URISyntaxException {
- IProxyData[] proxiesData = getProxyManager().select(
- new URI("http://eclipse"));
+ @Test
+ public void testNonProxiedHosts_WindowsIEManualSettings() throws URISyntaxException {
+ IProxyData[] proxiesData = getProxyManager().select(new URI("http://eclipse"));
assertEquals(1, proxiesData.length);
- proxiesData = getProxyManager().select(
- new URI("http://eclipse.org/bugs"));
+ proxiesData = getProxyManager().select(new URI("http://eclipse.org/bugs"));
assertEquals(0, proxiesData.length);
- proxiesData = getProxyManager().select(
- new URI("http://nonexisting.com"));
+ proxiesData = getProxyManager().select(new URI("http://nonexisting.com"));
assertEquals(0, proxiesData.length);
- proxiesData = getProxyManager().select(
- new URI("http://www.eclipse.org"));
+ proxiesData = getProxyManager().select(new URI("http://www.eclipse.org"));
assertEquals(0, proxiesData.length);
- proxiesData = getProxyManager().select(
- new URI("http://www.myDomain.com"));
+ proxiesData = getProxyManager().select(new URI("http://www.myDomain.com"));
assertEquals(0, proxiesData.length);
- proxiesData = getProxyManager().select(
- new URI("http://www.test.edu"));
+ proxiesData = getProxyManager().select(new URI("http://www.test.edu"));
assertEquals(0, proxiesData.length);
}
private void initializeTestProxyData(String proxyDataSource) {
- proxyDataMap.put(IProxyData.HTTP_PROXY_TYPE, new ProxyData(
- IProxyData.HTTP_PROXY_TYPE, "127.0.0.1", 8081, false,
- proxyDataSource));
- proxyDataMap.put(IProxyData.HTTPS_PROXY_TYPE, new ProxyData(
- IProxyData.HTTPS_PROXY_TYPE, "127.0.0.2", 8082, false,
- proxyDataSource));
- proxyDataMap.put(IProxyData.SOCKS_PROXY_TYPE, new ProxyData(
- IProxyData.SOCKS_PROXY_TYPE, "127.0.0.3", 8083, false,
- proxyDataSource));
+ proxyDataMap.put(IProxyData.HTTP_PROXY_TYPE,
+ new ProxyData(IProxyData.HTTP_PROXY_TYPE, "127.0.0.1", 8081, false, proxyDataSource));
+ proxyDataMap.put(IProxyData.HTTPS_PROXY_TYPE,
+ new ProxyData(IProxyData.HTTPS_PROXY_TYPE, "127.0.0.2", 8082, false, proxyDataSource));
+ proxyDataMap.put(IProxyData.SOCKS_PROXY_TYPE,
+ new ProxyData(IProxyData.SOCKS_PROXY_TYPE, "127.0.0.3", 8083, false, proxyDataSource));
}
} \ No newline at end of file

Back to the top