Skip to content

Commit

Permalink
Simplify and improve assertions in Ant core tests eclipse-platform#903
Browse files Browse the repository at this point in the history
Simplifies and/or improves several assertions in
org.eclipse.ant.core.tests
- Replace assertTrue/assertFalse with assertEquals/assertThat
- Remove obsolete assertions messages just repeating the assertions

This also prepares for a migration of assertions to JUnit 5.

Contributes to
eclipse-platform#903
  • Loading branch information
HeikoKlare committed Sep 13, 2024
1 parent ea7fa2a commit cfbe51d
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 176 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
*******************************************************************************/
package org.eclipse.ant.tests.core;

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

import java.io.File;
import java.util.List;
Expand Down Expand Up @@ -132,20 +132,20 @@ protected IProject getProject() {

protected IFile getBuildFile(String buildFileName) {
IFile file = getProject().getFolder(ProjectHelper.BUILDFILES_FOLDER).getFile(buildFileName);
assertTrue("Could not find build file named: " + buildFileName, file.exists()); //$NON-NLS-1$
assertThat(file).matches(IFile::exists, "exists"); //$NON-NLS-1$
return file;
}

protected IFolder getWorkingDirectory(String workingDirectoryName) {
IFolder folder = getProject().getFolder(workingDirectoryName);
assertTrue("Could not find the working directory named: " + workingDirectoryName, folder.exists()); //$NON-NLS-1$
assertThat(folder).matches(IFolder::exists, "exists"); //$NON-NLS-1$
return folder;
}

protected IFile checkFileExists(String fileName) throws CoreException {
getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
IFile file = getProject().getFolder(ProjectHelper.BUILDFILES_FOLDER).getFile(fileName);
assertTrue("Could not find file named: " + fileName, file.exists()); //$NON-NLS-1$
assertThat(file).matches(IFile::exists, "exists"); //$NON-NLS-1$
return file;
}

Expand Down Expand Up @@ -177,7 +177,8 @@ public void run(String buildFileName, String[] args, boolean retrieveTargets, St
} else {
runner.run(buildFile, targets, args, workingDir, true);
}
assertTrue("Build starts did not equal build finishes", AntTestChecker.getDefault().getBuildsStartedCount() == AntTestChecker.getDefault().getBuildsFinishedCount()); //$NON-NLS-1$
assertEquals("Build starts did not equal build finishes", //$NON-NLS-1$
AntTestChecker.getDefault().getBuildsStartedCount(), AntTestChecker.getDefault().getBuildsFinishedCount());
}

protected TargetInfo[] getTargets(String buildFileName) throws CoreException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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;
Expand Down Expand Up @@ -68,7 +69,7 @@ public void testClasspathOrderingDeprecated() throws MalformedURLException, Core

run("ClasspathOrdering.xml"); //$NON-NLS-1$
String msg = AntTestChecker.getDefault().getMessages().get(1);
assertTrue("Message incorrect: " + msg, msg.equals("classpathOrdering1")); //$NON-NLS-1$ //$NON-NLS-2$
assertEquals("classpathOrdering1", msg); //$NON-NLS-1$
assertSuccessful();

restorePreferenceDefaults();
Expand All @@ -84,7 +85,7 @@ public void testClasspathOrderingDeprecated() throws MalformedURLException, Core

run("ClasspathOrdering.xml"); //$NON-NLS-1$
msg = AntTestChecker.getDefault().getMessages().get(1);
assertTrue("Message incorrect: " + msg, msg.equals("classpathOrdering2")); //$NON-NLS-1$ //$NON-NLS-2$
assertEquals("classpathOrdering2", msg); //$NON-NLS-1$
assertSuccessful();
restorePreferenceDefaults();
}
Expand All @@ -110,7 +111,7 @@ public void testClasspathOrdering() throws CoreException {

run("ClasspathOrdering.xml"); //$NON-NLS-1$
String msg = AntTestChecker.getDefault().getMessages().get(1);
assertTrue("Message incorrect: " + msg, msg.equals("classpathOrdering1")); //$NON-NLS-1$ //$NON-NLS-2$
assertEquals("classpathOrdering1", msg); //$NON-NLS-1$
assertSuccessful();

restorePreferenceDefaults();
Expand All @@ -126,7 +127,7 @@ public void testClasspathOrdering() throws CoreException {

run("ClasspathOrdering.xml"); //$NON-NLS-1$
msg = AntTestChecker.getDefault().getMessages().get(1);
assertTrue("Message incorrect: " + msg, msg.equals("classpathOrdering2")); //$NON-NLS-1$ //$NON-NLS-2$
assertEquals("classpathOrdering2", msg); //$NON-NLS-1$
assertSuccessful();
restorePreferenceDefaults();
}
Expand Down Expand Up @@ -160,11 +161,11 @@ public void testIncludeAntRuntime() throws CoreException {
run("javac.xml", new String[] { "build", "refresh" }, false); // standard compiler //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
assertSuccessful();
IFile classFile = getProject().getFolder("temp.folder").getFolder("javac.bin").getFile("AntTestTask.class"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
assertTrue("Class file was not generated", classFile.exists()); //$NON-NLS-1$
assertThat(classFile).matches(IFile::exists, "exists"); //$NON-NLS-1$
run("javac.xml", new String[] { "-Duse.eclipse.compiler=true", "clean", "build", "refresh" }, false); // JDTCompiler //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
assertSuccessful();
classFile = getProject().getFolder("temp.folder").getFolder("javac.bin").getFile("AntTestTask.class"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
assertTrue("Class file was not generated", classFile.exists()); //$NON-NLS-1$
assertThat(classFile).matches(IFile::exists, "exists"); //$NON-NLS-1$
}

/**
Expand Down Expand Up @@ -228,9 +229,9 @@ public void testSettingAntHome() throws CoreException {
try {
AntCorePreferences prefs = AntCorePlugin.getPlugin().getPreferences();
run("echoing.xml"); //$NON-NLS-1$
assertTrue("ANT_HOME not set correctly", prefs.getDefaultAntHome().equals(System.getProperty("ant.home"))); //$NON-NLS-1$ //$NON-NLS-2$
assertEquals(prefs.getDefaultAntHome(), System.getProperty("ant.home")); //$NON-NLS-1$
File antLibDir = new File(prefs.getDefaultAntHome(), ProjectHelper.LIB_FOLDER);
assertTrue("ant.library.dir not set correctly", antLibDir.getAbsolutePath().equals(System.getProperty("ant.library.dir"))); //$NON-NLS-1$ //$NON-NLS-2$
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$
Expand Down
Loading

0 comments on commit cfbe51d

Please sign in to comment.