Skip to content

Commit

Permalink
Migrate Ant core tests to JUnit 5 eclipse-platform#903
Browse files Browse the repository at this point in the history
Migrates the tests in org.eclipse.ant.tests.core to JUnit 5.
- Exchange JUnit 4 test annotations
- Replace JUnit 4 test suites with JUnit platform suites
- Replace JUnit 4 assertions with JUnit 5 assertions

Contributes to
eclipse-platform#903
  • Loading branch information
HeikoKlare committed Sep 18, 2024
1 parent 920089f commit 9666d3e
Show file tree
Hide file tree
Showing 12 changed files with 192 additions and 163 deletions.
2 changes: 1 addition & 1 deletion ant/org.eclipse.ant.tests.core/Ant Core Test Suite.launch
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/>
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit5"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.ant.tests.core.AutomatedAntSuite"/>
Expand Down
6 changes: 4 additions & 2 deletions ant/org.eclipse.ant.tests.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ Export-Package: org.eclipse.ant.tests.core,
org.eclipse.ant.tests.core.tests
Require-Bundle: org.eclipse.ui.ide;resolution:=optional,
org.apache.ant;bundle-version="1.9.4",
org.junit,
org.eclipse.core.resources,
org.eclipse.ui,
org.eclipse.ant.core,
org.eclipse.core.runtime
Import-Package: org.assertj.core.api
Import-Package: org.assertj.core.api,
org.junit.jupiter.api,
org.junit.jupiter.api.function,
org.junit.platform.suite.api
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-17
Eclipse-BundleShape: dir
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.ant.tests.core;

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

import java.io.File;
import java.util.List;
Expand Down Expand Up @@ -48,7 +48,7 @@
import org.eclipse.ui.intro.IIntroManager;
import org.eclipse.ui.intro.IIntroPart;
import org.eclipse.ui.progress.UIJob;
import org.junit.Before;
import org.junit.jupiter.api.BeforeEach;

