Skip to content

Commit b432795

Browse files
committed
Migrate Ant core tests to JUnit 5 #903
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 #903
1 parent 48ab501 commit b432795

12 files changed

+192
-163
lines changed

ant/org.eclipse.ant.tests.core/Ant Core Test Suite.launch

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/>
2323
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
2424
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
25-
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
25+
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit5"/>
2626
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
2727
<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"/>
2828
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.ant.tests.core.AutomatedAntSuite"/>

ant/org.eclipse.ant.tests.core/META-INF/MANIFEST.MF

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ Export-Package: org.eclipse.ant.tests.core,
1212
org.eclipse.ant.tests.core.tests
1313
Require-Bundle: org.eclipse.ui.ide;resolution:=optional,
1414
org.apache.ant;bundle-version="1.9.4",
15-
org.junit,
1615
org.eclipse.core.resources,
1716
org.eclipse.ui,
1817
org.eclipse.ant.core,
1918
org.eclipse.core.runtime
20-
Import-Package: org.assertj.core.api
19+
Import-Package: org.assertj.core.api,
20+
org.junit.jupiter.api,
21+
org.junit.jupiter.api.function,
22+
org.junit.platform.suite.api
2123
Bundle-ActivationPolicy: lazy
2224
Bundle-RequiredExecutionEnvironment: JavaSE-17
2325
Eclipse-BundleShape: dir

ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/AbstractAntTest.java

+11-11
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
* https://www.eclipse.org/legal/epl-2.0/
88
*
99
* SPDX-License-Identifier: EPL-2.0
10-
*
10+
*
1111
* Contributors:
1212
* IBM Corporation - initial API and implementation
1313
*******************************************************************************/
1414
package org.eclipse.ant.tests.core;
1515

1616
import static org.assertj.core.api.Assertions.assertThat;
17-
import static org.junit.Assert.assertEquals;
17+
import static org.junit.jupiter.api.Assertions.assertEquals;
1818

1919
import java.io.File;
2020
import java.util.List;
@@ -48,7 +48,7 @@
4848
import org.eclipse.ui.intro.IIntroManager;
4949
import org.eclipse.ui.intro.IIntroPart;
5050
import org.eclipse.ui.progress.UIJob;
51-
import org.junit.Before;
51+
import org.junit.jupiter.api.BeforeEach;
5252

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

63-
@Before
63+
@BeforeEach
6464
public void setUp() throws Exception {
6565
assertProject();
6666
assertWelcomeScreenClosed();
6767
}
6868

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

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

124124
/**
125125
* Returns the 'AntTests' project.
126-
*
126+
*
127127
* @return the test project
128128
*/
129129
protected IProject getProject() {
@@ -177,8 +177,8 @@ public void run(String buildFileName, String[] args, boolean retrieveTargets, St
177177
} else {
178178
runner.run(buildFile, targets, args, workingDir, true);
179179
}
180-
assertEquals("Build starts did not equal build finishes", //$NON-NLS-1$
181-
AntTestChecker.getDefault().getBuildsStartedCount(), AntTestChecker.getDefault().getBuildsFinishedCount());
180+
assertEquals(AntTestChecker.getDefault().getBuildsStartedCount(),
181+
AntTestChecker.getDefault().getBuildsFinishedCount(), "Build starts did not equal build finishes"); //$NON-NLS-1$
182182
}
183183

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

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

