Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kurtakov2018-03-29 03:26:29 -0400
committerAlexander Kurtakov2018-03-29 04:47:41 -0400
commit624acf14a605ec6684ed9f55922590043a9e1ffa (patch)
tree53878a313c56f1c3f5c4473464c4a6562aceb477
parent534d3cc4229625961a0eed78a5e7fb467f2c549e (diff)
downloadeclipse.platform.team-624acf14a605ec6684ed9f55922590043a9e1ffa.tar.gz
eclipse.platform.team-624acf14a605ec6684ed9f55922590043a9e1ffa.tar.xz
eclipse.platform.team-624acf14a605ec6684ed9f55922590043a9e1ffa.zip
Convert to lambda, generify, deprecations and etc. Enabled save actions to automate cleanup tasks. Change-Id: I0ac28928c80871810cfa2eb584079b0ff92a25fd Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
-rw-r--r--tests/org.eclipse.compare.tests/.settings/org.eclipse.jdt.core.prefs64
-rw-r--r--tests/org.eclipse.compare.tests/.settings/org.eclipse.jdt.ui.prefs8
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/AsyncExecTests.java16
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/ContentMergeViewerTest.java13
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/FileDiffResultTest.java6
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/LineReaderTest.java17
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchBuilderTest.java42
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchTest.java137
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchUITest.java37
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/ReflectionUtils.java6
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/TextMergeViewerTest.java210
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/WorkspaceTest.java44
12 files changed, 268 insertions, 332 deletions
diff --git a/tests/org.eclipse.compare.tests/.settings/org.eclipse.jdt.core.prefs b/tests/org.eclipse.compare.tests/.settings/org.eclipse.jdt.core.prefs
index 64dab5a12..2a1fa004c 100644
--- a/tests/org.eclipse.compare.tests/.settings/org.eclipse.jdt.core.prefs
+++ b/tests/org.eclipse.compare.tests/.settings/org.eclipse.jdt.core.prefs
@@ -6,6 +6,15 @@ org.eclipse.jdt.core.builder.resourceCopyExclusionFilter=*.launch
org.eclipse.jdt.core.circularClasspath=error
org.eclipse.jdt.core.classpath.exclusionPatterns=enabled
org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled
+org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled
+org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
+org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull
+org.eclipse.jdt.core.compiler.annotation.nonnull.secondary=
+org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault
+org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary=
+org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
+org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
+org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
@@ -16,19 +25,29 @@ org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.doc.comment.support=enabled
org.eclipse.jdt.core.compiler.maxProblemPerUnit=100
+org.eclipse.jdt.core.compiler.problem.APILeak=warning
+org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
+org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
+org.eclipse.jdt.core.compiler.problem.deadCode=warning
org.eclipse.jdt.core.compiler.problem.deprecation=warning
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
org.eclipse.jdt.core.compiler.problem.discouragedReference=ignore
org.eclipse.jdt.core.compiler.problem.emptyStatement=warning
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore
+org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
+org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
org.eclipse.jdt.core.compiler.problem.fieldHiding=warning
org.eclipse.jdt.core.compiler.problem.finalParameterBound=ignore
org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=error
+org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled
org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=error
+org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning
org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=warning
org.eclipse.jdt.core.compiler.problem.invalidJavadoc=warning
org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled
@@ -37,34 +56,79 @@ org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=enabled
org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=private
org.eclipse.jdt.core.compiler.problem.localVariableHiding=warning
org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=error
+org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore
+org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
+org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled
+org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore
org.eclipse.jdt.core.compiler.problem.missingJavadocComments=ignore
org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=enabled
org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public
org.eclipse.jdt.core.compiler.problem.missingJavadocTags=warning
org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=enabled
org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=private
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
+org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore
org.eclipse.jdt.core.compiler.problem.noEffectAssignment=error
org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=error
org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
+org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning
+org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=warning
+org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error
+org.eclipse.jdt.core.compiler.problem.nullReference=warning
+org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error
+org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning
org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=error
+org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
+org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning
org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=error
+org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore
+org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore
+org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
+org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
+org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=warning
+org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore
+org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore
+org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore
org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=error
+org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
+org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
+org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled
org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
+org.eclipse.jdt.core.compiler.problem.terminalDeprecation=warning
+org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
+org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled
+org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
+org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning
org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=warning
+org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentType=warning
+org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentTypeStrict=disabled
+org.eclipse.jdt.core.compiler.problem.unlikelyEqualsArgumentType=info
org.eclipse.jdt.core.compiler.problem.unnecessaryElse=warning
org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=error
org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=enabled
+org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedImport=error
+org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
org.eclipse.jdt.core.compiler.problem.unusedLocal=error
+org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore
org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=error
+org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
+org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
org.eclipse.jdt.core.incompatibleJDKLevel=ignore
org.eclipse.jdt.core.incompleteClasspath=error
diff --git a/tests/org.eclipse.compare.tests/.settings/org.eclipse.jdt.ui.prefs b/tests/org.eclipse.compare.tests/.settings/org.eclipse.jdt.ui.prefs
index 27b88105a..df8001946 100644
--- a/tests/org.eclipse.compare.tests/.settings/org.eclipse.jdt.ui.prefs
+++ b/tests/org.eclipse.compare.tests/.settings/org.eclipse.jdt.ui.prefs
@@ -33,20 +33,20 @@ sp_cleanup.make_variable_declarations_final=false
sp_cleanup.never_use_blocks=false
sp_cleanup.never_use_parentheses_in_expressions=false
sp_cleanup.on_save_use_additional_actions=true
-sp_cleanup.organize_imports=false
+sp_cleanup.organize_imports=true
sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=false
sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=false
sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
sp_cleanup.remove_private_constructors=false
-sp_cleanup.remove_redundant_type_arguments=false
+sp_cleanup.remove_redundant_type_arguments=true
sp_cleanup.remove_trailing_whitespaces=true
sp_cleanup.remove_trailing_whitespaces_all=true
sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
-sp_cleanup.remove_unnecessary_casts=false
+sp_cleanup.remove_unnecessary_casts=true
sp_cleanup.remove_unnecessary_nls_tags=false
-sp_cleanup.remove_unused_imports=false
+sp_cleanup.remove_unused_imports=true
sp_cleanup.remove_unused_local_variables=false
sp_cleanup.remove_unused_private_fields=false
sp_cleanup.remove_unused_private_members=false
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 023a200c0..4a8b11685 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2016 IBM Corporation and others.
+ * Copyright (c) 2006, 2018 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -36,17 +36,11 @@ public class AsyncExecTests extends TestCase {
public void testQueueAdd() {
WorkQueue q = new WorkQueue();
assertTrue(q.isEmpty());
- IRunnableWithProgress r = new IRunnableWithProgress() {
- @Override
- public void run(IProgressMonitor monitor) {
- // Nothing to do for now
- }
+ IRunnableWithProgress r = monitor -> {
+ // Nothing to do for now
};
- IRunnableWithProgress r2 = new IRunnableWithProgress() {
- @Override
- public void run(IProgressMonitor monitor) {
- // Nothing to do for now
- }
+ IRunnableWithProgress r2 = monitor -> {
+ // Nothing to do for now
};
// Ensure that adding an element adds it
q.add(r);
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/ContentMergeViewerTest.java b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/ContentMergeViewerTest.java
index d5716cabc..48924ac93 100644
--- a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/ContentMergeViewerTest.java
+++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/ContentMergeViewerTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 IBM Corporation and others.
+ * Copyright (c) 2008, 2018 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -12,8 +12,6 @@ package org.eclipse.compare.tests;
import org.eclipse.compare.CompareConfiguration;
import org.eclipse.compare.contentmergeviewer.ContentMergeViewer;
-import org.eclipse.jface.util.IPropertyChangeListener;
-import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.widgets.Composite;
import org.junit.Assert;
@@ -99,12 +97,9 @@ public class ContentMergeViewerTest extends TestCase {
protected void setUp() throws Exception {
result = new boolean[] { false, false };
myContentMergeViewer = new MyContentMergeViewer();
- myContentMergeViewer.addPropertyChangeListener(new IPropertyChangeListener() {
- @Override
- public void propertyChange(PropertyChangeEvent event) {
- result[0] = true;
- result[1] = ((Boolean) event.getNewValue()).booleanValue();
- }
+ myContentMergeViewer.addPropertyChangeListener(event -> {
+ result[0] = true;
+ result[1] = ((Boolean) event.getNewValue()).booleanValue();
});
}
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/FileDiffResultTest.java b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/FileDiffResultTest.java
index 401bbd306..1396a4db2 100644
--- a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/FileDiffResultTest.java
+++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/FileDiffResultTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2009 IBM Corporation and others.
+ * Copyright (c) 2005, 2018 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -194,7 +194,7 @@ public class FileDiffResultTest extends WorkspaceTest {
FileDiffResult fileDiffResult = new FileDiffResult(myFileDiff,
patchConfiguration);
try {
- fileDiffResult.calculateFuzz(new ArrayList(), nullProgressMonitor);
+ fileDiffResult.calculateFuzz(new ArrayList<>(), nullProgressMonitor);
} catch (NullPointerException e) {
fail();
}
@@ -220,7 +220,7 @@ public class FileDiffResultTest extends WorkspaceTest {
protected MyFileDiff() {
super(null, 0, null, 0);
add(Hunk.createHunk(this, new int[] { 0, 0 }, new int[] { 0, 0 },
- new ArrayList(), false, false, false));
+ new ArrayList<>(), false, false, false));
}
}
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/LineReaderTest.java b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/LineReaderTest.java
index c7ee28a43..55756be6f 100644
--- a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/LineReaderTest.java
+++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/LineReaderTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2017 IBM Corporation and others.
+ * Copyright (c) 2005, 2018 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,32 +10,29 @@
*******************************************************************************/
package org.eclipse.compare.tests;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
+import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
-import junit.framework.TestCase;
-
import org.eclipse.compare.internal.core.patch.LineReader;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.junit.Assert;
+import junit.framework.TestCase;
+
public class LineReaderTest extends TestCase {
public void testReadEmpty() {
LineReader lr= new LineReader(getReader("empty.txt")); //$NON-NLS-1$
- List inLines= lr.readLines();
+ List<String> inLines= lr.readLines();
Assert.assertEquals(0, inLines.size());
}
public void testReadNormal() {
LineReader lr= new LineReader(getReader("normal.txt")); //$NON-NLS-1$
- List inLines= lr.readLines();
+ List<String> inLines= lr.readLines();
Assert.assertEquals(3, inLines.size());
Assert.assertEquals("[1]\n", convertLineDelimeters(inLines.get(0))); //$NON-NLS-1$
Assert.assertEquals("[2]\n", convertLineDelimeters(inLines.get(1))); //$NON-NLS-1$
@@ -51,7 +48,7 @@ public class LineReaderTest extends TestCase {
public void testReadUnterminatedLastLine() {
LineReader lr= new LineReader(getReader("unterminated.txt")); //$NON-NLS-1$
- List inLines= lr.readLines();
+ List<String> inLines= lr.readLines();
Assert.assertEquals(3, inLines.size());
Assert.assertEquals("[1]\n", convertLineDelimeters(inLines.get(0))); //$NON-NLS-1$
Assert.assertEquals("[2]\n", convertLineDelimeters(inLines.get(1))); //$NON-NLS-1$
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 08e9a317c..95d042c8b 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 IBM Corporation and others.
+ * Copyright (c) 2009, 2018 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -14,23 +14,16 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.List;
-import junit.framework.TestCase;
-
import org.eclipse.compare.internal.core.patch.Hunk;
import org.eclipse.compare.internal.core.patch.LineReader;
import org.eclipse.compare.internal.patch.Utilities;
-import org.eclipse.compare.patch.ApplyPatchOperation;
-import org.eclipse.compare.patch.IFilePatch;
-import org.eclipse.compare.patch.IFilePatch2;
-import org.eclipse.compare.patch.IFilePatchResult;
-import org.eclipse.compare.patch.IHunk;
-import org.eclipse.compare.patch.PatchBuilder;
-import org.eclipse.compare.patch.PatchConfiguration;
+import org.eclipse.compare.patch.*;
import org.eclipse.compare.tests.PatchUtils.StringStorage;
import org.eclipse.core.resources.IStorage;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.*;
+import org.junit.Assert;
+
+import junit.framework.TestCase;
public class PatchBuilderTest extends TestCase {
@@ -85,7 +78,7 @@ public class PatchBuilderTest extends TestCase {
LineReader lr = new LineReader(PatchUtils
.getReader("exp_modifyHunks.txt"));
- List inLines = lr.readLines();
+ List<String> inLines = lr.readLines();
String expected = LineReader.createString(false, inLines);
assertEquals(expected, PatchUtils.asString(actual));
@@ -135,7 +128,7 @@ public class PatchBuilderTest extends TestCase {
InputStream actual = result.getPatchedContents();
LineReader lr = new LineReader(PatchUtils.getReader("exp_addHunks.txt"));
- List inLines = lr.readLines();
+ List<String> inLines = lr.readLines();
String expected = LineReader.createString(false, inLines);
assertEquals(expected, PatchUtils.asString(actual));
@@ -172,7 +165,7 @@ public class PatchBuilderTest extends TestCase {
LineReader lr = new LineReader(PatchUtils
.getReader("exp_removeHunks.txt"));
- List inLines = lr.readLines();
+ List<String> inLines = lr.readLines();
String expected = LineReader.createString(false, inLines);
assertEquals(expected, PatchUtils.asString(actual));
@@ -209,7 +202,7 @@ public class PatchBuilderTest extends TestCase {
LineReader lr = new LineReader(PatchUtils
.getReader("exp_createFilePatch.txt"));
- List inLines = lr.readLines();
+ List<String> inLines = lr.readLines();
String expected = LineReader.createString(false, inLines);
assertEquals(expected, PatchUtils.asString(actual));
@@ -227,7 +220,7 @@ public class PatchBuilderTest extends TestCase {
Hunk hunk = (Hunk) PatchBuilder.createHunk(0, lines);
String[] actual = hunk.getUnifiedLines();
assertTrue(lines != actual);
- assertLinesEquals(lines, actual);
+ Assert.assertArrayEquals(lines, actual);
assertHunkEquals(hunk, (Hunk) filePatches[0].getHunks()[0]);
}
@@ -245,7 +238,7 @@ public class PatchBuilderTest extends TestCase {
Hunk hunk = (Hunk) PatchBuilder.createHunk(0, lines);
String[] actual = hunk.getUnifiedLines();
assertTrue(lines != actual);
- assertLinesEquals(lines, actual);
+ Assert.assertArrayEquals(lines, actual);
assertHunkEquals(hunk, (Hunk) filePatches[0].getHunks()[0]);
}
@@ -261,7 +254,7 @@ public class PatchBuilderTest extends TestCase {
Hunk hunk = (Hunk) PatchBuilder.createHunk(0, lines);
String[] actual = hunk.getUnifiedLines();
assertTrue(lines != actual);
- assertLinesEquals(lines, actual);
+ Assert.assertArrayEquals(lines, actual);
assertHunkEquals(hunk, (Hunk) filePatches[0].getHunks()[0]);
}
@@ -277,7 +270,7 @@ public class PatchBuilderTest extends TestCase {
Hunk hunk = (Hunk) PatchBuilder.createHunk(0, lines);
String[] actual = hunk.getUnifiedLines();
assertTrue(lines != actual);
- assertLinesEquals(lines, actual);
+ Assert.assertArrayEquals(lines, actual);
assertHunkEquals(hunk, (Hunk) filePatches[0].getHunks()[0]);
}
@@ -298,13 +291,6 @@ public class PatchBuilderTest extends TestCase {
assertEquals(h1.getHunkType(true), h2.getHunkType(true));
}
- private void assertLinesEquals(String[] expected, String[] actual) {
- assertEquals(expected.length, actual.length);
- for (int i = 0; i < expected.length; i++) {
- assertEquals(expected[i], actual[i]);
- }
- }
-
private void addLineDelimiters(String[] lines) {
for (int i = 0; i < lines.length; i++) {
lines[i] = lines[i] + "\r\n";
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 c1355d829..d388de207 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2018 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,54 +10,25 @@
*******************************************************************************/
package org.eclipse.compare.tests;
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileFilter;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.StringReader;
+import java.io.*;
import java.net.JarURLConnection;
import java.net.URL;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
+import java.util.*;
+import java.util.Map.Entry;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;
-import junit.framework.Assert;
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
-
-import org.eclipse.compare.internal.core.patch.FilePatch2;
-import org.eclipse.compare.internal.core.patch.FileDiffResult;
-import org.eclipse.compare.internal.core.patch.LineReader;
+import org.eclipse.compare.internal.core.patch.*;
import org.eclipse.compare.internal.patch.WorkspacePatcher;
-import org.eclipse.compare.patch.ApplyPatchOperation;
-import org.eclipse.compare.patch.IFilePatch;
-import org.eclipse.compare.patch.IFilePatchResult;
-import org.eclipse.compare.patch.IHunk;
-import org.eclipse.compare.patch.IHunkFilter;
-import org.eclipse.compare.patch.PatchConfiguration;
-import org.eclipse.compare.tests.PatchUtils.JarEntryStorage;
-import org.eclipse.compare.tests.PatchUtils.PatchTestConfiguration;
-import org.eclipse.compare.tests.PatchUtils.StringStorage;
+import org.eclipse.compare.patch.*;
+import org.eclipse.compare.tests.PatchUtils.*;
import org.eclipse.core.resources.IStorage;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.*;
+import org.junit.Assert;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.TestCase;
public class PatchTest extends TestCase {
@@ -111,11 +82,7 @@ public class PatchTest extends TestCase {
assertEquals(5, hunks.length);
PatchConfiguration pc = new PatchConfiguration();
final IHunk toFilterOut = hunks[3];
- pc.addHunkFilter(new IHunkFilter() {
- public boolean select(IHunk hunk) {
- return hunk != toFilterOut;
- }
- });
+ pc.addHunkFilter(hunk -> hunk != toFilterOut);
IFilePatchResult result = patches[0].apply(expStorage, pc,
new NullProgressMonitor());
IHunk[] rejects = result.getRejects();
@@ -127,7 +94,7 @@ public class PatchTest extends TestCase {
InputStream actual = result.getPatchedContents();
LineReader lr = new LineReader(PatchUtils.getReader("exp_hunkFilter.txt"));
- List inLines = lr.readLines();
+ List<String> inLines = lr.readLines();
String expected = LineReader.createString(false, inLines);
assertEquals(expected, PatchUtils.asString(actual));
@@ -139,8 +106,8 @@ public class PatchTest extends TestCase {
IFilePatch[] patches = ApplyPatchOperation.parsePatch(patchStorage);
String header = patches[0].getHeader();
LineReader reader = new LineReader(new BufferedReader(new InputStreamReader(new ByteArrayInputStream(header.getBytes()))));
- List lines = reader.readLines();
- List expected = new ArrayList();
+ List<String> lines = reader.readLines();
+ List<String> expected = new ArrayList<>();
expected.add("Index: old.txt\n");
expected.add("UID: 42\n");
assertEquals(LineReader.createString(false, expected), LineReader.createString(false, lines));
@@ -204,14 +171,14 @@ public class PatchTest extends TestCase {
}
// Keeps track of the failures
- private List failures = new ArrayList();
+ private List<AssertionError> failures = new ArrayList<>();
public void testPatchdataSubfolders() throws IOException, CoreException {
URL patchdataUrl = new URL(PatchUtils.getBundle().getEntry("/"),
new Path(PatchUtils.PATCHDATA).toString());
patchdataUrl = FileLocator.resolve(patchdataUrl);
- Map map = null;
+ Map<String, PatchTestConfiguration> map = null;
if (patchdataUrl.getProtocol().equals("file")) {
map = extractNamesForFileProtocol(patchdataUrl);
} else if (patchdataUrl.getProtocol().equals("jar")) {
@@ -221,9 +188,9 @@ public class PatchTest extends TestCase {
}
assertNotNull(map);
- for (Iterator iterator = map.keySet().iterator(); iterator.hasNext();) {
- String sf = (String) iterator.next(); // subfolder
- PatchTestConfiguration ptc = (PatchTestConfiguration) map.get(sf);
+ for (Entry<String, PatchTestConfiguration> entry : map.entrySet()) {
+ String sf = entry.getKey(); // subfolder
+ PatchTestConfiguration ptc = entry.getValue();
String[] originalFiles = ptc.originalFileNames;
String patch = ptc.patchFileName;
String[] expectedFiles = ptc.expectedFileNames;
@@ -237,7 +204,7 @@ public class PatchTest extends TestCase {
try {
// test with expected result
patchWorkspace(msg, originalFiles, patch, expectedFiles, pc);
- } catch (AssertionFailedError e) {
+ } catch (AssertionError e) {
failures.add(e);
}
@@ -245,11 +212,11 @@ public class PatchTest extends TestCase {
if (actualFiles != null) {
try {
patchWorkspace(msg, originalFiles, patch, actualFiles, pc);
- } catch (AssertionFailedError e) {
+ } catch (AssertionError e) {
// a failure is expected
continue; // continue with a next subfolder
}
- failures.add(new AssertionFailedError(
+ failures.add(new AssertionError(
"\npatchWorkspace should fail for folder ["
+ PatchUtils.PATCHDATA + "/" + sf + "]."));
}
@@ -259,12 +226,11 @@ public class PatchTest extends TestCase {
return;
if (failures.size() == 1)
- throw (AssertionFailedError) failures.get(0);
+ throw failures.get(0);
- StringBuffer sb = new StringBuffer(
+ StringBuilder sb = new StringBuilder(
"Failures occured while testing data from patchdata subfolder (Please check log for further details):");
- for (Iterator iterator = failures.iterator(); iterator.hasNext();) {
- AssertionFailedError error = (AssertionFailedError) iterator.next();
+ for (AssertionError error : failures) {
log("org.eclipse.compare.tests", error);
sb.append("\n" + error.getMessage());
}
@@ -292,15 +258,15 @@ public class PatchTest extends TestCase {
* @throws IOException
* @throws CoreException
*/
- private Map extractNamesForJarProtocol(URL patchdataUrl) throws IOException,
+ private Map<String, PatchTestConfiguration> extractNamesForJarProtocol(URL patchdataUrl) throws IOException,
CoreException {
JarFile jarFile = ((JarURLConnection) patchdataUrl.openConnection()).getJarFile();
// look for the patchdata folder entry
String patchdataName = null;
- Enumeration entries = jarFile.entries();
+ Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
- JarEntry entry = (JarEntry) entries.nextElement();
+ JarEntry entry = entries.nextElement();
String entryName = entry.getName();
if (entryName.endsWith("/" + PatchUtils.PATCHDATA + "/")) {
patchdataName = entryName;
@@ -311,10 +277,10 @@ public class PatchTest extends TestCase {
if (patchdataName == null)
return null;
- Map result = new HashMap();
+ Map<String, PatchTestConfiguration> result = new HashMap<>();
entries = jarFile.entries();
while (entries.hasMoreElements()) {
- JarEntry entry = (JarEntry) entries.nextElement();
+ JarEntry entry = entries.nextElement();
String entryName = entry.getName();
if (entry.isDirectory()) {
if (!entryName.equals(patchdataName) && entryName.startsWith(patchdataName)) {
@@ -338,22 +304,17 @@ public class PatchTest extends TestCase {
return result;
}
- private Map extractNamesForFileProtocol(URL patchdataUrl)
+ private Map<String, PatchTestConfiguration> extractNamesForFileProtocol(URL patchdataUrl)
throws CoreException {
- Map result = new HashMap(); // configuration map
+ 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(new FileFilter() {
- public boolean accept(File pathname) {
- return pathname.isDirectory();
- }
- });
- for (int i = 0; i < listOfSubfolders.length; i++) {
- File subfolder = listOfSubfolders[i];
+ .listFiles((FileFilter) pathname -> pathname.isDirectory());
+ for (File subfolder : listOfSubfolders) {
Path pcPath = new Path(subfolder.getPath() + "/" + PATCH_CONFIGURATION);
File pcFile = pcPath.toFile();
@@ -375,7 +336,7 @@ public class PatchTest extends TestCase {
return result;
}
- private void processProperties(Map result, Properties p, String subfolderName) {
+ private void processProperties(Map<String, PatchTestConfiguration> result, Properties p, String subfolderName) {
boolean skipTest = Boolean.valueOf(p.getProperty("skipTest", "false")).booleanValue();
if (skipTest)
return;
@@ -430,7 +391,7 @@ 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 inLines= lr.readLines();
+ List<String> inLines= lr.readLines();
String expected = LineReader.createString(false, inLines);
IStorage oldStorage = new StringStorage(old);
@@ -447,7 +408,7 @@ public class PatchTest extends TestCase {
private void patcherPatch(String old, String patch, String expt) {
LineReader lr= new LineReader(PatchUtils.getReader(old));
- List inLines= lr.readLines();
+ List<String> inLines= lr.readLines();
WorkspacePatcher patcher= new WorkspacePatcher();
try {
@@ -463,15 +424,9 @@ public class PatchTest extends TestCase {
diffResult.patch(inLines, null);
LineReader expectedContents= new LineReader(PatchUtils.getReader(expt));
- List expectedLines= expectedContents.readLines();
-
- Object[] expected= expectedLines.toArray();
- Object[] result= inLines.toArray();
+ List<String> expectedLines= expectedContents.readLines();
- Assert.assertEquals(expected.length, result.length);
-
- for (int i= 0; i < expected.length; i++)
- Assert.assertEquals(expected[i], result[i]);
+ Assert.assertArrayEquals(expectedLines.toArray(), inLines.toArray());
}
private void patchWorkspace(String[] originalFiles, String patch,
@@ -519,13 +474,13 @@ public class PatchTest extends TestCase {
//with the corresponding outcome file
for (int i = 0; i < originalFiles.length; i++) {
LineReader lr= new LineReader(PatchUtils.getReader(originalFiles[i]));
- List inLines= lr.readLines();
+ List<String> inLines= lr.readLines();
FileDiffResult diffResult = patcher.getDiffResult(diffs[i]);
diffResult.patch(inLines, null);
LineReader expectedContents= new LineReader(PatchUtils.getReader(expectedOutcomeFiles[i]));
- List expectedLines= expectedContents.readLines();
+ List<String> expectedLines= expectedContents.readLines();
Object[] expected= expectedLines.toArray();
@@ -533,11 +488,7 @@ public class PatchTest extends TestCase {
LineReader resultReader = new LineReader(new BufferedReader(new StringReader(resultString)));
Object[] result = resultReader.readLines().toArray();
- Assert.assertEquals(msg, expected.length, result.length);
-
- for (int j= 0; j < expected.length; j++)
- Assert.assertEquals(msg, expected[j], result[j]);
+ Assert.assertArrayEquals(msg, expected, result);
}
}
-
}
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 7f6625ed1..021a6e2dd 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2018 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -14,38 +14,25 @@ import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
-import junit.framework.TestCase;
-
import org.eclipse.compare.CompareConfiguration;
import org.eclipse.compare.internal.CompareUIPlugin;
-import org.eclipse.compare.internal.patch.PatchMessages;
-import org.eclipse.compare.internal.patch.PatchWizard;
-import org.eclipse.compare.internal.patch.PatchWizardDialog;
+import org.eclipse.compare.internal.patch.*;
import org.eclipse.core.internal.resources.WorkspaceRoot;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IStorage;
-import org.eclipse.core.resources.IWorkspaceRoot;
-import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.resources.*;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.viewers.TreePath;
-import org.eclipse.jface.viewers.TreeSelection;
-import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.*;
import org.eclipse.jface.wizard.IWizardPage;
-import org.eclipse.swt.dnd.Clipboard;
-import org.eclipse.swt.dnd.TextTransfer;
-import org.eclipse.swt.dnd.Transfer;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.dnd.*;
+import org.eclipse.swt.widgets.*;
import org.eclipse.ui.PlatformUI;
import org.osgi.service.prefs.BackingStoreException;
import org.osgi.service.prefs.Preferences;
+import junit.framework.TestCase;
+
public class PatchUITest extends TestCase {
private static final String TEST_PROJECT = "ApplyPatchTest";
@@ -89,7 +76,7 @@ public class PatchUITest extends TestCase {
assertTrue(patchWizardPage.canFlipToNextPage());
- callMethod(wizardDialog, "nextPressed", new Object[] {});
+ callMethod(wizardDialog, "nextPressed");
processQueuedEvents();
assertTrue(wizard.canFinish());
@@ -117,7 +104,7 @@ public class PatchUITest extends TestCase {
processQueuedEvents();
assertTrue(patchWizardPage.canFlipToNextPage());
- callMethod(wizardDialog, "nextPressed", new Object[] {});
+ callMethod(wizardDialog, "nextPressed");
assertTrue(wizard.canFinish());
wizard.performFinish();
@@ -149,7 +136,7 @@ public class PatchUITest extends TestCase {
assertTrue(patchWizardPage.canFlipToNextPage());
- callMethod(wizardDialog, "nextPressed", new Object[] {});
+ callMethod(wizardDialog, "nextPressed");
processQueuedEvents();
assertTrue(wizard.canFinish());
@@ -286,7 +273,7 @@ public class PatchUITest extends TestCase {
return ret;
}
- private Object callMethod(Object object, String name, Object args[]) {
+ private Object callMethod(Object object, String name, Object... args) {
Object ret = null;
try {
ret = ReflectionUtils.callMethod(object, name, args);
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/ReflectionUtils.java b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/ReflectionUtils.java
index 87d5980b1..467092a11 100644
--- a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/ReflectionUtils.java
+++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/ReflectionUtils.java
@@ -10,13 +10,11 @@
*******************************************************************************/
package org.eclipse.compare.tests;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
+import java.lang.reflect.*;
public class ReflectionUtils {
- public static Object callMethod(Object object, String name, Object args[])
+ public static Object callMethod(Object object, String name, Object... args)
throws IllegalArgumentException, IllegalAccessException,
InvocationTargetException, NoSuchMethodException {
Class<?> types[] = new Class[args.length];
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/TextMergeViewerTest.java b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/TextMergeViewerTest.java
index 0779899d1..b62ff25cf 100644
--- a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/TextMergeViewerTest.java
+++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/TextMergeViewerTest.java
@@ -251,11 +251,9 @@ public class TextMergeViewerTest extends TestCase {
DiffNode parentNode = new DiffNode(new ParentTestElement(), new ParentTestElement());
String copiedText = "hi there";
DiffNode testNode = new DiffNode(parentNode, Differencer.CHANGE, null, new EditableTestElement("some text".getBytes()), new EditableTestElement(copiedText.getBytes()));
- runInDialog(testNode, new Runnable() {
- public void run() {
- viewer.copy(false /* rightToLeft */);
- saveViewerContents();
- }
+ runInDialog(testNode, () -> {
+ viewer.copy(false /* rightToLeft */);
+ saveViewerContents();
});
assertEquals(copiedText, ((EditableTestElement)testNode.getLeft()).getContentsAsString());
}
@@ -264,11 +262,9 @@ public class TextMergeViewerTest extends TestCase {
DiffNode parentNode = new DiffNode(new ParentTestElement(), new ParentTestElement());
String copiedText = "hi there";
DiffNode testNode = new DiffNode(parentNode, Differencer.CHANGE, null, new EditableTestElement(copiedText.getBytes()), new EditableTestElement("some text".getBytes()));
- runInDialog(testNode, new Runnable() {
- public void run() {
- viewer.copy(true /* leftToRight */);
- saveViewerContents();
- }
+ runInDialog(testNode, () -> {
+ viewer.copy(true /* leftToRight */);
+ saveViewerContents();
});
assertEquals(copiedText, ((EditableTestElement)testNode.getRight()).getContentsAsString());
}
@@ -276,11 +272,9 @@ public class TextMergeViewerTest extends TestCase {
public void testCopyRightToEmptyLeft() throws Exception {
DiffNode parentNode = new DiffNode(new ParentTestElement(), new ParentTestElement());
DiffNode testNode = new DiffNode(parentNode, Differencer.ADDITION, null, null, new EditableTestElement("hi there".getBytes()));
- runInDialog(testNode, new Runnable() {
- public void run() {
- viewer.copy(false /* rightToLeft */);
- saveViewerContents();
- }
+ runInDialog(testNode, () -> {
+ viewer.copy(false /* rightToLeft */);
+ saveViewerContents();
});
assertEquals(testNode.getRight(), testNode.getLeft());
}
@@ -288,11 +282,9 @@ public class TextMergeViewerTest extends TestCase {
public void testCopyLeftToEmptyRight() throws Exception {
DiffNode parentNode = new DiffNode(new ParentTestElement(), new ParentTestElement());
DiffNode testNode = new DiffNode(parentNode, Differencer.DELETION, null, new EditableTestElement("hi there".getBytes()), null);
- runInDialog(testNode, new Runnable() {
- public void run() {
- viewer.copy(true /* leftToRight */);
- saveViewerContents();
- }
+ runInDialog(testNode, () -> {
+ viewer.copy(true /* leftToRight */);
+ saveViewerContents();
});
assertEquals(testNode.getRight(), testNode.getLeft());
}
@@ -300,11 +292,9 @@ public class TextMergeViewerTest extends TestCase {
public void testCopyEmptyLeftToRight() throws Exception {
DiffNode parentNode = new DiffNode(new ParentTestElement(), new ParentTestElement());
DiffNode testNode = new DiffNode(parentNode, Differencer.ADDITION, null, null, new EditableTestElement("hi there".getBytes()));
- runInDialog(testNode, new Runnable() {
- public void run() {
- viewer.copy(true /* leftToRight */);
- saveViewerContents();
- }
+ runInDialog(testNode, () -> {
+ viewer.copy(true /* leftToRight */);
+ saveViewerContents();
});
assertNull(testNode.getLeft());
assertNull(testNode.getRight());
@@ -313,11 +303,9 @@ public class TextMergeViewerTest extends TestCase {
public void testCopyEmptyRightToLeft() throws Exception {
DiffNode parentNode = new DiffNode(new ParentTestElement(), new ParentTestElement());
DiffNode testNode = new DiffNode(parentNode, Differencer.DELETION, null, new EditableTestElement("hi there".getBytes()), null);
- runInDialog(testNode, new Runnable() {
- public void run() {
- viewer.copy(false /* rightToLeft */);
- saveViewerContents();
- }
+ runInDialog(testNode, () -> {
+ viewer.copy(false /* rightToLeft */);
+ saveViewerContents();
});
assertNull(testNode.getLeft());
assertNull(testNode.getRight());
@@ -326,12 +314,10 @@ public class TextMergeViewerTest extends TestCase {
public void testModifyLeft() throws Exception {
DiffNode testNode = new DiffNode(new EditableTestElement("hi there".getBytes()), null);
final String newText = "New text";
- runInDialog(testNode, new Runnable() {
- public void run() {
- IDocument doc = getDocument(true /* left */);
- doc.set(newText);
- saveViewerContents();
- }
+ runInDialog(testNode, () -> {
+ IDocument doc = getDocument(true /* left */);
+ doc.set(newText);
+ saveViewerContents();
});
assertEquals(newText, ((EditableTestElement)testNode.getLeft()).getContentsAsString());
}
@@ -339,12 +325,10 @@ public class TextMergeViewerTest extends TestCase {
public void testModifyRight() throws Exception {
DiffNode testNode = new DiffNode(null, new EditableTestElement("hi there".getBytes()));
final String newText = "New text";
- runInDialog(testNode, new Runnable() {
- public void run() {
- IDocument doc = getDocument(false /* right */);
- doc.set(newText);
- saveViewerContents();
- }
+ runInDialog(testNode, () -> {
+ IDocument doc = getDocument(false /* right */);
+ doc.set(newText);
+ saveViewerContents();
});
assertEquals(newText, ((EditableTestElement)testNode.getRight()).getContentsAsString());
}
@@ -353,13 +337,11 @@ public class TextMergeViewerTest extends TestCase {
DiffNode parentNode = new DiffNode(new ParentTestElement(), new ParentTestElement());
DiffNode testNode = new DiffNode(parentNode, Differencer.ADDITION, null, null, new EditableTestElement("hi there".getBytes()));
final String newText = "New text";
- runInDialog(testNode, new Runnable() {
- public void run() {
- viewer.copy(false /* rightToLeft */);
- IDocument doc = getDocument(true /* left */);
- doc.set(newText);
- saveViewerContents();
- }
+ runInDialog(testNode, () -> {
+ viewer.copy(false /* rightToLeft */);
+ IDocument doc = getDocument(true /* left */);
+ doc.set(newText);
+ saveViewerContents();
});
assertEquals(newText, ((EditableTestElement)testNode.getLeft()).getContentsAsString());
}
@@ -368,13 +350,11 @@ public class TextMergeViewerTest extends TestCase {
DiffNode parentNode = new DiffNode(new ParentTestElement(), new ParentTestElement());
DiffNode testNode = new DiffNode(parentNode, Differencer.DELETION, null, new EditableTestElement("hi there".getBytes()), null);
final String newText = "New text";
- runInDialog(testNode, new Runnable() {
- public void run() {
- viewer.copy(true /* leftToRight */);
- IDocument doc = getDocument(false /* right */);
- doc.set(newText);
- saveViewerContents();
- }
+ runInDialog(testNode, () -> {
+ viewer.copy(true /* leftToRight */);
+ IDocument doc = getDocument(false /* right */);
+ doc.set(newText);
+ saveViewerContents();
});
assertEquals(newText, ((EditableTestElement)testNode.getRight()).getContentsAsString());
}
@@ -392,70 +372,68 @@ public class TextMergeViewerTest extends TestCase {
DiffNode testNode = new DiffNode(parentNode, Differencer.CHANGE, null,
leftElement, rightElement);
final CompareConfiguration cc = new CompareConfiguration();
- runInDialog(testNode, new Runnable() {
- public void run() {
- Object adapter = viewer
- .getAdapter(IMergeViewerTestAdapter.class);
- if (adapter instanceof IMergeViewerTestAdapter) {
- IMergeViewerTestAdapter ta = (IMergeViewerTestAdapter) adapter;
- assertEquals(ta.getChangesCount(), 1);
-
- Map<String, ICompareFilter> filters = new HashMap<>();
- filters.put("filter.id", new ICompareFilter() {
- public void setInput(Object input, Object ancestor,
- Object left, Object right) {
- assertTrue(leftElement == left);
- assertTrue(rightElement == right);
+ runInDialog(testNode, () -> {
+ Object adapter = viewer
+ .getAdapter(IMergeViewerTestAdapter.class);
+ if (adapter instanceof IMergeViewerTestAdapter) {
+ IMergeViewerTestAdapter ta = (IMergeViewerTestAdapter) adapter;
+ assertEquals(ta.getChangesCount(), 1);
+
+ Map<String, ICompareFilter> filters = new HashMap<>();
+ filters.put("filter.id", new ICompareFilter() {
+ public void setInput(Object input, Object ancestor,
+ Object left, Object right) {
+ assertTrue(leftElement == left);
+ assertTrue(rightElement == right);
+ }
+
+ public IRegion[] getFilteredRegions(
+ HashMap lineComparison) {
+ Object thisLine = lineComparison.get(THIS_LINE);
+ Object thisContributor = lineComparison
+ .get(THIS_CONTRIBUTOR);
+ Object otherLine = lineComparison.get(OTHER_LINE);
+ Object otherContributor = lineComparison
+ .get(OTHER_CONTRIBUTOR);
+
+ if (thisContributor.equals(Character.valueOf('L'))) {
+ assertEquals(thisLine, leftString);
+ assertEquals(otherContributor, Character.valueOf('R'));
+ assertEquals(otherLine, rightString);
+ } else {
+ assertEquals(thisContributor,
+ Character.valueOf('R'));
+ assertEquals(thisLine, rightString);
+ assertEquals(otherContributor, Character.valueOf('L'));
+ assertEquals(otherLine, leftString);
}
- public IRegion[] getFilteredRegions(
- HashMap lineComparison) {
- Object thisLine = lineComparison.get(THIS_LINE);
- Object thisContributor = lineComparison
- .get(THIS_CONTRIBUTOR);
- Object otherLine = lineComparison.get(OTHER_LINE);
- Object otherContributor = lineComparison
- .get(OTHER_CONTRIBUTOR);
-
- if (thisContributor.equals(Character.valueOf('L'))) {
- assertEquals(thisLine, leftString);
- assertEquals(otherContributor, Character.valueOf('R'));
- assertEquals(otherLine, rightString);
- } else {
- assertEquals(thisContributor,
- Character.valueOf('R'));
- assertEquals(thisLine, rightString);
- assertEquals(otherContributor, Character.valueOf('L'));
- assertEquals(otherLine, leftString);
- }
-
- if (thisContributor.equals(Character.valueOf('L')))
- return new IRegion[] { new Region(0, 1),
- new Region(1, 1) };
-
- return new IRegion[] { new Region(0, 2) };
- }
+ if (thisContributor.equals(Character.valueOf('L')))
+ return new IRegion[] { new Region(0, 1),
+ new Region(1, 1) };
- public boolean isEnabledInitially() {
- return false;
- }
+ return new IRegion[] { new Region(0, 2) };
+ }
- public boolean canCacheFilteredRegions() {
- return true;
- }
+ public boolean isEnabledInitially() {
+ return false;
+ }
- });
+ public boolean canCacheFilteredRegions() {
+ return true;
+ }
- cc.setProperty(
- ChangeCompareFilterPropertyAction.COMPARE_FILTERS,
- filters);
- assertEquals(ta.getChangesCount(), 0);
+ });
- cc.setProperty(
- ChangeCompareFilterPropertyAction.COMPARE_FILTERS,
- null);
- assertEquals(ta.getChangesCount(), 1);
- }
+ cc.setProperty(
+ ChangeCompareFilterPropertyAction.COMPARE_FILTERS,
+ filters);
+ assertEquals(ta.getChangesCount(), 0);
+
+ cc.setProperty(
+ ChangeCompareFilterPropertyAction.COMPARE_FILTERS,
+ null);
+ assertEquals(ta.getChangesCount(), 1);
}
}, cc);
}
@@ -480,10 +458,8 @@ public class TextMergeViewerTest extends TestCase {
DocumentAsTypedElement leftDoc = new DocumentAsTypedElement();
DocumentAsTypedElement rightDoc = new DocumentAsTypedElement();
DiffNode testNode = new DiffNode(parentNode, Differencer.DELETION, null, leftDoc, rightDoc);
- runInDialogWithPartioner(testNode, new Runnable() {
- public void run() {
- //Not needed
- }
+ runInDialogWithPartioner(testNode, () -> {
+ //Not needed
}, new CompareConfiguration());
assertNotNull(leftDoc.getDocumentPartitioner());
assertNotNull(rightDoc.getDocumentPartitioner());
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/WorkspaceTest.java b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/WorkspaceTest.java
index 2531f5416..cce2a0f95 100644
--- a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/WorkspaceTest.java
+++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/WorkspaceTest.java
@@ -10,28 +10,16 @@
*******************************************************************************/
package org.eclipse.compare.tests;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
+import java.io.*;
+import java.util.*;
+
+import org.eclipse.core.resources.*;
+import org.eclipse.core.runtime.*;
+import org.eclipse.core.tests.resources.ResourceTest;
import junit.framework.Test;
import junit.framework.TestSuite;
-import org.eclipse.core.resources.IContainer;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.tests.resources.ResourceTest;
-
public class WorkspaceTest extends ResourceTest {
protected static IProgressMonitor DEFAULT_MONITOR = new NullProgressMonitor();
protected static final IProgressMonitor DEFAULT_PROGRESS_MONITOR = new NullProgressMonitor();
@@ -102,11 +90,11 @@ public class WorkspaceTest extends ResourceTest {
* @throws CoreException
*/
public IResource[] buildResources(IContainer container, String[] hierarchy, boolean includeContainer) throws CoreException {
- List resources = new ArrayList(hierarchy.length + 1);
+ List<IResource> resources = new ArrayList<>(hierarchy.length + 1);
if (includeContainer)
resources.add(container);
resources.addAll(Arrays.asList(buildResources(container, hierarchy)));
- IResource[] result = (IResource[]) resources.toArray(new IResource[resources.size()]);
+ IResource[] result = resources.toArray(new IResource[resources.size()]);
ensureExistsInWorkspace(result, true);
for (int i = 0; i < result.length; i++) {
if (result[i].getType() == IResource.FILE) // 3786 bytes is the average size of Eclipse Java files!
@@ -115,11 +103,11 @@ public class WorkspaceTest extends ResourceTest {
return result;
}
public IResource[] buildEmptyResources(IContainer container, String[] hierarchy, boolean includeContainer) throws CoreException {
- List resources = new ArrayList(hierarchy.length + 1);
+ List<IResource> resources = new ArrayList<>(hierarchy.length + 1);
resources.addAll(Arrays.asList(buildResources(container, hierarchy)));
if (includeContainer)
resources.add(container);
- IResource[] result = (IResource[]) resources.toArray(new IResource[resources.size()]);
+ IResource[] result = resources.toArray(new IResource[resources.size()]);
ensureExistsInWorkspace(result, true);
return result;
}
@@ -212,15 +200,15 @@ public class WorkspaceTest extends ResourceTest {
// Assert that the two containers have equal contents
protected void assertEquals(IContainer container1, IContainer container2) throws CoreException {
assertEquals(container1.getName(), container2.getName());
- List members1 = new ArrayList();
+ List<IResource> members1 = new ArrayList<>();
members1.addAll(Arrays.asList(container1.members()));
- List members2 = new ArrayList();
+ List<IResource> members2 = new ArrayList<>();
members2.addAll(Arrays.asList(container2.members()));
assertTrue(members1.size() == members2.size());
for (int i=0;i<members1.size();i++) {
- IResource member1 = (IResource)members1.get(i);
+ IResource member1 = members1.get(i);
IResource member2 = container2.findMember(member1.getName());
assertNotNull(member2);
assertEquals(member1, member2);
@@ -236,17 +224,17 @@ public class WorkspaceTest extends ResourceTest {
// Assert that the two projects have equal contents ignoreing the project name
// and the .vcm_meta file
protected void assertEquals(IProject container1, IProject container2) throws CoreException {
- List members1 = new ArrayList();
+ List<IResource> members1 = new ArrayList<>();
members1.addAll(Arrays.asList(container1.members()));
members1.remove(container1.findMember(".project"));
- List members2 = new ArrayList();
+ List<IResource> members2 = new ArrayList<>();
members2.addAll(Arrays.asList(container2.members()));
members2.remove(container2.findMember(".project"));
assertTrue("Number of children differs for " + container1.getFullPath(), members1.size() == members2.size());
for (int i=0;i<members1.size();i++) {
- IResource member1 = (IResource)members1.get(i);
+ IResource member1 = members1.get(i);
IResource member2 = container2.findMember(member1.getName());
assertNotNull(member2);
assertEquals(member1, member2);

Back to the top