/**
* Tests for Ant core
Expand All @@ -60,15 +60,15 @@ public abstract class AbstractAntTest {
public static final String ANT_TEST_BUILD_LISTENER = "org.eclipse.ant.tests.core.support.testloggers.TestBuildListener"; //$NON-NLS-1$
private static boolean welcomeClosed = false;

@Before
@BeforeEach
public void setUp() throws Exception {
assertProject();
assertWelcomeScreenClosed();
}

/**
* Ensure the welcome screen is closed because in 4.x the debug perspective opens a giant fast-view causing issues
*
*
* @since 3.8
*/
void assertWelcomeScreenClosed() throws Exception {
Expand Down Expand Up @@ -98,7 +98,7 @@ public IStatus runInUIThread(IProgressMonitor monitor) {

/**
* Asserts that the test project has been created and all testing resources have been loaded each time the {@link #setUp()} method is called
*
*
* @since 3.5
*/
protected void assertProject() throws Exception {
Expand All @@ -123,7 +123,7 @@ protected void assertProject() throws Exception {

/**
* Returns the 'AntTests' project.
*
*
* @return the test project
*/
protected IProject getProject() {
Expand Down Expand Up @@ -177,8 +177,8 @@ public void run(String buildFileName, String[] args, boolean retrieveTargets, St
} else {
runner.run(buildFile, targets, args, workingDir, true);
}
assertEquals("Build starts did not equal build finishes", //$NON-NLS-1$
AntTestChecker.getDefault().getBuildsStartedCount(), AntTestChecker.getDefault().getBuildsFinishedCount());
assertEquals(AntTestChecker.getDefault().getBuildsStartedCount(),
AntTestChecker.getDefault().getBuildsFinishedCount(), "Build starts did not equal build finishes"); //$NON-NLS-1$
}

protected TargetInfo[] getTargets(String buildFileName) throws CoreException {
Expand Down Expand Up @@ -245,7 +245,7 @@ protected TargetInfo getTarget(String buildFileName, String targetName) throws C

/**
* Return the log message n from the last: e.g. getLoggedMessage(0) returns the most recent message
*
*
* @param n
* message index
* @return the nth last message
Expand All @@ -261,7 +261,7 @@ protected String getLastMessageLogged() {
protected void assertSuccessful() {
List<String> messages = AntTestChecker.getDefault().getMessages();
String success = messages.get(messages.size() - 1);
assertEquals("Build was not flagged as successful: " + success, BUILD_SUCCESSFUL, success); //$NON-NLS-1$
assertEquals(BUILD_SUCCESSFUL, success, "Build was not flagged as successful"); //$NON-NLS-1$
}

protected String getPropertyFileName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
Expand All @@ -21,12 +21,12 @@
import org.eclipse.ant.tests.core.tests.TargetTests;
import org.eclipse.ant.tests.core.tests.TaskTests;
import org.eclipse.ant.tests.core.tests.TypeTests;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.Suite;

/**
* Test the Eclipse Ant Core.
*
*
* To run this test suite:
* <ol>
* <li>Create a new JUnit plugin test launch configuration</li>
Expand All @@ -35,9 +35,17 @@
* <li>Run the launch configuration. Output from the tests will be displayed in a JUnit view</li>
* </ol>
*/
@RunWith(Suite.class)
@Suite.SuiteClasses({ FrameworkTests.class, TargetTests.class, ProjectTests.class, OptionTests.class, TaskTests.class, TypeTests.class,
PropertyTests.class, AntSecurityManagerTest.class })
@Suite
@SelectClasses({ //
FrameworkTests.class, //
TargetTests.class, //
ProjectTests.class, //
OptionTests.class, //
TaskTests.class, //
TypeTests.class, //
PropertyTests.class, //
AntSecurityManagerTest.class //
})
public class AutomatedAntSuite {
// SUITE
//
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.eclipse.ant.tests.core.tests;

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

import org.eclipse.ant.internal.core.AntSecurityManager;
import org.eclipse.ant.tests.core.AbstractAntTest;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class AntSecurityManagerTest extends AbstractAntTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
package org.eclipse.ant.tests.core.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.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertNull;

import java.io.File;
import java.net.MalformedURLException;
Expand All @@ -39,7 +38,7 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class FrameworkTests extends AbstractAntTest {

Expand Down Expand Up @@ -181,9 +180,9 @@ public void testGlobalPropertyFile() throws CoreException {

run("TestForEcho.xml", new String[] {}); //$NON-NLS-1$
assertSuccessful();
assertTrue("eclipse.is.cool should have been set as Yep", "Yep".equals(AntTestChecker.getDefault().getUserProperty("eclipse.is.cool"))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
assertTrue("AntTests should have a value of testing", "testing from properties file".equals(AntTestChecker.getDefault().getUserProperty("AntTests"))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
assertNull("my.name was not set and should be null", AntTestChecker.getDefault().getUserProperty("my.name")); //$NON-NLS-1$ //$NON-NLS-2$
assertEquals("Yep", AntTestChecker.getDefault().getUserProperty("eclipse.is.cool")); //$NON-NLS-1$ //$NON-NLS-2$
assertEquals("testing from properties file", AntTestChecker.getDefault().getUserProperty("AntTests")); //$NON-NLS-1$ //$NON-NLS-2$
assertNull(AntTestChecker.getDefault().getUserProperty("my.name"), "my.name was not set and should be null"); //$NON-NLS-1$ //$NON-NLS-2$

restorePreferenceDefaults();
}
Expand All @@ -199,9 +198,9 @@ public void testGlobalProperty() throws CoreException {

run("TestForEcho.xml", new String[] {}); //$NON-NLS-1$
assertSuccessful();
assertTrue("eclipse.is.cool should have been set as Yep", "Yep".equals(AntTestChecker.getDefault().getUserProperty("eclipse.is.cool"))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
assertTrue("JUnitTests should have a value of true", "true".equals(AntTestChecker.getDefault().getUserProperty("JUnitTest"))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
assertNull("my.name was not set and should be null", AntTestChecker.getDefault().getUserProperty("my.name")); //$NON-NLS-1$ //$NON-NLS-2$
assertEquals("Yep", AntTestChecker.getDefault().getUserProperty("eclipse.is.cool")); //$NON-NLS-1$ //$NON-NLS-2$
assertEquals("true", AntTestChecker.getDefault().getUserProperty("JUnitTest")); //$NON-NLS-1$ //$NON-NLS-2$
assertNull(AntTestChecker.getDefault().getUserProperty("my.name"), "my.name was not set and should be null"); //$NON-NLS-1$ //$NON-NLS-2$

restorePreferenceDefaults();
}
Expand All @@ -215,9 +214,9 @@ public void testGlobalPropertyFileWithMinusDTakingPrecedence() throws CoreExcept

run("echoing.xml", new String[] { "-DAntTests=testing", "-Declipse.is.cool=true" }, false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
assertSuccessful();
assertTrue("eclipse.is.cool should have been set as true", "true".equals(AntTestChecker.getDefault().getUserProperty("eclipse.is.cool"))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
assertTrue("AntTests should have a value of testing", "testing".equals(AntTestChecker.getDefault().getUserProperty("AntTests"))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
assertNull("my.name was not set and should be null", AntTestChecker.getDefault().getUserProperty("my.name")); //$NON-NLS-1$ //$NON-NLS-2$
assertEquals("true", AntTestChecker.getDefault().getUserProperty("eclipse.is.cool")); //$NON-NLS-1$ //$NON-NLS-2$
assertEquals("testing", AntTestChecker.getDefault().getUserProperty("AntTests")); //$NON-NLS-1$ //$NON-NLS-2$
assertNull(AntTestChecker.getDefault().getUserProperty("my.name"), "my.name should be null"); //$NON-NLS-1$ //$NON-NLS-2$
restorePreferenceDefaults();
}

Expand All @@ -234,8 +233,8 @@ public void testSettingAntHome() throws CoreException {
assertEquals(antLibDir.getAbsolutePath(), System.getProperty("ant.library.dir")); //$NON-NLS-1$
prefs.setAntHome(""); //$NON-NLS-1$
run("echoing.xml"); //$NON-NLS-1$
assertTrue("ANT_HOME not set correctly", null == System.getProperty("ant.home")); //$NON-NLS-1$ //$NON-NLS-2$
assertTrue("ant.library.dir not set correctly", null == System.getProperty("ant.library.dir")); //$NON-NLS-1$ //$NON-NLS-2$
assertNull(System.getProperty("ant.home"), "ant.home should be null"); //$NON-NLS-1$ //$NON-NLS-2$
assertNull(System.getProperty("ant.library.dir"), "ant.library.dir should be null"); //$NON-NLS-1$ //$NON-NLS-2$
}
finally {
restorePreferenceDefaults();
Expand Down Expand Up @@ -290,8 +289,14 @@ public void testAntClasspathEntryFromUrl() throws MalformedURLException {

IAntClasspathEntry resultedEntries[] = prefs.getAntHomeClasspathEntries();
int index = resultedEntries[entries.length].getLabel().indexOf("hub"); //$NON-NLS-1$
assertNotSame("Missing machine details", index, -1); //$NON-NLS-1$
assertFalse("Incorrect classpath entry. This would have been the value before the fix", resultedEntries[entries.length].getLabel().equals(IPath.fromOSString("/home/tom/.eclipse/3.8/configuration/org.eclipse.osgi/bundles/21/2/.cp/lib/remote.jar").toOSString())); //$NON-NLS-1$ //$NON-NLS-2$
assertTrue("Incorrect classpath entry", resultedEntries[entries.length].getLabel().substring(index).equals(IPath.fromOSString("hub/home/tom/.eclipse/3.8/configuration/org.eclipse.osgi/bundles/21/2/.cp/lib/remote.jar").toOSString())); //$NON-NLS-1$ //$NON-NLS-2$
assertNotSame(index, -1, "Missing machine details"); //$NON-NLS-1$
assertNotEquals(resultedEntries[entries.length].getLabel(),
IPath.fromOSString(
"/home/tom/.eclipse/3.8/configuration/org.eclipse.osgi/bundles/21/2/.cp/lib/remote.jar") //$NON-NLS-1$
.toOSString());
assertEquals(resultedEntries[entries.length].getLabel().substring(index),
IPath.fromOSString(
"hub/home/tom/.eclipse/3.8/configuration/org.eclipse.osgi/bundles/21/2/.cp/lib/remote.jar") //$NON-NLS-1$
.toOSString());
}
}
Loading

0 comments on commit 9666d3e

Please sign in to comment.