Bug 561040 - Migrate ant tests to JUnit 4
Make use of newer asserts.
Change-Id: Ica263f0c500ccfded36801800e0eda8d27adf996
Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
diff --git a/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/tests/OptionTests.java b/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/tests/OptionTests.java
index 320e8c8..81b36cd 100644
--- a/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/tests/OptionTests.java
+++ b/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/tests/OptionTests.java
@@ -14,8 +14,10 @@
package org.eclipse.ant.tests.core.tests;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import java.io.BufferedInputStream;
@@ -45,7 +47,8 @@
public void testHelp() throws CoreException {
run("TestForEcho.xml", new String[] { "-help" }); //$NON-NLS-1$ //$NON-NLS-2$
assertEquals("incorrect message number logged", 36, AntTestChecker.getDefault().getMessagesLoggedCount()); //$NON-NLS-1$
- assertTrue("Help is incorrect", getLastMessageLogged() != null && AntTestChecker.getDefault().getMessages().get(0).startsWith(START_OF_HELP)); //$NON-NLS-1$
+ assertTrue("Help is incorrect", getLastMessageLogged() != null //$NON-NLS-1$
+ && AntTestChecker.getDefault().getMessages().get(0).startsWith(START_OF_HELP));
}
/**
@@ -55,7 +58,8 @@
public void testMinusH() throws CoreException {
run("TestForEcho.xml", new String[] { "-h" }); //$NON-NLS-1$ //$NON-NLS-2$
assertEquals("incorrect message number logged", 36, AntTestChecker.getDefault().getMessagesLoggedCount()); //$NON-NLS-1$
- assertTrue("Help is incorrect", getLastMessageLogged() != null && AntTestChecker.getDefault().getMessages().get(0).startsWith(START_OF_HELP)); //$NON-NLS-1$
+ assertTrue("Help is incorrect", getLastMessageLogged() != null //$NON-NLS-1$
+ && AntTestChecker.getDefault().getMessages().get(0).startsWith(START_OF_HELP));
}
/**
@@ -64,7 +68,7 @@
@Test
public void testVersion() throws CoreException {
run("TestForEcho.xml", new String[] { "-version" }); //$NON-NLS-1$ //$NON-NLS-2$
- assertTrue("One message should have been logged", AntTestChecker.getDefault().getMessagesLoggedCount() == 1); //$NON-NLS-1$
+ assertEquals("One message should have been logged", 1, AntTestChecker.getDefault().getMessagesLoggedCount()); //$NON-NLS-1$
assertTrue("Version is incorrect", getLastMessageLogged().startsWith(VERSION)); //$NON-NLS-1$
}
@@ -98,20 +102,18 @@
}
/**
- * Tests the "-listener" option with a listener that is not an instance of BuildListener
+ * Tests the "-listener" option with a listener that is not an instance of
+ * BuildListener
*/
@Test
public void testListenerBad() {
- try {
- run("TestForEcho.xml", new String[] { "-listener", "java.lang.String" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
- catch (CoreException ce) {
- String msg = ce.getMessage();
- assertTrue("Message incorrect!: " //$NON-NLS-1$
- + msg, msg.equals("java.lang.String which was specified to be a build listener is not an instance of org.apache.tools.ant.BuildListener.")); //$NON-NLS-1$
- return;
- }
- assertTrue("A core exception should have occurred wrappering a class cast exception", false); //$NON-NLS-1$
+ CoreException ce = assertThrows("A core exception should have occurred wrappering a class cast exception", //$NON-NLS-1$
+ CoreException.class, () -> run("TestForEcho.xml", new String[] { "-listener", "java.lang.String" })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ String msg = ce.getMessage();
+ assertTrue("Message incorrect!: " //$NON-NLS-1$
+ + msg,
+ msg.equals(
+ "java.lang.String which was specified to be a build listener is not an instance of org.apache.tools.ant.BuildListener.")); //$NON-NLS-1$
}
/**
@@ -121,7 +123,8 @@
public void testUnknownArg() throws CoreException {
run("TestForEcho.xml", new String[] { "-listenr" }); //$NON-NLS-1$ //$NON-NLS-2$
assertTrue("Unrecognized option message should have been logged before successful build", //$NON-NLS-1$
- (AntTestChecker.getDefault().getMessagesLoggedCount() == 6) && (getLoggedMessage(5).startsWith(UNKNOWN_ARG))
+ (AntTestChecker.getDefault().getMessagesLoggedCount() == 6)
+ && (getLoggedMessage(5).startsWith(UNKNOWN_ARG))
&& (getLastMessageLogged().startsWith(BUILD_SUCCESSFUL)));
}
@@ -130,13 +133,8 @@
*/
@Test
public void testLogFileWithNoArg() {
- try {
- run("TestForEcho.xml", new String[] { "-logfile" }); //$NON-NLS-1$ //$NON-NLS-2$
- }
- catch (CoreException ce) {
- return;
- }
- assertTrue("You must specify a log file when using the -log argument", false); //$NON-NLS-1$
+ assertThrows("You must specify a log file when using the -log argument", CoreException.class, //$NON-NLS-1$
+ () -> run("TestForEcho.xml", new String[] { "-logfile" })); //$NON-NLS-1$ //$NON-NLS-2$
}
/**
@@ -147,7 +145,8 @@
run("TestForEcho.xml", new String[] { "-logfile", "TestLogFile.txt" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
IFile file = checkFileExists("TestLogFile.txt"); //$NON-NLS-1$
- try (InputStream stream = file.getContents(); InputStreamReader in = new InputStreamReader(new BufferedInputStream(stream))) {
+ try (InputStream stream = file.getContents();
+ InputStreamReader in = new InputStreamReader(new BufferedInputStream(stream))) {
StringBuilder buffer = new StringBuilder();
char[] readBuffer = new char[2048];
int n = in.read(readBuffer);
@@ -165,27 +164,18 @@
*/
@Test
public void testLoggerWithNoArg() {
- try {
- run("TestForEcho.xml", new String[] { "-logger" }); //$NON-NLS-1$ //$NON-NLS-2$
- }
- catch (CoreException ce) {
- return;
- }
- assertTrue("You must specify a classname when using the -logger argument", false); //$NON-NLS-1$
+ assertThrows("You must specify a classname when using the -logger argument", CoreException.class, //$NON-NLS-1$
+ () -> run("TestForEcho.xml", new String[] { "-logger" })); //$NON-NLS-1$ //$NON-NLS-2$
}
/**
- * Tests the "-logger" option with a logger that is not an instance of BuildLogger
+ * Tests the "-logger" option with a logger that is not an instance of
+ * BuildLogger
*/
@Test
public void testLoggerBad() {
- try {
- run("TestForEcho.xml", new String[] { "-logger", "java.lang.String" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
- catch (CoreException ce) {
- return;
- }
- assertTrue("A core exception should have occurred wrappering a class cast exception", false); //$NON-NLS-1$
+ assertThrows("A core exception should have occurred wrappering a class cast exception", CoreException.class, //$NON-NLS-1$
+ () -> run("TestForEcho.xml", new String[] { "-logger", "java.lang.String" })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
/**
@@ -193,13 +183,8 @@
*/
@Test
public void testTwoLoggers() {
- try {
- run("TestForEcho.xml", new String[] { "-logger", "java.lang.String", "-q", "-logger", "java.lang.String" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
- }
- catch (CoreException ce) {
- return;
- }
- assertTrue("As only one logger can be specified", false); //$NON-NLS-1$
+ assertThrows("As only one logger can be specified", CoreException.class, () -> run("TestForEcho.xml", //$NON-NLS-1$ //$NON-NLS-2$
+ new String[] { "-logger", "java.lang.String", "-q", "-logger", "java.lang.String" })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
}
/**
@@ -207,13 +192,8 @@
*/
@Test
public void testListenerWithNoArg() {
- try {
- run("TestForEcho.xml", new String[] { "-listener" }); //$NON-NLS-1$ //$NON-NLS-2$
- }
- catch (CoreException ce) {
- return;
- }
- assertTrue("You must specify a listeners when using the -listener argument ", false); //$NON-NLS-1$
+ assertThrows("You must specify a listeners when using the -listener argument ", CoreException.class, //$NON-NLS-1$
+ () -> run("TestForEcho.xml", new String[] { "-listener" })); //$NON-NLS-1$ //$NON-NLS-2$
}
/**
@@ -221,15 +201,11 @@
*/
@Test
public void testListenerClassNotFound() {
- try {
- run("TestForEcho.xml", new String[] { "-listener", "TestBuildListener" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
- catch (CoreException e) {
- String message = e.getStatus().getException().getMessage();
- assertTrue("Should be ClassNotFoundException", "java.lang.ClassNotFoundException: TestBuildListener".equals(message)); //$NON-NLS-1$ //$NON-NLS-2$
- return;
- }
- assertTrue("A CoreException should have occurred as the listener class will not be found", false); //$NON-NLS-1$
+ CoreException e = assertThrows("A CoreException should have occurred as the listener class will not be found", //$NON-NLS-1$
+ CoreException.class, () -> run("TestForEcho.xml", new String[] { "-listener", "TestBuildListener" })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ String message = e.getStatus().getException().getMessage();
+ assertTrue("Should be ClassNotFoundException", //$NON-NLS-1$
+ "java.lang.ClassNotFoundException: TestBuildListener".equals(message)); //$NON-NLS-1$
}
@@ -241,26 +217,22 @@
run("TestForEcho.xml", new String[] { "-listener", ANT_TEST_BUILD_LISTENER }); //$NON-NLS-1$ //$NON-NLS-2$
assertSuccessful();
assertTrue("A listener should have been added named: " //$NON-NLS-1$
- + ANT_TEST_BUILD_LISTENER, ANT_TEST_BUILD_LISTENER.equals(AntTestChecker.getDefault().getLastListener()));
+ + ANT_TEST_BUILD_LISTENER,
+ ANT_TEST_BUILD_LISTENER.equals(AntTestChecker.getDefault().getLastListener()));
}
/**
* Tests specifying the XmlLogger as a listener (bug 80435)
*/
@Test
- public void testXmlLoggerListener() throws CoreException {
+ public void testXmlLoggerListener() throws CoreException, IOException {
run("TestForEcho.xml", new String[] { "-listener", "org.apache.tools.ant.XmlLogger" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
assertSuccessful();
// find the log file generated by the xml logger
IFile file = checkFileExists("log.xml"); //$NON-NLS-1$
InputStream stream = file.getContents();
- try {
- assertTrue(stream.available() != 0);
- }
- catch (IOException e) {
- assertTrue(false);
- }
+ assertNotEquals(0, stream.available());
}
/**
@@ -268,26 +240,24 @@
*/
@Test
public void testListenerMultiple() throws CoreException {
- run("TestForEcho.xml", new String[] { "-listener", ANT_TEST_BUILD_LISTENER, "-listener", ANT_TEST_BUILD_LISTENER }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ run("TestForEcho.xml", //$NON-NLS-1$
+ new String[] { "-listener", ANT_TEST_BUILD_LISTENER, "-listener", ANT_TEST_BUILD_LISTENER }); //$NON-NLS-1$ //$NON-NLS-2$
assertSuccessful();
assertTrue("A listener should have been added named: " //$NON-NLS-1$
- + ANT_TEST_BUILD_LISTENER, ANT_TEST_BUILD_LISTENER.equals(AntTestChecker.getDefault().getLastListener()));
- assertTrue("Two listeners should have been added", AntTestChecker.getDefault().getListeners().size() == 2); //$NON-NLS-1$
+ + ANT_TEST_BUILD_LISTENER,
+ ANT_TEST_BUILD_LISTENER.equals(AntTestChecker.getDefault().getLastListener()));
+ assertEquals("Two listeners should have been added", 2, AntTestChecker.getDefault().getListeners().size()); //$NON-NLS-1$
}
/**
- * Tests specifying the -listener option multiple times, with one missing the arg
+ * Tests specifying the -listener option multiple times, with one missing the
+ * arg
*/
@Test
public void testListenerMultipleWithBad() {
- try {
- run("TestForEcho.xml", new String[] { "-listener", ANT_TEST_BUILD_LISTENER, "-q", "-listener", "-verbose" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- }
- catch (CoreException e) {
- // You must specify a listener for all -listener arguments
- return;
- }
- assertTrue("You must specify a listener for all -listener arguments ", false); //$NON-NLS-1$
+ assertThrows("You must specify a listener for all -listener arguments ", CoreException.class, //$NON-NLS-1$
+ () -> run("TestForEcho.xml", //$NON-NLS-1$
+ new String[] { "-listener", ANT_TEST_BUILD_LISTENER, "-q", "-listener", "-verbose" })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
}
/**
@@ -295,14 +265,8 @@
*/
@Test
public void testBuildFileWithNoArg() {
- try {
- run("TestForEcho.xml", new String[] { "-buildfile" }); //$NON-NLS-1$ //$NON-NLS-2$
- }
- catch (CoreException ce) {
- // You must specify a buildfile when using the -buildfile argument
- return;
- }
- assertTrue("You must specify a buildfile when using the -buildfile argument", false); //$NON-NLS-1$
+ assertThrows("You must specify a buildfile when using the -buildfile argument", CoreException.class, //$NON-NLS-1$
+ () -> run("TestForEcho.xml", new String[] { "-buildfile" })); //$NON-NLS-1$ //$NON-NLS-2$
}
/**
@@ -310,11 +274,13 @@
*/
@Test
public void testBuildFile() throws CoreException {
- String buildFileName = getProject().getFolder("buildfiles").getFile("echoing.xml").getLocation().toFile().getAbsolutePath(); //$NON-NLS-1$ //$NON-NLS-2$
+ String buildFileName = getProject().getFolder("buildfiles").getFile("echoing.xml").getLocation().toFile() //$NON-NLS-1$ //$NON-NLS-2$
+ .getAbsolutePath();
run("TestForEcho.xml", new String[] { "-buildfile", buildFileName }, false, "buildfiles"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- assertTrue("Should have been 1 tasks, was: " //$NON-NLS-1$
- + AntTestChecker.getDefault().getTaskStartedCount(), AntTestChecker.getDefault().getTaskStartedCount() == 1);
+ assertEquals("Should have been 1 tasks, was: " //$NON-NLS-1$
+ + AntTestChecker.getDefault().getTaskStartedCount(), 1,
+ AntTestChecker.getDefault().getTaskStartedCount());
}
/**
@@ -326,22 +292,29 @@
@Test
public void testSpecifyBadTargetAsArg() throws CoreException {
run("TestForEcho.xml", new String[] { "echo2" }, false); //$NON-NLS-1$ //$NON-NLS-2$
- assertTrue("Should be an unknown target message", AntTestChecker.getDefault().getLoggedMessage(1).contains("Unknown target")); //$NON-NLS-1$//$NON-NLS-2$
- assertTrue("Should be an unknown target message", AntTestChecker.getDefault().getLoggedMessage(1).contains("echo2")); //$NON-NLS-1$ //$NON-NLS-2$
- assertTrue("Should be a no known target message", AntTestChecker.getDefault().getLoggedMessage(0).contains("No known target specified.")); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("Should be an unknown target message", //$NON-NLS-1$
+ AntTestChecker.getDefault().getLoggedMessage(1).contains("Unknown target")); //$NON-NLS-1$
+ assertTrue("Should be an unknown target message", //$NON-NLS-1$
+ AntTestChecker.getDefault().getLoggedMessage(1).contains("echo2")); //$NON-NLS-1$
+ assertTrue("Should be a no known target message", //$NON-NLS-1$
+ AntTestChecker.getDefault().getLoggedMessage(0).contains("No known target specified.")); //$NON-NLS-1$
assertEquals("Should not have run any targets", 0, AntTestChecker.getDefault().getTargetsStartedCount()); //$NON-NLS-1$
}
/**
- * Tests specifying both a non-existent target and an existent target in the command line
+ * Tests specifying both a non-existent target and an existent target in the
+ * command line
*
*/
@Test
public void testSpecifyBothBadAndGoodTargetsAsArg() throws CoreException {
run("TestForEcho.xml", new String[] { "echo2", "Test for Echo" }, false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- assertTrue("Should be an unknown target message", AntTestChecker.getDefault().getLoggedMessage(5).contains("Unknown target")); //$NON-NLS-1$ //$NON-NLS-2$
- assertTrue("Should be an unknown target message", AntTestChecker.getDefault().getLoggedMessage(5).contains("echo2")); //$NON-NLS-1$ //$NON-NLS-2$
- assertEquals("Should have run the Test for Echo target", 5, AntTestChecker.getDefault().getTargetsStartedCount()); //$NON-NLS-1$
+ assertTrue("Should be an unknown target message", //$NON-NLS-1$
+ AntTestChecker.getDefault().getLoggedMessage(5).contains("Unknown target")); //$NON-NLS-1$
+ assertTrue("Should be an unknown target message", //$NON-NLS-1$
+ AntTestChecker.getDefault().getLoggedMessage(5).contains("echo2")); //$NON-NLS-1$
+ assertEquals("Should have run the Test for Echo target", 5, //$NON-NLS-1$
+ AntTestChecker.getDefault().getTargetsStartedCount());
}
/**
@@ -350,8 +323,9 @@
@Test
public void testSpecifyTargetAsArg() throws CoreException {
run("echoing.xml", new String[] { "echo3" }, false); //$NON-NLS-1$ //$NON-NLS-2$
- assertTrue("3 messages should have been logged; was " //$NON-NLS-1$
- + AntTestChecker.getDefault().getMessagesLoggedCount(), AntTestChecker.getDefault().getMessagesLoggedCount() == 3);
+ assertEquals("3 messages should have been logged; was " //$NON-NLS-1$
+ + AntTestChecker.getDefault().getMessagesLoggedCount(), 3,
+ AntTestChecker.getDefault().getMessagesLoggedCount());
assertSuccessful();
}
@@ -361,8 +335,9 @@
@Test
public void testSpecifyTargetAsArgWithOtherOptions() throws CoreException {
run("echoing.xml", new String[] { "-logfile", "TestLogFile.txt", "echo3" }, false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- assertTrue("4 messages should have been logged; was " //$NON-NLS-1$
- + AntTestChecker.getDefault().getMessagesLoggedCount(), AntTestChecker.getDefault().getMessagesLoggedCount() == 4);
+ assertEquals("4 messages should have been logged; was " //$NON-NLS-1$
+ + AntTestChecker.getDefault().getMessagesLoggedCount(), 4,
+ AntTestChecker.getDefault().getMessagesLoggedCount());
List<String> messages = AntTestChecker.getDefault().getMessages();
// ensure that echo3 target executed and only that target
assertTrue("echo3 target not executed", messages.get(2).equals("echo3")); //$NON-NLS-1$ //$NON-NLS-2$
@@ -375,8 +350,9 @@
@Test
public void testSpecifyTargetsAsArgWithOtherOptions() throws CoreException {
run("echoing.xml", new String[] { "-logfile", "TestLogFile.txt", "echo2", "echo3" }, false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- assertTrue("5 messages should have been logged; was " //$NON-NLS-1$
- + AntTestChecker.getDefault().getMessagesLoggedCount(), AntTestChecker.getDefault().getMessagesLoggedCount() == 5);
+ assertEquals("5 messages should have been logged; was " //$NON-NLS-1$
+ + AntTestChecker.getDefault().getMessagesLoggedCount(), 5,
+ AntTestChecker.getDefault().getMessagesLoggedCount());
List<String> messages = AntTestChecker.getDefault().getMessages();
// ensure that echo2 target executed
assertTrue("echo2 target not executed", messages.get(2).equals("echo2")); //$NON-NLS-1$ //$NON-NLS-2$
@@ -389,8 +365,9 @@
@Test
public void testSpecifyTargetAsArgAndQuiet() throws CoreException {
run("echoing.xml", new String[] { "-logfile", "TestLogFile.txt", "echo3", "-quiet" }, false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- assertTrue("2 messages should have been logged; was " //$NON-NLS-1$
- + AntTestChecker.getDefault().getMessagesLoggedCount(), AntTestChecker.getDefault().getMessagesLoggedCount() == 2);
+ assertEquals("2 messages should have been logged; was " //$NON-NLS-1$
+ + AntTestChecker.getDefault().getMessagesLoggedCount(), 2,
+ AntTestChecker.getDefault().getMessagesLoggedCount());
}
/**
@@ -400,8 +377,10 @@
public void testMinusD() throws CoreException {
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$
+ assertTrue("eclipse.is.cool should have been set as true", //$NON-NLS-1$
+ "true".equals(AntTestChecker.getDefault().getUserProperty("eclipse.is.cool"))); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("AntTests should have a value of testing", //$NON-NLS-1$
+ "testing".equals(AntTestChecker.getDefault().getUserProperty("AntTests"))); //$NON-NLS-1$ //$NON-NLS-2$
assertNull("my.name was not set and should be null", AntTestChecker.getDefault().getUserProperty("my.name")); //$NON-NLS-1$ //$NON-NLS-2$
}
@@ -413,8 +392,10 @@
public void testMinusDMinusd() throws CoreException {
run("echoing.xml", new String[] { "-d", "-DAntTests=testing", "-Declipse.is.cool=true" }, false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
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$
+ assertTrue("eclipse.is.cool should have been set as true", //$NON-NLS-1$
+ "true".equals(AntTestChecker.getDefault().getUserProperty("eclipse.is.cool"))); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("AntTests should have a value of testing", //$NON-NLS-1$
+ "testing".equals(AntTestChecker.getDefault().getUserProperty("AntTests"))); //$NON-NLS-1$ //$NON-NLS-2$
assertNull("my.name was not set and should be null", AntTestChecker.getDefault().getUserProperty("my.name")); //$NON-NLS-1$ //$NON-NLS-2$
}
@@ -423,7 +404,8 @@
public void testMinusDAndGlobalProperties() throws CoreException {
run("echoing.xml", new String[] { "-DAntTests=testing", "-Declipse.is.cool=true" }, false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
assertSuccessful();
- assertTrue("eclipse.running should have been set as true", "true".equals(AntTestChecker.getDefault().getUserProperty("eclipse.running"))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ assertTrue("eclipse.running should have been set as true", //$NON-NLS-1$
+ "true".equals(AntTestChecker.getDefault().getUserProperty("eclipse.running"))); //$NON-NLS-1$ //$NON-NLS-2$
assertNotNull("eclipse.home should have been set", AntTestChecker.getDefault().getUserProperty("eclipse.home")); //$NON-NLS-1$ //$NON-NLS-2$
}
@@ -434,8 +416,10 @@
public void testMinusDEmpty() throws CoreException {
run("echoing.xml", new String[] { "-D=emptyStringIsMyName", "-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("\"\" should have a value of emptyStringIsMyName", "emptyStringIsMyName".equals(AntTestChecker.getDefault().getUserProperty(""))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ assertTrue("eclipse.is.cool should have been set as true", //$NON-NLS-1$
+ "true".equals(AntTestChecker.getDefault().getUserProperty("eclipse.is.cool"))); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("\"\" should have a value of emptyStringIsMyName", //$NON-NLS-1$
+ "emptyStringIsMyName".equals(AntTestChecker.getDefault().getUserProperty(""))); //$NON-NLS-1$ //$NON-NLS-2$
assertNull("my.name was not set and should be null", AntTestChecker.getDefault().getUserProperty("my.name")); //$NON-NLS-1$ //$NON-NLS-2$
}
@@ -446,21 +430,27 @@
public void testMinusDWithSpaces() throws CoreException {
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$
+ assertTrue("eclipse.is.cool should have been set as true", //$NON-NLS-1$
+ "true".equals(AntTestChecker.getDefault().getUserProperty("eclipse.is.cool"))); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("AntTests should have a value of testing", //$NON-NLS-1$
+ "testing".equals(AntTestChecker.getDefault().getUserProperty("AntTests"))); //$NON-NLS-1$ //$NON-NLS-2$
assertNull("my.name was not set and should be null", AntTestChecker.getDefault().getUserProperty("my.name")); //$NON-NLS-1$ //$NON-NLS-2$
}
/**
- * Tests specifying properties when the user has incorrectly specified "-Debug" Bug 40935
+ * Tests specifying properties when the user has incorrectly specified "-Debug"
+ * Bug 40935
*/
@Test
public void testPropertiesWithMinusDebug() throws CoreException {
run("echoing.xml", new String[] { "-Debug", "-DAntTests= testing", "-Declipse.is.cool= true" }, false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- assertTrue("\"-Debug\" should be flagged as an unknown argument", "Unknown argument: -Debug".equals(AntTestChecker.getDefault().getMessages().get(0))); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("\"-Debug\" should be flagged as an unknown argument", //$NON-NLS-1$
+ "Unknown argument: -Debug".equals(AntTestChecker.getDefault().getMessages().get(0))); //$NON-NLS-1$
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$
+ assertTrue("eclipse.is.cool should have been set as true", //$NON-NLS-1$
+ "true".equals(AntTestChecker.getDefault().getUserProperty("eclipse.is.cool"))); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("AntTests should have a value of testing", //$NON-NLS-1$
+ "testing".equals(AntTestChecker.getDefault().getUserProperty("AntTests"))); //$NON-NLS-1$ //$NON-NLS-2$
assertNull("my.name was not set and should be null", AntTestChecker.getDefault().getUserProperty("my.name")); //$NON-NLS-1$ //$NON-NLS-2$
}
@@ -470,25 +460,23 @@
@Test
public void testMinusDebug() throws CoreException {
run("echoing.xml", new String[] { "-Debug" }); //$NON-NLS-1$ //$NON-NLS-2$
- assertTrue("\"-Debug\" should be flagged as an unknown argument", "Unknown argument: -Debug".equals(AntTestChecker.getDefault().getMessages().get(0))); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("\"-Debug\" should be flagged as an unknown argument", //$NON-NLS-1$
+ "Unknown argument: -Debug".equals(AntTestChecker.getDefault().getMessages().get(0))); //$NON-NLS-1$
assertSuccessful();
}
@Test
public void testPropertyFileWithNoArg() {
- try {
- run("TestForEcho.xml", new String[] { "-propertyfile" }); //$NON-NLS-1$ //$NON-NLS-2$
- }
- catch (CoreException ce) {
- String msg = AntTestChecker.getDefault().getMessages().get(0);
- assertTrue("Message incorrect!: " + msg, msg.equals("You must specify a property filename when using the -propertyfile argument")); //$NON-NLS-1$ //$NON-NLS-2$
- return;
- }
- assertTrue("You must specify a property filename when using the -propertyfile argument", false); //$NON-NLS-1$
+ assertThrows("You must specify a property filename when using the -propertyfile argument", CoreException.class, //$NON-NLS-1$
+ () -> run("TestForEcho.xml", new String[] { "-propertyfile" })); //$NON-NLS-1$ //$NON-NLS-2$
+ String msg = AntTestChecker.getDefault().getMessages().get(0);
+ assertTrue("Message incorrect!: " + msg, //$NON-NLS-1$
+ msg.equals("You must specify a property filename when using the -propertyfile argument")); //$NON-NLS-1$
}
/**
- * A build should succeed when a property file is not found. The error is reported and the build continues.
+ * A build should succeed when a property file is not found. The error is
+ * reported and the build continues.
*/
@Test
public void testPropertyFileFileNotFound() throws CoreException {
@@ -503,98 +491,91 @@
public void testPropertyFile() throws CoreException {
run("TestForEcho.xml", new String[] { "-propertyfile", getPropertyFileName() }); //$NON-NLS-1$ //$NON-NLS-2$
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$
+ assertTrue("eclipse.is.cool should have been set as Yep", //$NON-NLS-1$
+ "Yep".equals(AntTestChecker.getDefault().getUserProperty("eclipse.is.cool"))); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("AntTests should have a value of testing", //$NON-NLS-1$
+ "testing from properties file".equals(AntTestChecker.getDefault().getUserProperty("AntTests"))); //$NON-NLS-1$ //$NON-NLS-2$
assertNull("my.name was not set and should be null", AntTestChecker.getDefault().getUserProperty("my.name")); //$NON-NLS-1$ //$NON-NLS-2$
}
@Test
public void testPropertyFileWithMinusDTakingPrecedence() throws CoreException {
- run("echoing.xml", new String[] { "-propertyfile", getPropertyFileName(), "-DAntTests=testing", "-Declipse.is.cool=true" }, false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ run("echoing.xml", //$NON-NLS-1$
+ new String[] { "-propertyfile", getPropertyFileName(), "-DAntTests=testing", "-Declipse.is.cool=true" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ false);
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$
+ assertTrue("eclipse.is.cool should have been set as true", //$NON-NLS-1$
+ "true".equals(AntTestChecker.getDefault().getUserProperty("eclipse.is.cool"))); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("AntTests should have a value of testing", //$NON-NLS-1$
+ "testing".equals(AntTestChecker.getDefault().getUserProperty("AntTests"))); //$NON-NLS-1$ //$NON-NLS-2$
assertNull("my.name was not set and should be null", AntTestChecker.getDefault().getUserProperty("my.name")); //$NON-NLS-1$ //$NON-NLS-2$
}
@Test
public void testInputHandlerWithNoArg() {
- try {
- run("TestForEcho.xml", new String[] { "-inputhandler" }); //$NON-NLS-1$ //$NON-NLS-2$
- }
- catch (CoreException ce) {
- String msg = ce.getMessage();
- assertTrue("Message incorrect!: " + msg, msg.equals("You must specify a classname when using the -inputhandler argument")); //$NON-NLS-1$ //$NON-NLS-2$
- return;
- }
- assertTrue("You must specify a classname when using the -inputhandler argument", false); //$NON-NLS-1$
+ CoreException ce = assertThrows("You must specify a classname when using the -inputhandler argument", //$NON-NLS-1$
+ CoreException.class, () -> run("TestForEcho.xml", new String[] { "-inputhandler" })); //$NON-NLS-1$ //$NON-NLS-2$
+ String msg = ce.getMessage();
+ assertTrue("Message incorrect!: " + msg, //$NON-NLS-1$
+ msg.equals("You must specify a classname when using the -inputhandler argument")); //$NON-NLS-1$
}
/**
- * Tests the "-inputhandler" option with two handlers specified...only one is allowed
+ * Tests the "-inputhandler" option with two handlers specified...only one is
+ * allowed
*/
@Test
public void testInputHandlerMultiple() {
- try {
- run("TestForEcho.xml", new String[] { "-inputhandler", "org.apache.tools.ant.input.DefaultInputHandler", "-q", "-inputhandler", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- "org.apache.tools.ant.input.DefaultInputHandler" }); //$NON-NLS-1$
- }
- catch (CoreException ce) {
- String msg = ce.getMessage();
- assertTrue("Message incorrect!: " + msg, msg.equals("Only one input handler class may be specified.")); //$NON-NLS-1$ //$NON-NLS-2$
- return;
- }
- assertTrue("As only one input handler can be specified", false); //$NON-NLS-1$
+ CoreException ce = assertThrows("As only one input handler can be specified", CoreException.class, //$NON-NLS-1$
+ () -> run("TestForEcho.xml", //$NON-NLS-1$
+ new String[] { "-inputhandler", "org.apache.tools.ant.input.DefaultInputHandler", "-q", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ "-inputhandler", //$NON-NLS-1$
+ "org.apache.tools.ant.input.DefaultInputHandler" })); //$NON-NLS-1$
+ String msg = ce.getMessage();
+ assertTrue("Message incorrect!: " + msg, msg.equals("Only one input handler class may be specified.")); //$NON-NLS-1$ //$NON-NLS-2$
}
/**
- * Tests the "-inputhandler" option with a input handler that is not an instance of InputHandler
+ * Tests the "-inputhandler" option with a input handler that is not an instance
+ * of InputHandler
*/
@Test
public void testInputHandlerBad() {
- try {
- run("TestForEcho.xml", new String[] { "-inputhandler", "java.lang.StringBuffer" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
- catch (CoreException ce) {
- String msg = ce.getMessage();
- assertTrue("Message incorrect!: " //$NON-NLS-1$
- + msg, msg.equals("The specified input handler class java.lang.StringBuffer does not implement the org.apache.tools.ant.input.InputHandler interface")); //$NON-NLS-1$
- return;
- }
- assertTrue("Incorrect inputhandler", false); //$NON-NLS-1$
+ CoreException ce = assertThrows("Incorrect inputhandler", CoreException.class, //$NON-NLS-1$
+ () -> run("TestForEcho.xml", new String[] { "-inputhandler", "java.lang.StringBuffer" })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ String msg = ce.getMessage();
+ assertTrue("Message incorrect!: " //$NON-NLS-1$
+ + msg,
+ msg.equals(
+ "The specified input handler class java.lang.StringBuffer does not implement the org.apache.tools.ant.input.InputHandler interface")); //$NON-NLS-1$
}
/**
- * Tests the "-inputhandler" option with a input handler that is not a defined class
+ * Tests the "-inputhandler" option with a input handler that is not a defined
+ * class
*/
@Test
public void testInputHandlerBad2() {
- try {
- run("TestForEcho.xml", new String[] { "-inputhandler", "ja.lang.StringBuffer" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
- catch (CoreException ce) {
- String msg = ce.getMessage();
- assertTrue("Message incorrect!: " + msg, msg.startsWith("Unable to instantiate specified input handler class ja.lang.StringBuffer")); //$NON-NLS-1$ //$NON-NLS-2$
- return;
- }
- assertTrue("Incorrect inputhandler", false); //$NON-NLS-1$
+ CoreException ce = assertThrows("Incorrect inputhandler", CoreException.class, //$NON-NLS-1$
+ () -> run("TestForEcho.xml", new String[] { "-inputhandler", "ja.lang.StringBuffer" })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ String msg = ce.getMessage();
+ assertTrue("Message incorrect!: " + msg, //$NON-NLS-1$
+ msg.startsWith("Unable to instantiate specified input handler class ja.lang.StringBuffer")); //$NON-NLS-1$
}
/**
- * Tests the "-inputhandler" option with a test input handler and the -noinput option
+ * Tests the "-inputhandler" option with a test input handler and the -noinput
+ * option
*/
@Test
public void testInputHandlerWithMinusNoInput() {
- try {
- run("input.xml", new String[] { "-inputhandler", "org.eclipse.ant.tests.core.support.inputHandlers.AntTestInputHandler", "-noinput" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- }
- catch (CoreException ce) {
- assertTrue("Message incorrect: " //$NON-NLS-1$
- + ce.getMessage(), ce.getMessage().endsWith("Unable to respond to input request likely as a result of specifying the -noinput command")); //$NON-NLS-1$
- return;
- }
-
- assertTrue("Build should have failed", false); //$NON-NLS-1$
+ CoreException ce = assertThrows("Build should have failed", CoreException.class, //$NON-NLS-1$
+ () -> run("input.xml", new String[] { "-inputhandler", //$NON-NLS-1$ //$NON-NLS-2$
+ "org.eclipse.ant.tests.core.support.inputHandlers.AntTestInputHandler", "-noinput" })); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("Message incorrect: " //$NON-NLS-1$
+ + ce.getMessage(),
+ ce.getMessage().endsWith(
+ "Unable to respond to input request likely as a result of specifying the -noinput command")); //$NON-NLS-1$
}
/**
@@ -602,24 +583,21 @@
*/
@Test
public void testMinusNoInput() {
- try {
- run("input.xml", new String[] { "-noinput" }); //$NON-NLS-1$ //$NON-NLS-2$
- }
- catch (CoreException ce) {
- assertTrue("Message incorrect: " + ce.getMessage(), ce.getMessage().endsWith("Failed to read input from Console.")); //$NON-NLS-1$ //$NON-NLS-2$
- return;
- }
-
- assertTrue("Build should have failed", false); //$NON-NLS-1$
+ CoreException ce = assertThrows("Build should have failed", CoreException.class, //$NON-NLS-1$
+ () -> run("input.xml", new String[] { "-noinput" })); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("Message incorrect: " + ce.getMessage(), //$NON-NLS-1$
+ ce.getMessage().endsWith("Failed to read input from Console.")); //$NON-NLS-1$
}
/**
- * Tests the "-inputhandler" option with a test input handler Order after the noinput tests so that we test we are resetting the system property
+ * Tests the "-inputhandler" option with a test input handler Order after the
+ * noinput tests so that we test we are resetting the system property
*/
@Test
public void testInputHandler() throws CoreException {
- run("input.xml", new String[] { "-inputhandler", "org.eclipse.ant.tests.core.support.inputHandlers.AntTestInputHandler" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ run("input.xml", new String[] { "-inputhandler", //$NON-NLS-1$ //$NON-NLS-2$
+ "org.eclipse.ant.tests.core.support.inputHandlers.AntTestInputHandler" }); //$NON-NLS-1$
assertSuccessful();
String msg = AntTestChecker.getDefault().getMessages().get(1);
assertTrue("Message incorrect: " + msg, msg.equals("testing handling input requests")); //$NON-NLS-1$ //$NON-NLS-2$
@@ -637,8 +615,7 @@
String msg = AntTestChecker.getDefault().getMessages().get(0);
assertTrue("Message incorrect: " + msg, msg.equals("------- Ant diagnostics report -------")); //$NON-NLS-1$ //$NON-NLS-2$
- }
- finally {
+ } finally {
restorePreferenceDefaults();
}
}
@@ -651,8 +628,7 @@
try {
run("input.xml", new String[] { "-diagnostics" }); //$NON-NLS-1$ //$NON-NLS-2$
- }
- finally {
+ } finally {
restorePreferenceDefaults();
}
// we are looking for the ant.home entry
@@ -694,18 +670,14 @@
*/
@Test
public void testMinusKeepGoing() {
- try {
- run("failingTarget.xml", new String[] { "-keep-going" }, false); //$NON-NLS-1$ //$NON-NLS-2$
- }
- catch (CoreException be) {
- assertTrue("4 messages should have been logged; was " //$NON-NLS-1$
- + AntTestChecker.getDefault().getMessagesLoggedCount(), AntTestChecker.getDefault().getMessagesLoggedCount() == 4);
- assertTrue("Incorrect message:" //$NON-NLS-1$
- + AntTestChecker.getDefault().getLoggedMessage(1), "Still echo on failure".equals(AntTestChecker.getDefault().getLoggedMessage(1))); //$NON-NLS-1$
- return;
- }
-
- assertTrue("The build should have failed", false); //$NON-NLS-1$
+ assertThrows("The build should have failed", CoreException.class, //$NON-NLS-1$
+ () -> run("failingTarget.xml", new String[] { "-keep-going" }, false)); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("4 messages should have been logged; was " //$NON-NLS-1$
+ + AntTestChecker.getDefault().getMessagesLoggedCount(), 4,
+ AntTestChecker.getDefault().getMessagesLoggedCount());
+ assertTrue("Incorrect message:" //$NON-NLS-1$
+ + AntTestChecker.getDefault().getLoggedMessage(1),
+ "Still echo on failure".equals(AntTestChecker.getDefault().getLoggedMessage(1))); //$NON-NLS-1$
}
/**
@@ -713,17 +685,13 @@
*/
@Test
public void testMinusK() {
- try {
- run("failingTarget.xml", new String[] { "-k" }, false); //$NON-NLS-1$ //$NON-NLS-2$
- }
- catch (CoreException be) {
- assertTrue("4 messages should have been logged; was " //$NON-NLS-1$
- + AntTestChecker.getDefault().getMessagesLoggedCount(), AntTestChecker.getDefault().getMessagesLoggedCount() == 4);
- assertTrue("Incorrect message:" //$NON-NLS-1$
- + AntTestChecker.getDefault().getLoggedMessage(1), "Still echo on failure".equals(AntTestChecker.getDefault().getLoggedMessage(1))); //$NON-NLS-1$
- return;
- }
-
- assertTrue("The build should have failed", false); //$NON-NLS-1$
+ assertThrows("The build should have failed", CoreException.class, //$NON-NLS-1$
+ () -> run("failingTarget.xml", new String[] { "-k" }, false)); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("4 messages should have been logged; was " //$NON-NLS-1$
+ + AntTestChecker.getDefault().getMessagesLoggedCount(), 4,
+ AntTestChecker.getDefault().getMessagesLoggedCount());
+ assertTrue("Incorrect message:" //$NON-NLS-1$
+ + AntTestChecker.getDefault().getLoggedMessage(1),
+ "Still echo on failure".equals(AntTestChecker.getDefault().getLoggedMessage(1))); //$NON-NLS-1$
}
}
\ No newline at end of file
diff --git a/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/tests/TargetTests.java b/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/tests/TargetTests.java
index 2f3c026..c607033 100644
--- a/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/tests/TargetTests.java
+++ b/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/tests/TargetTests.java
@@ -16,6 +16,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import java.io.File;
@@ -48,20 +49,19 @@
}
/**
- * Ensures that targets are found in a buildfile with a fileset based on ant_home (that ant_home is set at parse time) Bug 42926.
+ * Ensures that targets are found in a buildfile with a fileset based on
+ * ant_home (that ant_home is set at parse time) Bug 42926.
*/
@Test
public void testGetTargetsWithAntHome() {
System.getProperties().remove("ant.home"); //$NON-NLS-1$
- try {
- getTargets("Bug42926.xml"); //$NON-NLS-1$
- }
- catch (CoreException ce) {
- // classpathref was successful but the task is not defined
- String message = ce.getMessage();
- assertTrue("Core exception message not as expected: " //$NON-NLS-1$
- + message, message.endsWith("Bug42926.xml:7: taskdef class com.foo.SomeTask cannot be found\n using the classloader AntClassLoader[]")); //$NON-NLS-1$
- }
+ CoreException ce = assertThrows(CoreException.class, () -> getTargets("Bug42926.xml")); //$NON-NLS-1$
+ // classpathref was successful but the task is not defined
+ String message = ce.getMessage();
+ assertTrue("Core exception message not as expected: " //$NON-NLS-1$
+ + message,
+ message.endsWith(
+ "Bug42926.xml:7: taskdef class com.foo.SomeTask cannot be found\n using the classloader AntClassLoader[]")); //$NON-NLS-1$
}
/**
diff --git a/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/tests/TaskTests.java b/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/tests/TaskTests.java
index 0891252..b227b27 100644
--- a/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/tests/TaskTests.java
+++ b/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/tests/TaskTests.java
@@ -14,6 +14,7 @@
package org.eclipse.ant.tests.core.tests;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import java.io.File;
@@ -80,16 +81,13 @@
AntCorePreferences prefs = AntCorePlugin.getPlugin().getPreferences();
prefs.setCustomTasks(new Task[] {});
try {
- run("CustomTask.xml"); //$NON-NLS-1$
- }
- catch (CoreException ce) {
- assertTrue("Exception from undefined task is incorrect", ce.getMessage().trim().endsWith("Action: Check that any <presetdef>/<macrodef> declarations have taken place.")); //$NON-NLS-1$ //$NON-NLS-2$
- return;
- }
- finally {
+ CoreException ce = assertThrows("Build should have failed as task no longer defined", CoreException.class, //$NON-NLS-1$
+ () -> run("CustomTask.xml")); //$NON-NLS-1$
+ assertTrue("Exception from undefined task is incorrect", ce.getMessage().trim() //$NON-NLS-1$
+ .endsWith("Action: Check that any <presetdef>/<macrodef> declarations have taken place.")); //$NON-NLS-1$
+ } finally {
restorePreferenceDefaults();
}
- assertTrue("Build should have failed as task no longer defined", false); //$NON-NLS-1$
}
@Test
@@ -97,7 +95,8 @@
try {
AntCorePreferences prefs = AntCorePlugin.getPlugin().getPreferences();
Task newTask = new Task();
- String path = getProject().getFolder(ProjectHelper.LIB_FOLDER).getFile("taskFolder").getLocation().toFile().getAbsolutePath(); //$NON-NLS-1$
+ String path = getProject().getFolder(ProjectHelper.LIB_FOLDER).getFile("taskFolder").getLocation().toFile() //$NON-NLS-1$
+ .getAbsolutePath();
IAntClasspathEntry entry = new AntClasspathEntry(path + File.separatorChar);
IAntClasspathEntry entries[] = prefs.getAdditionalClasspathEntries();
IAntClasspathEntry newEntries[] = new IAntClasspathEntry[entries.length + 1];
@@ -116,8 +115,7 @@
String msg = AntTestChecker.getDefault().getMessages().get(1);
assertEquals("Message incorrect: " + msg, "Testing Ant in Eclipse with a custom task", msg); //$NON-NLS-1$ //$NON-NLS-2$
assertSuccessful();
- }
- finally {
+ } finally {
restorePreferenceDefaults();
}
}
@@ -129,8 +127,7 @@
Property newProp = new Property("ROOTDIR", "..//resources"); //$NON-NLS-1$ //$NON-NLS-2$
prefs.setCustomProperties(new Property[] { newProp });
run("Bug34663.xml"); //$NON-NLS-1$
- }
- finally {
+ } finally {
restorePreferenceDefaults();
}
}
@@ -147,16 +144,13 @@
public void testTaskDefinedInExtensionPointHeadless() {
AntCorePlugin.getPlugin().setRunningHeadless(true);
try {
- run("ExtensionPointTask.xml"); //$NON-NLS-1$
- }
- catch (CoreException ce) {
- assertTrue("Exception from undefined task is incorrect", ce.getMessage().trim().endsWith("Action: Check that any <presetdef>/<macrodef> declarations have taken place.")); //$NON-NLS-1$ //$NON-NLS-2$
- return;
- }
- finally {
+ CoreException ce = assertThrows("Build should have failed as task was not defined to run in headless", //$NON-NLS-1$
+ CoreException.class, () -> run("ExtensionPointTask.xml")); //$NON-NLS-1$
+ assertTrue("Exception from undefined task is incorrect", ce.getMessage().trim() //$NON-NLS-1$
+ .endsWith("Action: Check that any <presetdef>/<macrodef> declarations have taken place.")); //$NON-NLS-1$
+ } finally {
AntCorePlugin.getPlugin().setRunningHeadless(false);
}
- assertTrue("Build should have failed as task was not defined to run in headless", false); //$NON-NLS-1$
}
@Test
diff --git a/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/tests/TypeTests.java b/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/tests/TypeTests.java
index cfcb592..42a2abf 100644
--- a/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/tests/TypeTests.java
+++ b/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/tests/TypeTests.java
@@ -14,6 +14,7 @@
package org.eclipse.ant.tests.core.tests;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import java.net.URL;
@@ -50,17 +51,15 @@
AntCorePreferences prefs = AntCorePlugin.getPlugin().getPreferences();
prefs.setCustomTypes(new Type[] {});
try {
- run("CustomType.xml"); //$NON-NLS-1$
- }
- catch (CoreException ce) {
+ CoreException ce = assertThrows("Build should have failed as type no longer defined", CoreException.class, //$NON-NLS-1$
+ () -> run("CustomType.xml")); //$NON-NLS-1$
assertTrue("Exception from undefined type is incorrect: " //$NON-NLS-1$
- + ce.getMessage(), ce.getMessage().trim().endsWith("Action: Check that any <presetdef>/<macrodef> declarations have taken place.")); //$NON-NLS-1$
- return;
- }
- finally {
+ + ce.getMessage(),
+ ce.getMessage().trim()
+ .endsWith("Action: Check that any <presetdef>/<macrodef> declarations have taken place.")); //$NON-NLS-1$
+ } finally {
restorePreferenceDefaults();
}
- assertTrue("Build should have failed as type no longer defined", false); //$NON-NLS-1$
}
@@ -76,16 +75,14 @@
public void testTypeDefinedInExtensionPointHeadless() {
AntCorePlugin.getPlugin().setRunningHeadless(true);
try {
- run("ExtensionPointType.xml"); //$NON-NLS-1$
- }
- catch (CoreException ce) {
+ CoreException ce = assertThrows("Build should have failed as type was not defined to run in headless", //$NON-NLS-1$
+ CoreException.class, () -> run("ExtensionPointType.xml")); //$NON-NLS-1$
assertTrue("Exception from undefined type is incorrect: " //$NON-NLS-1$
- + ce.getMessage(), ce.getMessage().trim().endsWith("Action: Check that any <presetdef>/<macrodef> declarations have taken place.")); //$NON-NLS-1$
- return;
- }
- finally {
+ + ce.getMessage(),
+ ce.getMessage().trim()
+ .endsWith("Action: Check that any <presetdef>/<macrodef> declarations have taken place.")); //$NON-NLS-1$
+ } finally {
AntCorePlugin.getPlugin().setRunningHeadless(false);
}
- assertTrue("Build should have failed as type was not defined to run in headless", false); //$NON-NLS-1$
}
}
\ No newline at end of file
diff --git a/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/RunToLineTests.java b/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/RunToLineTests.java
index 7aadf4a..a2cf9c3 100644
--- a/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/RunToLineTests.java
+++ b/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/RunToLineTests.java
@@ -51,7 +51,8 @@
class MyListener implements IPerspectiveListener2 {
@Override
- public void perspectiveChanged(IWorkbenchPage page, IPerspectiveDescriptor perspective, IWorkbenchPartReference partRef, String changeId) {
+ public void perspectiveChanged(IWorkbenchPage page, IPerspectiveDescriptor perspective,
+ IWorkbenchPartReference partRef, String changeId) {
if (partRef.getTitle().equals("breakpoints.xml") && changeId == IWorkbenchPage.CHANGE_EDITOR_OPEN) { //$NON-NLS-1$
synchronized (fLock) {
fEditor = (IEditorPart) partRef.getPart(true);
@@ -101,7 +102,8 @@
}
/**
- * Test a run to line, with an extra breakpoint, and preference to skip in a separate VM
+ * Test a run to line, with an extra breakpoint, and preference to skip in a
+ * separate VM
*
* @throws Exception
*/
@@ -131,22 +133,26 @@
}
/**
- * Runs to the given line number in the 'breakpoints.xml' buildfile, after stopping at the Starts from line 5 in the buildfile.
+ * Runs to the given line number in the 'breakpoints.xml' buildfile, after
+ * stopping at the Starts from line 5 in the buildfile.
*
- * @param lineNumber
- * line number to run to, ONE BASED
- * @param expectedLineNumber
- * the line number to be on after run-to-line (may differ from the target line number if the option to skip breakpoints is off).
- * @param skipBreakpoints
- * preference value for "skip breakpoints during run to line"
+ * @param lineNumber line number to run to, ONE BASED
+ * @param expectedLineNumber the line number to be on after run-to-line (may
+ * differ from the target line number if the option to
+ * skip breakpoints is off).
+ * @param skipBreakpoints preference value for "skip breakpoints during run
+ * to line"
* @throws Exception
*/
- public void runToLine(final int lineNumber, int expectedLineNumber, boolean skipBreakpoints, boolean sepVM) throws Exception {
+ public void runToLine(final int lineNumber, int expectedLineNumber, boolean skipBreakpoints, boolean sepVM)
+ throws Exception {
String fileName = "breakpoints"; //$NON-NLS-1$
AntLineBreakpoint breakpoint = createLineBreakpoint(5, fileName + ".xml"); //$NON-NLS-1$
- boolean restore = DebugUITools.getPreferenceStore().getBoolean(IDebugUIConstants.PREF_SKIP_BREAKPOINTS_DURING_RUN_TO_LINE);
- DebugUITools.getPreferenceStore().setValue(IDebugUIConstants.PREF_SKIP_BREAKPOINTS_DURING_RUN_TO_LINE, skipBreakpoints);
+ boolean restore = DebugUITools.getPreferenceStore()
+ .getBoolean(IDebugUIConstants.PREF_SKIP_BREAKPOINTS_DURING_RUN_TO_LINE);
+ DebugUITools.getPreferenceStore().setValue(IDebugUIConstants.PREF_SKIP_BREAKPOINTS_DURING_RUN_TO_LINE,
+ skipBreakpoints);
AntThread thread = null;
final IPerspectiveListener2 listener = new MyListener();
try {
@@ -190,11 +196,7 @@
editor.selectAndReveal(lineOffset, 0);
// run to line
adapter.runToLine(editor, editor.getSelectionProvider().getSelection(), suspendee);
- }
- catch (CoreException e) {
- exs[0] = e;
- }
- catch (BadLocationException e) {
+ } catch (CoreException | BadLocationException e) {
exs[0] = e;
}
};
@@ -207,11 +209,11 @@
IStackFrame topStackFrame = thread.getTopStackFrame();
assertNotNull("There must be a top stack frame", topStackFrame); //$NON-NLS-1$
assertEquals("wrong line", expectedLineNumber, topStackFrame.getLineNumber()); //$NON-NLS-1$
- }
- finally {
+ } finally {
terminateAndRemove(thread);
removeAllBreakpoints();
- DebugUITools.getPreferenceStore().setValue(IDebugUIConstants.PREF_SKIP_BREAKPOINTS_DURING_RUN_TO_LINE, restore);
+ DebugUITools.getPreferenceStore().setValue(IDebugUIConstants.PREF_SKIP_BREAKPOINTS_DURING_RUN_TO_LINE,
+ restore);
Runnable cleanup = () -> {
IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
activeWorkbenchWindow.removePerspectiveListener(listener);
diff --git a/ant/org.eclipse.ant.tests.ui/Ant Editor Tests/org/eclipse/ant/tests/ui/editor/formatter/XmlTagFormatterTest.java b/ant/org.eclipse.ant.tests.ui/Ant Editor Tests/org/eclipse/ant/tests/ui/editor/formatter/XmlTagFormatterTest.java
index aa1c0c4..b9a96a4 100644
--- a/ant/org.eclipse.ant.tests.ui/Ant Editor Tests/org/eclipse/ant/tests/ui/editor/formatter/XmlTagFormatterTest.java
+++ b/ant/org.eclipse.ant.tests.ui/Ant Editor Tests/org/eclipse/ant/tests/ui/editor/formatter/XmlTagFormatterTest.java
@@ -14,6 +14,8 @@
*******************************************************************************/
package org.eclipse.ant.tests.ui.editor.formatter;
+import static org.junit.Assert.assertThrows;
+
import java.util.List;
import org.eclipse.ant.internal.ui.editor.formatter.FormattingPreferences;
@@ -96,7 +98,8 @@
super(name);
}
- private FormattingPreferences getPreferences(final boolean wrapLongTags, final boolean alignCloseChar, final int maxLineWidth) {
+ private FormattingPreferences getPreferences(final boolean wrapLongTags, final boolean alignCloseChar,
+ final int maxLineWidth) {
return new FormattingPreferences() {
@@ -117,7 +120,8 @@
};
}
- private void simpleTest(String source, String target, FormattingPreferences prefs, String indent, String lineDelimiter) throws Exception {
+ private void simpleTest(String source, String target, FormattingPreferences prefs, String indent,
+ String lineDelimiter) throws Exception {
String result = XmlTagFormatter.format(source, prefs, indent, lineDelimiter);
assertEquals(target, result);
@@ -140,23 +144,11 @@
assertEquals("x:y", tagParser.getElementName("<x:y/>")); //$NON-NLS-1$ //$NON-NLS-2$
assertEquals("x:y", tagParser.getElementName("<x:y abc/>")); //$NON-NLS-1$ //$NON-NLS-2$
- Exception e1 = null;
- try {
- tagParser.getElementName("<>"); //$NON-NLS-1$
- }
- catch (Exception e) {
- e1 = e;
- }
+ Exception e1 = assertThrows(Exception.class, () -> tagParser.getElementName("<>")); //$NON-NLS-1$
assertNotNull(e1);
assertTrue(e1.getClass().isAssignableFrom(InnerClassFactory.ParseException.class));
- Exception e2 = null;
- try {
- tagParser.getElementName("<>"); //$NON-NLS-1$
- }
- catch (Exception e) {
- e2 = e;
- }
+ Exception e2 = assertThrows(Exception.class, () -> tagParser.getElementName("<>")); //$NON-NLS-1$
assertNotNull(e2);
assertTrue(e2.getClass().isAssignableFrom(InnerClassFactory.ParseException.class));
@@ -182,24 +174,14 @@
InnerClassFactory.validateAttributePair(attributePairs.get(1), "attribute2", "value2'"); //$NON-NLS-1$ //$NON-NLS-2$
// test parse errors - equals in the wrong place
- Exception e2 = null;
- try {
- attributePairs = tagParser.getAttibutes("<myElement attribute1=\"value1\" = attribute2=\"value2\" />"); //$NON-NLS-1$
- }
- catch (Exception e) {
- e2 = e;
- }
+ Exception e2 = assertThrows(Exception.class,
+ () -> tagParser.getAttibutes("<myElement attribute1=\"value1\" = attribute2=\"value2\" />")); //$NON-NLS-1$
assertNotNull(e2);
assertTrue(e2.getClass().isAssignableFrom(InnerClassFactory.ParseException.class));
// test parse errors - quotes in the wrong place
- Exception e3 = null;
- try {
- attributePairs = tagParser.getAttibutes("<myElement attribute1=\"\"value1\" attribute2=\"value2\" />"); //$NON-NLS-1$
- }
- catch (Exception e) {
- e3 = e;
- }
+ Exception e3 = assertThrows(Exception.class,
+ () -> tagParser.getAttibutes("<myElement attribute1=\"\"value1\" attribute2=\"value2\" />")); //$NON-NLS-1$
assertNotNull(e3);
assertTrue(e3.getClass().isAssignableFrom(InnerClassFactory.ParseException.class));
}
@@ -243,12 +225,14 @@
InnerClassFactory.TagFormatter tagFormatter = InnerClassFactory.createTagFormatter();
- boolean shouldWrap = tagFormatter.lineRequiresWrap("\t\t <myElement attribute1=\"value1\" attribute2=\"value2\" />", //$NON-NLS-1$
+ boolean shouldWrap = tagFormatter.lineRequiresWrap(
+ "\t\t <myElement attribute1=\"value1\" attribute2=\"value2\" />", //$NON-NLS-1$
70, 8);
- boolean shouldNotWrap = tagFormatter.lineRequiresWrap("\t\t <myElement attribute1=\"value1\" attribute2=\"value2\" />", //$NON-NLS-1$
+ boolean shouldNotWrap = tagFormatter.lineRequiresWrap(
+ "\t\t <myElement attribute1=\"value1\" attribute2=\"value2\" />", //$NON-NLS-1$
70, 8);
assertTrue(shouldWrap);
- assertTrue(!shouldNotWrap);
+ assertFalse(shouldNotWrap);
}
@@ -314,8 +298,8 @@
String lineSep = System.getProperty("line.separator"); //$NON-NLS-1$
assertEquals("<myElement attribute1=\"value1\"" + lineSep //$NON-NLS-1$
- + "\t\t attribute2=\"value2\" />", tagFormatter //$NON-NLS-1$
- .wrapTag(tag, dontAlignCloseChar, "\t\t ", lineSep)); //$NON-NLS-1$
+ + "\t\t attribute2=\"value2\" />", //$NON-NLS-1$
+ tagFormatter.wrapTag(tag, dontAlignCloseChar, "\t\t ", lineSep)); //$NON-NLS-1$
assertEquals("<myElement attribute1=\"value1\"" + lineSep //$NON-NLS-1$
+ "\t\t attribute2=\"value2\"" + lineSep + "\t\t />", //$NON-NLS-1$ //$NON-NLS-2$
@@ -324,8 +308,8 @@
tag.setClosed(false);
assertEquals("<myElement attribute1=\"value1\"" + lineSep //$NON-NLS-1$
- + "\t\t attribute2=\"value2\">", tagFormatter //$NON-NLS-1$
- .wrapTag(tag, dontAlignCloseChar, "\t\t ", lineSep)); //$NON-NLS-1$
+ + "\t\t attribute2=\"value2\">", //$NON-NLS-1$
+ tagFormatter.wrapTag(tag, dontAlignCloseChar, "\t\t ", lineSep)); //$NON-NLS-1$
assertEquals("<myElement attribute1=\"value1\"" + lineSep //$NON-NLS-1$
+ "\t\t attribute2=\"value2\"" + lineSep + "\t\t >", //$NON-NLS-1$ //$NON-NLS-2$
@@ -344,7 +328,7 @@
FormattingPreferences prefs = getPreferences(true, false, 60);
simpleTest(source1, source1, prefs, "\t", lineSep); //$NON-NLS-1$
- String source2 = "<echo file=\"foo\"/bar/baz></echo>"; //$NON-NLS-1$
+ String source2 = "<echo file=\"foo\"/bar/baz></echo>"; //$NON-NLS-1$
simpleTest(source2, source2, prefs, "\t", lineSep); //$NON-NLS-1$
}
}
diff --git a/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/BuildTests.java b/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/BuildTests.java
index 4802876..323095a 100644
--- a/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/BuildTests.java
+++ b/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/BuildTests.java
@@ -42,35 +42,37 @@
*/
public void testOutput() throws CoreException {
launch("echoing"); //$NON-NLS-1$
- assertTrue("Incorrect number of messages logged for build. Should be 8. Was " + ConsoleLineTracker.getNumberOfMessages(), ConsoleLineTracker.getNumberOfMessages() == 8); //$NON-NLS-1$
+ assertEquals("Incorrect number of messages logged for build. Should be 8. Was " //$NON-NLS-1$
+ + ConsoleLineTracker.getNumberOfMessages(), 8, ConsoleLineTracker.getNumberOfMessages());
String message = ConsoleLineTracker.getMessage(6);
- assertTrue("Incorrect last message. Should start with Total time:. Message: " + message, message.startsWith("Total time:")); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("Incorrect last message. Should start with Total time:. Message: " + message, //$NON-NLS-1$
+ message.startsWith("Total time:")); //$NON-NLS-1$
}
/**
- * This build will fail. With verbose on you should be presented with a full stack trace. Bug 82833
+ * This build will fail. With verbose on you should be presented with a full
+ * stack trace. Bug 82833
*/
public void testVerboseStackTrace() throws Exception {
launch("failingTarget", "-k -verbose"); //$NON-NLS-1$ //$NON-NLS-2$
assertEquals("Incorrect message", "BUILD FAILED", ConsoleLineTracker.getMessage(19)); //$NON-NLS-1$ //$NON-NLS-2$
- assertTrue("Incorrect message" + ConsoleLineTracker.getMessage(22), ConsoleLineTracker.getMessage(22).startsWith("\tat org.apache.tools.ant.taskdefs.Zip")); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("Incorrect message" + ConsoleLineTracker.getMessage(22), //$NON-NLS-1$
+ ConsoleLineTracker.getMessage(22).startsWith("\tat org.apache.tools.ant.taskdefs.Zip")); //$NON-NLS-1$
}
/**
- * Tests launching Ant and getting the build failed message logged to the console with associated link. Bug 42333 and 44565
+ * Tests launching Ant and getting the build failed message logged to the
+ * console with associated link. Bug 42333 and 44565
*/
- public void testBuildFailedMessage() throws CoreException {
+ public void testBuildFailedMessage() throws CoreException, BadLocationException {
launch("bad"); //$NON-NLS-1$
- assertTrue("Incorrect number of messages logged for build. Should be 10. Was " + ConsoleLineTracker.getNumberOfMessages(), ConsoleLineTracker.getNumberOfMessages() == 10); //$NON-NLS-1$
+ assertEquals("Incorrect number of messages logged for build. Should be 10. Was " //$NON-NLS-1$
+ + ConsoleLineTracker.getNumberOfMessages(), 10, ConsoleLineTracker.getNumberOfMessages());
String message = ConsoleLineTracker.getMessage(5);
- assertTrue("Incorrect last message. Should start with BUILD FAILED. Message: " + message, message.startsWith("BUILD FAILED")); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("Incorrect last message. Should start with BUILD FAILED. Message: " + message, //$NON-NLS-1$
+ message.startsWith("BUILD FAILED")); //$NON-NLS-1$
int offset = -1;
- try {
- offset = ConsoleLineTracker.getDocument().getLineOffset(4) + 30; // link to buildfile that failed
- }
- catch (BadLocationException e) {
- assertTrue("failed getting offset of line", false); //$NON-NLS-1$
- }
+ offset = ConsoleLineTracker.getDocument().getLineOffset(4) + 30; // link to buildfile that failed
IHyperlink link = getHyperlink(offset, ConsoleLineTracker.getDocument());
assertNotNull("No hyperlink found at offset " + offset, link); //$NON-NLS-1$
}
@@ -78,39 +80,29 @@
/**
* Tests launching Ant and that the correct links are in the console doc
*/
- public void testLinks() throws CoreException {
+ public void testLinks() throws CoreException, BadLocationException {
launch("build"); //$NON-NLS-1$
int offset = 25; // buildfile link
IHyperlink link = getHyperlink(offset, ConsoleLineTracker.getDocument());
assertNotNull("No hyperlink found at offset " + offset, link); //$NON-NLS-1$
activateLink(link);
- try {
- offset = ConsoleLineTracker.getDocument().getLineOffset(4) + 10; // echo link
- }
- catch (BadLocationException e) {
- assertTrue("failed getting offset of line", false); //$NON-NLS-1$
- }
+ offset = ConsoleLineTracker.getDocument().getLineOffset(4) + 10; // echo link
link = getHyperlink(offset, ConsoleLineTracker.getDocument());
assertNotNull("No hyperlink found at offset " + offset, link); //$NON-NLS-1$
activateLink(link);
}
/**
- * Tests launching Ant and that build failed presents links to the failures when multi-line.
+ * Tests launching Ant and that build failed presents links to the failures when
+ * multi-line.
*/
- public void testBuildFailedLinks() throws CoreException {
+ public void testBuildFailedLinks() throws CoreException, BadLocationException {
launch("102282"); //$NON-NLS-1$
- try {
- int offset = ConsoleLineTracker.getDocument().getLineOffset(9) + 10; // second line of build failed link
- IHyperlink link = getHyperlink(offset, ConsoleLineTracker.getDocument());
- assertNotNull("No hyperlink found at offset " + offset, link); //$NON-NLS-1$
- activateLink(link);
-
- }
- catch (BadLocationException e) {
- assertTrue("failed getting offset of line", false); //$NON-NLS-1$
- }
+ int offset = ConsoleLineTracker.getDocument().getLineOffset(9) + 10; // second line of build failed link
+ IHyperlink link = getHyperlink(offset, ConsoleLineTracker.getDocument());
+ assertNotNull("No hyperlink found at offset " + offset, link); //$NON-NLS-1$
+ activateLink(link);
}
/**
@@ -123,19 +115,15 @@
Color color = getColorAtOffset(offset, ConsoleLineTracker.getDocument());
assertNotNull("No color found at " + offset, color); //$NON-NLS-1$
assertEquals(AntUIPlugin.getPreferenceColor(IAntUIPreferenceConstants.CONSOLE_INFO_COLOR), color);
- try {
- offset = ConsoleLineTracker.getDocument().getLineOffset(4) + 10; // echo
- }
- catch (BadLocationException e) {
- assertTrue("failed getting offset of line", false); //$NON-NLS-1$
- }
+ offset = ConsoleLineTracker.getDocument().getLineOffset(4) + 10; // echo
color = getColorAtOffset(offset, ConsoleLineTracker.getDocument());
assertNotNull("No color found at " + offset, color); //$NON-NLS-1$
assertEquals(AntUIPlugin.getPreferenceColor(IAntUIPreferenceConstants.CONSOLE_WARNING_COLOR), color);
}
/**
- * Tests launching Ant in a separate vm and that the correct property substitions occur
+ * Tests launching Ant in a separate vm and that the correct property
+ * substitions occur
*/
public void testPropertySubstitution() throws CoreException {
ILaunchConfiguration config = getLaunchConfiguration("74840"); //$NON-NLS-1$
@@ -147,8 +135,10 @@
copy.setAttribute(IAntLaunchConstants.ATTR_ANT_PROPERTIES, properties);
launchAndTerminate(copy, 20000);
ConsoleLineTracker.waitForConsole();
- assertTrue("Incorrect number of messages logged for build. Should be 8. Was " + ConsoleLineTracker.getNumberOfMessages(), ConsoleLineTracker.getNumberOfMessages() == 8); //$NON-NLS-1$
- assertTrue("Incorrect echo message. Should not include unsubstituted property", !ConsoleLineTracker.getMessage(4).trim().startsWith("[echo] ${workspace_loc}")); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Incorrect number of messages logged for build. Should be 8. Was " //$NON-NLS-1$
+ + ConsoleLineTracker.getNumberOfMessages(), 8, ConsoleLineTracker.getNumberOfMessages());
+ assertFalse("Incorrect echo message. Should not include unsubstituted property", //$NON-NLS-1$
+ ConsoleLineTracker.getMessage(4).trim().startsWith("[echo] ${workspace_loc}")); //$NON-NLS-1$
}
/**
@@ -158,9 +148,11 @@
*/
public void testXmlLoggerListener() throws CoreException, FileNotFoundException {
launch("echoing", "-listener org.apache.tools.ant.XmlLogger"); //$NON-NLS-1$ //$NON-NLS-2$
- assertTrue("Incorrect number of messages logged for build. Should be 8. Was " + ConsoleLineTracker.getNumberOfMessages(), ConsoleLineTracker.getNumberOfMessages() == 8); //$NON-NLS-1$
+ assertEquals("Incorrect number of messages logged for build. Should be 8. Was " //$NON-NLS-1$
+ + ConsoleLineTracker.getNumberOfMessages(), 8, ConsoleLineTracker.getNumberOfMessages());
String message = ConsoleLineTracker.getMessage(6);
- assertTrue("Incorrect last message. Should start with Total time:. Message: " + message, message.startsWith("Total time:")); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("Incorrect last message. Should start with Total time:. Message: " + message, //$NON-NLS-1$
+ message.startsWith("Total time:")); //$NON-NLS-1$
// find the log file generated by the xml logger
getProject().getFolder("buildfiles").refreshLocal(IResource.DEPTH_INFINITE, null); //$NON-NLS-1$
File file = getBuildFile("log.xml"); //$NON-NLS-1$
@@ -169,14 +161,17 @@
}
/**
- * Tests launching Ant and getting the build failed message logged to the console. Bug 42333.
+ * Tests launching Ant and getting the build failed message logged to the
+ * console. Bug 42333.
*/
// public void testBuildFailedMessageDebug() throws CoreException {
// launchInDebug("bad");
- // assertTrue("Incorrect number of messages logged for build. Should be 35. Was " + ConsoleLineTracker.getNumberOfMessages(),
+ // assertTrue("Incorrect number of messages logged for build. Should be 35. Was
+ // " + ConsoleLineTracker.getNumberOfMessages(),
// ConsoleLineTracker.getNumberOfMessages() == 35);
// String message= ConsoleLineTracker.getMessage(33);
- // assertTrue("Incorrect last message. Should start with Build Failed:. Message: " + message, message.startsWith("BUILD FAILED:"));
+ // assertTrue("Incorrect last message. Should start with Build Failed:. Message:
+ // " + message, message.startsWith("BUILD FAILED:"));
// }
//
// /**
@@ -187,11 +182,13 @@
// launchInDebug("echoing");
// int offset= 0;
// try {
- // offset= ConsoleLineTracker.getDocument().getLineOffset(2) + 15; //buildfile line 3
+ // offset= ConsoleLineTracker.getDocument().getLineOffset(2) + 15; //buildfile
+ // line 3
// } catch (BadLocationException e) {
// assertTrue("failed getting offset of line", false);
// }
- // IConsoleHyperlink link= getHyperlink(offset, ConsoleLineTracker.getDocument());
+ // IConsoleHyperlink link= getHyperlink(offset,
+ // ConsoleLineTracker.getDocument());
// assertNotNull("No hyperlink found at offset " + offset, link);
//
// try {
@@ -211,13 +208,15 @@
// launchInDebug("echoing");
// int offset= 0;
// try {
- // offset= ConsoleLineTracker.getDocument().getLineOffset(2) + 15; //buildfile line 3
+ // offset= ConsoleLineTracker.getDocument().getLineOffset(2) + 15; //buildfile
+ // line 3
// } catch (BadLocationException e) {
// assertTrue("failed getting offset of line", false);
// }
// Color color= getColorAtOffset(offset, ConsoleLineTracker.getDocument());
// assertNotNull("No color found at " + offset, color);
- // assertEquals(AntUIPlugin.getPreferenceColor(IAntUIPreferenceConstants.CONSOLE_INFO_COLOR), color);
+ // assertEquals(AntUIPlugin.getPreferenceColor(IAntUIPreferenceConstants.CONSOLE_INFO_COLOR),
+ // color);
//
// try {
// offset= ConsoleLineTracker.getDocument().getLineOffset(4) + 3; //debug info
@@ -226,15 +225,18 @@
// }
// color= getColorAtOffset(offset, ConsoleLineTracker.getDocument());
// assertNotNull("No color found at " + offset, color);
- // assertEquals(AntUIPlugin.getPreferenceColor(IAntUIPreferenceConstants.CONSOLE_DEBUG_COLOR), color);
+ // assertEquals(AntUIPlugin.getPreferenceColor(IAntUIPreferenceConstants.CONSOLE_DEBUG_COLOR),
+ // color);
//
// try {
- // offset= ConsoleLineTracker.getDocument().getLineOffset(33) + 10; //echo line 33
+ // offset= ConsoleLineTracker.getDocument().getLineOffset(33) + 10; //echo line
+ // 33
// } catch (BadLocationException e) {
// assertTrue("failed getting offset of line", false);
// }
// color= getColorAtOffset(offset, ConsoleLineTracker.getDocument());
// assertNotNull("No color found at " + offset, color);
- // assertEquals(AntUIPlugin.getPreferenceColor(IAntUIPreferenceConstants.CONSOLE_WARNING_COLOR), color);
+ // assertEquals(AntUIPlugin.getPreferenceColor(IAntUIPreferenceConstants.CONSOLE_WARNING_COLOR),
+ // color);
// }
}
diff --git a/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/separateVM/SeparateVMTests.java b/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/separateVM/SeparateVMTests.java
index 06c00c5..8b2c355 100644
--- a/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/separateVM/SeparateVMTests.java
+++ b/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/separateVM/SeparateVMTests.java
@@ -47,7 +47,8 @@
}
/**
- * Checks that the expected line count has been reached and if not dump out what was tracked to System.err
+ * Checks that the expected line count has been reached and if not dump out what
+ * was tracked to System.err
*
* @param expectedLines
* @since 3.8.200
@@ -60,13 +61,15 @@
for (String string : lines) {
System.out.println('\t' + string);
}
- throw new TestAgainException("Test again - Incorrect number of messages logged for build - should be " + expectedLines + " but was " //$NON-NLS-1$ //$NON-NLS-2$
+ throw new TestAgainException("Test again - Incorrect number of messages logged for build - should be " //$NON-NLS-1$
+ + expectedLines + " but was " //$NON-NLS-1$
+ ConsoleLineTracker.getNumberOfMessages());
}
}
/**
- * Tests launching Ant in a separate VM and getting messages logged to the console.
+ * Tests launching Ant in a separate VM and getting messages logged to the
+ * console.
*/
public void testBuild() throws CoreException {
launch("echoingSepVM"); //$NON-NLS-1$
@@ -76,7 +79,8 @@
}
/**
- * Tests launching Ant in a separate VM and having an extra classpath entry designated to be available.
+ * Tests launching Ant in a separate VM and having an extra classpath entry
+ * designated to be available.
*/
public void testExtraClasspathEntries() throws CoreException {
launch("extensionPointSepVM"); //$NON-NLS-1$
@@ -86,53 +90,59 @@
}
/**
- * Tests launching Ant in a separate VM and having a property designated to be available.
+ * Tests launching Ant in a separate VM and having a property designated to be
+ * available.
*/
public void testProperties() throws CoreException {
launch("extensionPointSepVM"); //$NON-NLS-1$
assertLines(8);
assertTrue("Incorrect last message. Should start with [echo] ${property.ui.testing. Message: " //$NON-NLS-1$
- + ConsoleLineTracker.getMessage(3), ConsoleLineTracker.getMessage(3).trim().startsWith("[echo] ${property.ui.testing")); //$NON-NLS-1$
+ + ConsoleLineTracker.getMessage(3),
+ ConsoleLineTracker.getMessage(3).trim().startsWith("[echo] ${property.ui.testing")); //$NON-NLS-1$
assertTrue("Incorrect last message. Should start with [echo] hey. Message: " //$NON-NLS-1$
+ ConsoleLineTracker.getMessage(4), ConsoleLineTracker.getMessage(4).trim().startsWith("[echo] hey")); //$NON-NLS-1$
}
/**
- * Tests launching Ant in a separate VM and having an task designated to be available.
+ * Tests launching Ant in a separate VM and having an task designated to be
+ * available.
*/
public void testExtensionPointTask() throws CoreException {
launch("extensionPointTaskSepVM"); //$NON-NLS-1$
assertLines(7);
assertTrue("Incorrect message. Should start with [null] Testing Ant in Eclipse with a custom task2. Message: " //$NON-NLS-1$
- + ConsoleLineTracker.getMessage(2), ConsoleLineTracker.getMessage(2).trim().startsWith("[null] Testing Ant in Eclipse with a custom task2")); //$NON-NLS-1$
+ + ConsoleLineTracker.getMessage(2),
+ ConsoleLineTracker.getMessage(2).trim()
+ .startsWith("[null] Testing Ant in Eclipse with a custom task2")); //$NON-NLS-1$
assertTrue("Incorrect message. Should start with [null] Testing Ant in Eclipse with a custom task2. Message: " //$NON-NLS-1$
- + ConsoleLineTracker.getMessage(3), ConsoleLineTracker.getMessage(3).trim().startsWith("[null] Testing Ant in Eclipse with a custom task2")); //$NON-NLS-1$
+ + ConsoleLineTracker.getMessage(3),
+ ConsoleLineTracker.getMessage(3).trim()
+ .startsWith("[null] Testing Ant in Eclipse with a custom task2")); //$NON-NLS-1$
}
/**
- * Tests launching Ant in a separate VM and having a type designated to be available.
+ * Tests launching Ant in a separate VM and having a type designated to be
+ * available.
*/
public void testExtensionPointType() throws CoreException {
launch("extensionPointTypeSepVM"); //$NON-NLS-1$
assertLines(6);
assertTrue("Incorrect message. Should start with [echo] Ensure that an extension point defined type. Message: " //$NON-NLS-1$
- + ConsoleLineTracker.getMessage(2), ConsoleLineTracker.getMessage(2).trim().startsWith("[echo] Ensure that an extension point defined type")); //$NON-NLS-1$
+ + ConsoleLineTracker.getMessage(2),
+ ConsoleLineTracker.getMessage(2).trim()
+ .startsWith("[echo] Ensure that an extension point defined type")); //$NON-NLS-1$
}
/**
- * Tests launching Ant in a separate VM and that the correct links are in the console doc
+ * Tests launching Ant in a separate VM and that the correct links are in the
+ * console doc
*/
- public void testLinks() throws CoreException {
+ public void testLinks() throws CoreException, BadLocationException {
launch("echoingSepVM"); //$NON-NLS-1$
int offset = 15; // buildfile link
IHyperlink link = getHyperlink(offset, ConsoleLineTracker.getDocument());
assertNotNull("No hyperlink found at offset " + offset, link); //$NON-NLS-1$
- try {
- offset = ConsoleLineTracker.getDocument().getLineOffset(2) + 10; // echo link
- }
- catch (BadLocationException e) {
- assertTrue("failed getting offset of line", false); //$NON-NLS-1$
- }
+ offset = ConsoleLineTracker.getDocument().getLineOffset(2) + 10; // echo link
link = getHyperlink(offset, ConsoleLineTracker.getDocument());
assertNotNull("No hyperlink found at offset " + offset, link); //$NON-NLS-1$
}
@@ -140,22 +150,17 @@
/**
* Tests launching Ant and that build failed presents links to the failures
*/
- public void testBuildFailedLinks() throws CoreException {
- try {
- launch("102282"); //$NON-NLS-1$
- int offset = ConsoleLineTracker.getDocument().getLineOffset(9) + 10; // second line of build failed link
- IHyperlink link = getHyperlink(offset, ConsoleLineTracker.getDocument());
- assertNotNull("No hyperlink found at offset " + offset, link); //$NON-NLS-1$
- activateLink(link);
-
- }
- catch (BadLocationException e) {
- assertTrue("failed getting offset of line", false); //$NON-NLS-1$
- }
+ public void testBuildFailedLinks() throws CoreException, BadLocationException {
+ launch("102282"); //$NON-NLS-1$
+ int offset = ConsoleLineTracker.getDocument().getLineOffset(9) + 10; // second line of build failed link
+ IHyperlink link = getHyperlink(offset, ConsoleLineTracker.getDocument());
+ assertNotNull("No hyperlink found at offset " + offset, link); //$NON-NLS-1$
+ activateLink(link);
}
/**
- * Tests launching Ant in a separate VM and that the correct colors are in the console doc
+ * Tests launching Ant in a separate VM and that the correct colors are in the
+ * console doc
*/
public void testColor() throws BadLocationException, CoreException {
launch("echoingSepVM"); //$NON-NLS-1$
@@ -163,35 +168,34 @@
Color color = getColorAtOffset(offset, ConsoleLineTracker.getDocument());
assertNotNull("No color found at " + offset, color); //$NON-NLS-1$
assertEquals(color, AntUIPlugin.getPreferenceColor(IAntUIPreferenceConstants.CONSOLE_INFO_COLOR));
- try {
- offset = ConsoleLineTracker.getDocument().getLineOffset(2) + 10; // echo link
- }
- catch (BadLocationException e) {
- assertTrue("failed getting offset of line", false); //$NON-NLS-1$
- }
+ offset = ConsoleLineTracker.getDocument().getLineOffset(2) + 10; // echo link
color = getColorAtOffset(offset, ConsoleLineTracker.getDocument());
assertNotNull("No color found at " + offset, color); //$NON-NLS-1$
assertEquals(color, AntUIPlugin.getPreferenceColor(IAntUIPreferenceConstants.CONSOLE_WARNING_COLOR));
}
/**
- * Tests launching Ant in a separate VM and that the correct working directory is set
+ * Tests launching Ant in a separate VM and that the correct working directory
+ * is set
*/
public void testWorkingDirectory() throws CoreException {
ILaunchConfiguration config = getLaunchConfiguration("echoingSepVM"); //$NON-NLS-1$
assertNotNull("Could not locate launch configuration for " + "echoingSepVM", config); //$NON-NLS-1$ //$NON-NLS-2$
ILaunchConfigurationWorkingCopy copy = config.getWorkingCopy();
- copy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, getJavaProject().getProject().getLocation().toOSString());
+ copy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY,
+ getJavaProject().getProject().getLocation().toOSString());
copy.setAttribute(IAntLaunchConstants.ATTR_ANT_TARGETS, "Bug42984"); //$NON-NLS-1$
launchAndTerminate(copy, 20000);
ConsoleLineTracker.waitForConsole();
assertLines(6);
assertTrue("Incorrect last message. Should end with " + ProjectHelper.PROJECT_NAME + ". Message: " //$NON-NLS-1$ //$NON-NLS-2$
- + ConsoleLineTracker.getMessage(2), ConsoleLineTracker.getMessage(2).endsWith(ProjectHelper.PROJECT_NAME));
+ + ConsoleLineTracker.getMessage(2),
+ ConsoleLineTracker.getMessage(2).endsWith(ProjectHelper.PROJECT_NAME));
}
/**
- * Tests launching Ant in a separate VM and that the correct property substitutions occur
+ * Tests launching Ant in a separate VM and that the correct property
+ * substitutions occur
*/
public void testPropertySubstitution() throws CoreException {
ILaunchConfiguration config = getLaunchConfiguration("74840SepVM"); //$NON-NLS-1$
@@ -203,11 +207,13 @@
launchAndTerminate(copy, 20000);
ConsoleLineTracker.waitForConsole();
assertLines(6);
- assertTrue("Incorrect echo message. Should not include unsubstituted property ", !ConsoleLineTracker.getMessage(2).trim().startsWith("[echo] ${workspace_loc}")); //$NON-NLS-1$ //$NON-NLS-2$
+ assertFalse("Incorrect echo message. Should not include unsubstituted property ", //$NON-NLS-1$
+ ConsoleLineTracker.getMessage(2).trim().startsWith("[echo] ${workspace_loc}")); //$NON-NLS-1$
}
/**
- * Tests launching Ant in a separate VM and getting messages logged to the console for project help.
+ * Tests launching Ant in a separate VM and getting messages logged to the
+ * console for project help.
*/
public void testProjectHelp() throws CoreException {
launch("echoingSepVM", "-p"); //$NON-NLS-1$ //$NON-NLS-2$
@@ -237,8 +243,9 @@
}
/**
- * Tests launching Ant in a separate VM and that the Environment variable ANT_HOME is set from the Ant home set for the build and ant.home is set
- * as a property. Bug 75729
+ * Tests launching Ant in a separate VM and that the Environment variable
+ * ANT_HOME is set from the Ant home set for the build and ant.home is set as a
+ * property. Bug 75729
*/
public void testAntHome() throws CoreException {
launch("environmentVar"); //$NON-NLS-1$
@@ -246,7 +253,8 @@
String message = ConsoleLineTracker.getMessage(1);
assertTrue("Incorrect message. Should end with org.apache.ant [" + message + "]", checkAntHomeMessage(message)); //$NON-NLS-1$ //$NON-NLS-2$
message = ConsoleLineTracker.getMessage(2);
- assertTrue("Incorrect message. Should end with org.apache.ant. Message: " + message, checkAntHomeMessage(message)); //$NON-NLS-1$
+ assertTrue("Incorrect message. Should end with org.apache.ant. Message: " + message, //$NON-NLS-1$
+ checkAntHomeMessage(message));
}
private boolean checkAntHomeMessage(String message) {