Skip to content

Commit

Permalink
Migrate org.eclipse.compare.tests to JUnit 5 eclipse-platform#903
Browse files Browse the repository at this point in the history
Migrates the tests in org.eclipse.compare.tests to JUnit 5. This
consists of a replacement of the according annotations, migration of
assertions, and the replacement of the JUnit 4 WorkspaceTestRule with
the JUnit 5 WorkspaceResetExtension. The org.junit dependency is removed
from the test bundle.

Contributes to
eclipse-platform#903
  • Loading branch information
HeikoKlare committed Jul 18, 2024
1 parent e0be5f5 commit 699a7f6
Show file tree
Hide file tree
Showing 21 changed files with 63 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ Export-Package: org.eclipse.core.tests.filesystem,
org.eclipse.core.tests.resources.refresh,
org.eclipse.core.tests.resources.regression,
org.eclipse.core.tests.resources.session,
org.eclipse.core.tests.resources.usecase
org.eclipse.core.tests.resources.usecase,
org.eclipse.core.tests.resources.util
Require-Bundle: org.eclipse.core.resources,
org.eclipse.core.tests.harness,
org.junit,
Expand Down
4 changes: 2 additions & 2 deletions team/tests/org.eclipse.compare.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.compare.tests;singleton:=true
Bundle-Version: 3.8.400.qualifier
Require-Bundle: org.junit,
org.eclipse.compare,
Require-Bundle: org.eclipse.compare,
org.eclipse.jface.text,
org.eclipse.jface,
org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)",
Expand All @@ -18,6 +17,7 @@ Require-Bundle: org.junit,
Import-Package: org.assertj.core.api,
org.assertj.core.api.iterable,
org.junit.jupiter.api,
org.junit.jupiter.api.extension,
org.junit.platform.suite.api
Bundle-Activator: org.eclipse.compare.tests.CompareTestPlugin
Bundle-ActivationPolicy: lazy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@
*******************************************************************************/
package org.eclipse.compare.tests;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.Suite;

/**
* Test some non-UI areas of the compare plug-in.
*/

