Skip to content

Commit cfbe51d

Browse files
committed
Simplify and improve assertions in Ant core tests #903
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 #903
1 parent ea7fa2a commit cfbe51d

File tree

7 files changed

+124
-176
lines changed

7 files changed

+124
-176
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
*******************************************************************************/
1414
package org.eclipse.ant.tests.core;
1515

16+
import static org.assertj.core.api.Assertions.assertThat;
1617
import static org.junit.Assert.assertEquals;
17-
import static org.junit.Assert.assertTrue;
1818

1919
import java.io.File;
2020
import java.util.List;
@@ -132,20 +132,20 @@ protected IProject getProject() {
132132

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

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

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

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

183184
protected TargetInfo[] getTargets(String buildFileName) throws CoreException {

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
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;
1819
import static org.junit.Assert.assertFalse;
1920
import static org.junit.Assert.assertNotSame;
2021
import static org.junit.Assert.assertNull;
@@ -68,7 +69,7 @@ public void testClasspathOrderingDeprecated() throws MalformedURLException, Core
6869

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

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

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

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

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

127128
run("ClasspathOrdering.xml"); //$NON-NLS-1$
128129
msg = AntTestChecker.getDefault().getMessages().get(1);
129-
assertTrue("Message incorrect: " + msg, msg.equals("classpathOrdering2")); //$NON-NLS-1$ //$NON-NLS-2$
130+
assertEquals("classpathOrdering2", msg); //$NON-NLS-1$
130131
assertSuccessful();
131132
restorePreferenceDefaults();
132133
}
@@ -160,11 +161,11 @@ public void testIncludeAntRuntime() throws CoreException {
160161
run("javac.xml", new String[] { "build", "refresh" }, false); // standard compiler //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
161162
assertSuccessful();
162163
IFile classFile = getProject().getFolder("temp.folder").getFolder("javac.bin").getFile("AntTestTask.class"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
163-
assertTrue("Class file was not generated", classFile.exists()); //$NON-NLS-1$
164+
assertThat(classFile).matches(IFile::exists, "exists"); //$NON-NLS-1$
164165
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$
165166
assertSuccessful();
166167
classFile = getProject().getFolder("temp.folder").getFolder("javac.bin").getFile("AntTestTask.class"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
167-
assertTrue("Class file was not generated", classFile.exists()); //$NON-NLS-1$
168+
assertThat(classFile).matches(IFile::exists, "exists"); //$NON-NLS-1$
168169
}
169170

170171
/**
@@ -228,9 +229,9 @@ public void testSettingAntHome() throws CoreException {
228229
try {
229230
AntCorePreferences prefs = AntCorePlugin.getPlugin().getPreferences();
230231
run("echoing.xml"); //$NON-NLS-1$
231-
assertTrue("ANT_HOME not set correctly", prefs.getDefaultAntHome().equals(System.getProperty("ant.home"))); //$NON-NLS-1$ //$NON-NLS-2$
232+
assertEquals(prefs.getDefaultAntHome(), System.getProperty("ant.home")); //$NON-NLS-1$
232233
File antLibDir = new File(prefs.getDefaultAntHome(), ProjectHelper.LIB_FOLDER);
233-
assertTrue("ant.library.dir not set correctly", antLibDir.getAbsolutePath().equals(System.getProperty("ant.library.dir"))); //$NON-NLS-1$ //$NON-NLS-2$
234+
assertEquals(antLibDir.getAbsolutePath(), System.getProperty("ant.library.dir")); //$NON-NLS-1$
234235
prefs.setAntHome(""); //$NON-NLS-1$
235236
run("echoing.xml"); //$NON-NLS-1$
236237
assertTrue("ANT_HOME not set correctly", null == System.getProperty("ant.home")); //$NON-NLS-1$ //$NON-NLS-2$

0 commit comments

Comments
 (0)