267267
protected String getPropertyFileName() {

ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/AutomatedAntSuite.java

+16-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* https://www.eclipse.org/legal/epl-2.0/
88
*
99
* SPDX-License-Identifier: EPL-2.0
10-
*
10+
*
1111
* Contributors:
1212
* IBM Corporation - initial API and implementation
1313
*******************************************************************************/
@@ -21,12 +21,12 @@
2121
import org.eclipse.ant.tests.core.tests.TargetTests;
2222
import org.eclipse.ant.tests.core.tests.TaskTests;
2323
import org.eclipse.ant.tests.core.tests.TypeTests;
24-
import org.junit.runner.RunWith;
25-
import org.junit.runners.Suite;
24+
import org.junit.platform.suite.api.SelectClasses;
25+
import org.junit.platform.suite.api.Suite;
2626

2727
/**
2828
* Test the Eclipse Ant Core.
29-
*
29+
*
3030
* To run this test suite:
3131
* <ol>
3232
* <li>Create a new JUnit plugin test launch configuration</li>
@@ -35,9 +35,17 @@
3535
* <li>Run the launch configuration. Output from the tests will be displayed in a JUnit view</li>
3636
* </ol>
3737
*/
38-
@RunWith(Suite.class)
39-
@Suite.SuiteClasses({ FrameworkTests.class, TargetTests.class, ProjectTests.class, OptionTests.class, TaskTests.class, TypeTests.class,
40-
PropertyTests.class, AntSecurityManagerTest.class })
38+
@Suite
39+
@SelectClasses({ //
40+
FrameworkTests.class, //
41+
TargetTests.class, //
42+
ProjectTests.class, //
43+
OptionTests.class, //
44+
TaskTests.class, //
45+
TypeTests.class, //
46+
PropertyTests.class, //
47+
AntSecurityManagerTest.class //
48+
})
4149
public class AutomatedAntSuite {
42-
// SUITE
50+
//
4351
}

ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/tests/AntSecurityManagerTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package org.eclipse.ant.tests.core.tests;
22

3-
import static org.junit.Assert.assertFalse;
3+
import static org.junit.jupiter.api.Assertions.assertFalse;
44

55
import org.eclipse.ant.internal.core.AntSecurityManager;
66
import org.eclipse.ant.tests.core.AbstractAntTest;
7-
import org.junit.Test;
7+
import org.junit.jupiter.api.Test;
88

99
public class AntSecurityManagerTest extends AbstractAntTest {
1010

ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/tests/FrameworkTests.java

+25-20
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@
1515
package org.eclipse.ant.tests.core.tests;
1616

1717
import static org.assertj.core.api.Assertions.assertThat;
18-
import static org.junit.Assert.assertEquals;
19-
import static org.junit.Assert.assertFalse;
20-
import static org.junit.Assert.assertNotSame;
21-
import static org.junit.Assert.assertNull;
22-
import static org.junit.Assert.assertTrue;
18+
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
20+
import static org.junit.jupiter.api.Assertions.assertNotSame;
21+
import static org.junit.jupiter.api.Assertions.assertNull;
2322

2423
import java.io.File;
2524
import java.net.MalformedURLException;
@@ -39,7 +38,7 @@
3938
import org.eclipse.core.resources.IFile;
4039
import org.eclipse.core.runtime.CoreException;
4140
import org.eclipse.core.runtime.IPath;
42-
import org.junit.Test;
41+
import org.junit.jupiter.api.Test;
4342

4443
public class FrameworkTests extends AbstractAntTest {
4544

@@ -181,9 +180,9 @@ public void testGlobalPropertyFile() throws CoreException {
181180

182181
run("TestForEcho.xml", new String[] {}); //$NON-NLS-1$
183182
assertSuccessful();
184-
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$
185-
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$
186-
assertNull("my.name was not set and should be null", AntTestChecker.getDefault().getUserProperty("my.name")); //$NON-NLS-1$ //$NON-NLS-2$
183+
assertEquals("Yep", AntTestChecker.getDefault().getUserProperty("eclipse.is.cool")); //$NON-NLS-1$ //$NON-NLS-2$
184+
assertEquals("testing from properties file", AntTestChecker.getDefault().getUserProperty("AntTests")); //$NON-NLS-1$ //$NON-NLS-2$
185+
assertNull(AntTestChecker.getDefault().getUserProperty("my.name"), "my.name was not set and should be null"); //$NON-NLS-1$ //$NON-NLS-2$
187186

188187
restorePreferenceDefaults();
189188
}
@@ -199,9 +198,9 @@ public void testGlobalProperty() throws CoreException {
199198

200199
run("TestForEcho.xml", new String[] {}); //$NON-NLS-1$
201200
assertSuccessful();
202-
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$
203-
assertTrue("JUnitTests should have a value of true", "true".equals(AntTestChecker.getDefault().getUserProperty("JUnitTest"))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
204-
assertNull("my.name was not set and should be null", AntTestChecker.getDefault().getUserProperty("my.name")); //$NON-NLS-1$ //$NON-NLS-2$
201+
assertEquals("Yep", AntTestChecker.getDefault().getUserProperty("eclipse.is.cool")); //$NON-NLS-1$ //$NON-NLS-2$
202+
assertEquals("true", AntTestChecker.getDefault().getUserProperty("JUnitTest")); //$NON-NLS-1$ //$NON-NLS-2$
203+
assertNull(AntTestChecker.getDefault().getUserProperty("my.name"), "my.name was not set and should be null"); //$NON-NLS-1$ //$NON-NLS-2$
205204

206205
restorePreferenceDefaults();
207206
}
@@ -215,9 +214,9 @@ public void testGlobalPropertyFileWithMinusDTakingPrecedence() throws CoreExcept
215214

216215
run("echoing.xml", new String[] { "-DAntTests=testing", "-Declipse.is.cool=true" }, false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
217216
assertSuccessful();
218-
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$
219-
assertTrue("AntTests should have a value of testing", "testing".equals(AntTestChecker.getDefault().getUserProperty("AntTests"))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
220-
assertNull("my.name was not set and should be null", AntTestChecker.getDefault().getUserProperty("my.name")); //$NON-NLS-1$ //$NON-NLS-2$
217+
assertEquals("true", AntTestChecker.getDefault().getUserProperty("eclipse.is.cool")); //$NON-NLS-1$ //$NON-NLS-2$
218+
assertEquals("testing", AntTestChecker.getDefault().getUserProperty("AntTests")); //$NON-NLS-1$ //$NON-NLS-2$
219+
assertNull(AntTestChecker.getDefault().getUserProperty("my.name"), "my.name should be null"); //$NON-NLS-1$ //$NON-NLS-2$
221220
restorePreferenceDefaults();
222221
}
223222

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

291290
IAntClasspathEntry resultedEntries[] = prefs.getAntHomeClasspathEntries();
292291
int index = resultedEntries[entries.length].getLabel().indexOf("hub"); //$NON-NLS-1$
293-
assertNotSame("Missing machine details", index, -1); //$NON-NLS-1$
294-
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$
295-
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$
292+
assertNotSame(index, -1, "Missing machine details"); //$NON-NLS-1$
293+
assertNotEquals(resultedEntries[entries.length].getLabel(),
294+
IPath.fromOSString(
295+
"/home/tom/.eclipse/3.8/configuration/org.eclipse.osgi/bundles/21/2/.cp/lib/remote.jar") //$NON-NLS-1$
296+
.toOSString());
297+
assertEquals(resultedEntries[entries.length].getLabel().substring(index),
298+
IPath.fromOSString(
299+
"hub/home/tom/.eclipse/3.8/configuration/org.eclipse.osgi/bundles/21/2/.cp/lib/remote.jar") //$NON-NLS-1$
300+
.toOSString());
296301
}
297302
}

0 commit comments

Comments
 (0)