@RunWith(Suite.class)
@SuppressWarnings("deprecation")
@SuiteClasses({
@Suite
@SelectClasses({
TextMergeViewerTest.class,
LineReaderTest.class,
StreamMergerTest.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
package org.eclipse.compare.tests;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -27,7 +27,7 @@
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class AsyncExecTests {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.eclipse.swt.graphics.Image;
import org.eclipse.team.internal.ui.history.CompareFileRevisionEditorInput;
import org.eclipse.ui.IWorkbenchPage;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class CompareFileRevisionEditorInputTest {
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.eclipse.compare.structuremergeviewer.DiffNode;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.swt.graphics.Image;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class CompareUIPluginTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
*******************************************************************************/
package org.eclipse.compare.tests;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.eclipse.compare.CompareConfiguration;
import org.eclipse.compare.contentmergeviewer.ContentMergeViewer;
import org.eclipse.swt.widgets.Composite;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class ContentMergeViewerTest {
private MyContentMergeViewer myContentMergeViewer;
Expand Down Expand Up @@ -91,7 +91,7 @@ protected void updateContent(Object ancestor, Object left, Object right) {
}
}

@Before
@BeforeEach
public void setUp() {
result = new boolean[] { false, false };
myContentMergeViewer = new MyContentMergeViewer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class DiffTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
package org.eclipse.compare.tests;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.HashMap;
import java.util.Optional;
Expand All @@ -27,7 +27,7 @@
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.Region;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class DocLineComparatorTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,13 @@
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.tests.resources.WorkspaceTestRule;
import org.junit.Rule;
import org.junit.Test;
import org.eclipse.core.tests.resources.util.WorkspaceResetExtension;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

@ExtendWith(WorkspaceResetExtension.class)
public class FileDiffResultTest {

@Rule
public WorkspaceTestRule workspaceRule = new WorkspaceTestRule();

private static final String PATCH_FILE = "patchfile";

private static final String NEW_FILENAME = "newfile";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import static org.assertj.core.api.Assertions.assertThat;

import org.eclipse.compare.internal.CompareResourceFilter;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class FilterTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import org.eclipse.compare.internal.core.patch.LineReader;
import org.eclipse.core.runtime.IPath;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class LineReaderTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package org.eclipse.compare.tests;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertArrayEquals;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -35,7 +34,7 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class PatchBuilderTest {
@Test
Expand Down Expand Up @@ -273,7 +272,7 @@ public void testCreateHunk3() throws CoreException, IOException {
public void testReadNotValidPatch() throws CoreException, IOException {
IStorage patch = new StringStorage("not_a_patch.txt");
IFilePatch[] filePatches = ApplyPatchOperation.parsePatch(patch);
assertArrayEquals(new IFilePatch[0], filePatches);
assertThat(filePatches).isEmpty();
}

private void assertHunkEquals(Hunk h1, Hunk h2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*******************************************************************************/
package org.eclipse.compare.tests;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.BufferedReader;
import java.io.IOException;
Expand All @@ -22,7 +22,7 @@
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;
import org.junit.jupiter.api.Test;

public class PatchLinesTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
package org.eclipse.compare.tests;

import static org.assertj.core.api.Assertions.assertThat;
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 static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
Expand Down Expand Up @@ -57,15 +57,9 @@
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.junit.Test;

import junit.framework.AssertionFailedError;
import org.junit.jupiter.api.Test;

public class PatchTest {

Expand Down Expand Up @@ -297,27 +291,13 @@ public void testPatchdataSubfolders() throws IOException, CoreException {
}
}

if (failures.isEmpty())
return;

if (failures.size() == 1)
if (failures.size() == 1) {
throw failures.get(0);

StringBuilder sb = new StringBuilder(
"Failures occured while testing data from patchdata subfolder (Please check log for further details):");
for (AssertionError error : failures) {
log("org.eclipse.compare.tests", error);
sb.append("\n" + error.getMessage());
} else if (failures.size() > 1) {
AssertionError aggregatedFailure = new AssertionError("Failures occured while testing data from patchdata subfolder");
failures.forEach(failure -> aggregatedFailure.addSuppressed(failure));
throw aggregatedFailure;
}
throw new AssertionFailedError(sb.toString());
}

private void log(String pluginID, IStatus status) {
ILog.of(Platform.getBundle(pluginID)).log(status);
}

private void log(String pluginID, Throwable e) {
log(pluginID, new Status(IStatus.ERROR, pluginID, IStatus.ERROR, "Error", e)); //$NON-NLS-1$
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
package org.eclipse.compare.tests;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -46,9 +46,9 @@
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.osgi.service.prefs.BackingStoreException;
import org.osgi.service.prefs.Preferences;

Expand All @@ -62,15 +62,15 @@ public class PatchUITest {
private PatchWizardDialog wizardDialog = null;
private PatchWizard wizard = null;

@Before
@BeforeEach
public void setUp() throws Exception {
workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
testProject = workspaceRoot.getProject(TEST_PROJECT);
testProject.create(null);
testProject.open(null);
}

@After
@AfterEach
public void tearDown() throws Exception {
testProject.delete(true, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.eclipse.compare.rangedifferencer.RangeDifferencer;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jface.text.Document;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class RangeDifferencerThreeWayDiffTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*******************************************************************************/
package org.eclipse.compare.tests;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
Expand All @@ -24,7 +24,7 @@
import org.eclipse.compare.internal.merge.TextStreamMerger;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.junit.Test;
import org.junit.jupiter.api.Test;

// Tested class is deprecated
@Deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
*******************************************************************************/
package org.eclipse.compare.tests;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.HashMap;
import java.util.regex.Matcher;
Expand All @@ -33,7 +33,7 @@
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.Region;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class StructureCreatorTest {

Expand Down
Loading

0 comments on commit 699a7f6

Please sign in to comment.