From 866ce9f550d2c7d3fa44319f8acbfb75a3ad3c42 Mon Sep 17 00:00:00 2001 From: Gintas Grigelionis Date: Fri, 1 Dec 2017 21:18:02 +0100 Subject: [PATCH] Checkstyle: mostly whitespace --- .checkstyle | 13 + src/etc/checkstyle/checkstyle-config | 5 +- .../core/containersrc/test/SpecialSeq.java | 17 +- .../taskdefs/javadoc/java/ClassToJavadoc.java | 2 +- .../depend/src4/test/ContainsOnlyInner.java | 3 +- .../taskdefs/rmic/src/AntTimestamp.java | 2 +- .../taskdefs/rmic/src/RemoteTimestamp.java | 2 +- .../types/assertions/AssertionTest.java | 4 +- src/etc/testcases/util/unusual.properties | 2 +- .../core/location/src/task/EchoLocation.java | 2 +- .../core/uuencode/src/task/BaseTask.java | 6 +- .../core/uuencode/src/task/UUDecodeTask.java | 1 - .../junit/org/apache/tools/ant/AntAssert.java | 6 +- .../ant/AntClassLoaderDelegationTest.java | 13 +- .../apache/tools/ant/AntClassLoaderTest.java | 1 + .../org/apache/tools/ant/BuildFileRule.java | 21 +- .../org/apache/tools/ant/BuildFileTest.java | 35 +-- .../junit/org/apache/tools/ant/CaseTest.java | 2 +- .../apache/tools/ant/DefaultLoggerTest.java | 1 + .../tools/ant/DirectoryScannerTest.java | 57 +++-- .../org/apache/tools/ant/ExecutorTest.java | 24 +- .../apache/tools/ant/ExtendedTaskdefTest.java | 4 +- .../org/apache/tools/ant/FileUtilities.java | 5 +- .../tools/ant/IntrospectionHelperTest.java | 58 +++-- .../apache/tools/ant/MockBuildListener.java | 28 ++- .../ant/ProjectHelperRepositoryTest.java | 2 +- .../org/apache/tools/ant/ProjectTest.java | 88 ++++--- .../apache/tools/ant/TaskContainerTest.java | 2 +- .../apache/tools/ant/UnknownElementTest.java | 17 +- .../tools/ant/filters/ConcatFilterTest.java | 12 +- .../tools/ant/filters/DynamicFilterTest.java | 11 +- .../tools/ant/filters/HeadTailTest.java | 2 +- .../tools/ant/filters/LineContainsTest.java | 3 +- .../tools/ant/filters/TokenFilterTest.java | 8 +- .../apache/tools/ant/launch/LocatorTest.java | 9 +- .../taskdefs/AntLikeTasksAtTopLevelTest.java | 2 +- .../apache/tools/ant/taskdefs/AntTest.java | 71 ++++-- .../apache/tools/ant/taskdefs/AntlibTest.java | 6 +- .../tools/ant/taskdefs/BUnzip2Test.java | 10 +- .../apache/tools/ant/taskdefs/BZip2Test.java | 4 +- .../tools/ant/taskdefs/CVSPassTest.java | 28 +-- .../tools/ant/taskdefs/ChecksumTest.java | 4 +- .../apache/tools/ant/taskdefs/ConcatTest.java | 21 +- .../tools/ant/taskdefs/ConditionTest.java | 10 +- .../apache/tools/ant/taskdefs/CopyTest.java | 44 ++-- .../tools/ant/taskdefs/CopydirTest.java | 2 +- .../ant/taskdefs/DefaultExcludesTest.java | 6 +- .../tools/ant/taskdefs/DirnameTest.java | 6 +- .../apache/tools/ant/taskdefs/EchoTest.java | 7 +- .../tools/ant/taskdefs/ExecuteJavaTest.java | 36 +-- .../ant/taskdefs/ExecuteWatchdogTest.java | 41 ++-- .../apache/tools/ant/taskdefs/FailTest.java | 28 +-- .../apache/tools/ant/taskdefs/FilterTest.java | 6 +- .../tools/ant/taskdefs/FixCrLfTest.java | 2 +- .../apache/tools/ant/taskdefs/GUnzipTest.java | 12 +- .../apache/tools/ant/taskdefs/GzipTest.java | 8 +- .../apache/tools/ant/taskdefs/ImportTest.java | 8 +- .../apache/tools/ant/taskdefs/JarTest.java | 32 +-- .../apache/tools/ant/taskdefs/JavaTest.java | 56 +++-- .../apache/tools/ant/taskdefs/JavacTest.java | 2 +- .../tools/ant/taskdefs/LoadFileTest.java | 25 +- .../tools/ant/taskdefs/MakeUrlTest.java | 10 +- .../ant/taskdefs/ManifestClassPathTest.java | 5 +- .../tools/ant/taskdefs/ManifestTest.java | 24 +- .../apache/tools/ant/taskdefs/MkdirTest.java | 4 +- .../tools/ant/taskdefs/MultiMapTest.java | 15 +- .../tools/ant/taskdefs/ParallelTest.java | 2 +- .../tools/ant/taskdefs/PropertyTest.java | 6 +- .../tools/ant/taskdefs/ReplaceTest.java | 2 +- .../tools/ant/taskdefs/RmicAdvancedTest.java | 30 +-- .../apache/tools/ant/taskdefs/RmicTest.java | 2 +- .../tools/ant/taskdefs/SQLExecTest.java | 42 ++-- .../apache/tools/ant/taskdefs/SleepTest.java | 33 ++- .../apache/tools/ant/taskdefs/StyleTest.java | 5 +- .../apache/tools/ant/taskdefs/SubAntTest.java | 23 +- .../apache/tools/ant/taskdefs/TStampTest.java | 18 +- .../apache/tools/ant/taskdefs/TarTest.java | 6 +- .../tools/ant/taskdefs/TestProcess.java | 38 +-- .../apache/tools/ant/taskdefs/TouchTest.java | 18 +- .../tools/ant/taskdefs/TypeAdapterTest.java | 11 +- .../tools/ant/taskdefs/TypedefTest.java | 6 +- .../apache/tools/ant/taskdefs/UntarTest.java | 17 +- .../apache/tools/ant/taskdefs/UnzipTest.java | 10 +- .../tools/ant/taskdefs/UpToDateTest.java | 2 +- .../tools/ant/taskdefs/XmlPropertyTest.java | 51 ++-- .../tools/ant/taskdefs/ZipExtraFieldTest.java | 11 +- .../apache/tools/ant/taskdefs/ZipTest.java | 6 +- .../compilers/DefaultCompilerAdapterTest.java | 13 +- .../taskdefs/condition/IsReachableTest.java | 8 +- .../taskdefs/cvslib/ChangeLogParserTest.java | 2 +- .../taskdefs/cvslib/ChangeLogWriterTest.java | 21 +- .../org/apache/tools/ant/taskdefs/dir2/A.java | 4 +- .../ant/taskdefs/email/EmailAddressTest.java | 36 +-- .../ant/taskdefs/optional/ANTLRTest.java | 4 +- .../optional/AbstractXSLTLiaisonTest.java | 6 +- .../taskdefs/optional/EchoPropertiesTest.java | 57 ++--- .../tools/ant/taskdefs/optional/JspcTest.java | 30 +-- .../taskdefs/optional/Native2AsciiTest.java | 3 +- .../taskdefs/optional/PropertyFileTest.java | 3 +- .../taskdefs/optional/ReplaceRegExpTest.java | 4 +- .../taskdefs/optional/RhinoScriptTest.java | 3 +- .../taskdefs/optional/TraXLiaisonTest.java | 20 +- .../taskdefs/optional/depend/DependTest.java | 24 +- .../taskdefs/optional/i18n/TranslateTest.java | 13 +- .../taskdefs/optional/image/ImageTest.java | 6 +- .../optional/jdepend/JDependTest.java | 2 +- .../optional/junit/BatchTestTest.java | 3 +- .../taskdefs/optional/junit/DOMUtilTest.java | 5 +- .../optional/junit/JUnitClassLoaderTest.java | 2 +- .../optional/junit/JUnitReportTest.java | 25 +- .../optional/junit/JUnitTaskTest.java | 99 +++++--- .../optional/junit/JUnitTestListenerTest.java | 2 +- .../optional/junit/JUnitTestRunnerTest.java | 98 ++++---- .../junit/JUnitVersionHelperTest.java | 32 ++- .../ant/taskdefs/optional/junit/Sleeper.java | 1 - .../junit/XMLResultAggregatorTest.java | 12 +- .../ant/taskdefs/optional/net/FTPTest.java | 225 +++++++----------- .../ant/taskdefs/optional/sos/SOSTest.java | 2 +- .../ant/taskdefs/optional/ssh/ScpTest.java | 124 +++++----- .../taskdefs/optional/unix/SymlinkTest.java | 8 +- .../ant/taskdefs/optional/vss/MSVSSTest.java | 13 +- .../apache/tools/ant/types/AddTypeTest.java | 53 ++--- .../tools/ant/types/AssertionsTest.java | 4 +- .../tools/ant/types/CommandlineJavaTest.java | 2 +- .../tools/ant/types/CommandlineTest.java | 4 +- .../tools/ant/types/DescriptionTest.java | 12 +- .../ant/types/EnumeratedAttributeTest.java | 16 +- .../apache/tools/ant/types/FilterSetTest.java | 7 +- .../org/apache/tools/ant/types/PathTest.java | 4 +- .../tools/ant/types/PermissionsTest.java | 8 +- .../org/apache/tools/ant/types/PolyTest.java | 9 +- .../ant/types/RedirectorElementTest.java | 2 +- .../tools/ant/types/ResourceOutputTest.java | 2 +- .../tools/ant/types/TarFileSetTest.java | 26 +- .../tools/ant/types/XMLCatalogTest.java | 46 +--- .../tools/ant/types/ZipFileSetTest.java | 32 +-- .../tools/ant/types/mappers/MapperResult.java | 2 +- .../ant/types/resources/FileResourceTest.java | 1 - .../resources/LazyResourceCollectionTest.java | 1 - .../ant/types/resources/TarResourceTest.java | 3 +- .../ant/types/selectors/BaseSelectorRule.java | 10 +- .../ant/types/selectors/BaseSelectorTest.java | 26 +- .../ant/types/selectors/DateSelectorTest.java | 26 +- .../types/selectors/DepthSelectorTest.java | 2 - .../types/selectors/FilenameSelectorTest.java | 66 +++-- .../tools/ant/types/selectors/MockCache.java | 8 +- .../types/selectors/ModifiedSelectorTest.java | 206 ++++++++-------- .../types/selectors/PresentSelectorTest.java | 3 - .../ant/types/selectors/SizeSelectorTest.java | 4 - .../ant/types/selectors/TypeSelectorTest.java | 11 +- .../tools/ant/util/DOMElementWriterTest.java | 5 +- .../apache/tools/ant/util/DateUtilsTest.java | 22 +- .../tools/ant/util/DeweyDecimalTest.java | 20 +- .../apache/tools/ant/util/FileUtilsTest.java | 23 +- .../apache/tools/ant/util/JAXPUtilsTest.java | 4 +- .../tools/ant/util/JavaEnvUtilsTest.java | 29 ++- .../util/LayoutPreservingPropertiesTest.java | 4 +- .../util/LineOrientedOutputStreamTest.java | 16 +- .../tools/ant/util/ReaderInputStreamTest.java | 15 +- .../tools/ant/util/ResourceUtilsTest.java | 8 +- .../tools/ant/util/StringUtilsTest.java | 85 ++++--- .../ant/util/UnPackageNameMapperTest.java | 2 +- .../util/regexp/JakartaRegexpMatcherTest.java | 3 +- .../util/regexp/JakartaRegexpRegexpTest.java | 7 +- .../util/regexp/Jdk14RegexpMatcherTest.java | 8 +- .../util/regexp/Jdk14RegexpRegexpTest.java | 8 +- .../ant/util/regexp/RegexpMatcherTest.java | 6 +- .../apache/tools/bzip2/CBZip2StreamTest.java | 1 + .../apache/tools/mail/MailMessageTest.java | 111 +++++---- .../org/apache/tools/tar/TarEntryTest.java | 4 +- .../apache/tools/zip/AsiExtraFieldTest.java | 8 +- .../apache/tools/zip/ExtraFieldUtilsTest.java | 26 +- .../apache/tools/zip/UTF8ZipFilesTest.java | 12 +- .../org/apache/tools/zip/ZipEncodingTest.java | 6 +- .../org/apache/tools/zip/ZipEntryTest.java | 2 +- .../org/apache/tools/zip/ZipLongTest.java | 2 +- .../org/example/junit/MultilineAsserts.java | 16 +- .../org/example/junit/TestNotMissed.java | 1 - .../tasks/TaskdefTestContainerTask.java | 3 +- .../example/tasks/TaskdefTestSimpleTask.java | 15 +- 180 files changed, 1697 insertions(+), 1623 deletions(-) create mode 100644 .checkstyle diff --git a/.checkstyle b/.checkstyle new file mode 100644 index 000000000..f2697b162 --- /dev/null +++ b/.checkstyle @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/etc/checkstyle/checkstyle-config b/src/etc/checkstyle/checkstyle-config index b3232be7b..508a8823e 100644 --- a/src/etc/checkstyle/checkstyle-config +++ b/src/etc/checkstyle/checkstyle-config @@ -1,4 +1,5 @@ - + + - @@ -65,6 +65,7 @@ + diff --git a/src/etc/testcases/core/containersrc/test/SpecialSeq.java b/src/etc/testcases/core/containersrc/test/SpecialSeq.java index ae6a3dd93..f3f017601 100644 --- a/src/etc/testcases/core/containersrc/test/SpecialSeq.java +++ b/src/etc/testcases/core/containersrc/test/SpecialSeq.java @@ -1,4 +1,4 @@ -/* +/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. @@ -13,7 +13,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * */ package test; @@ -22,21 +22,22 @@ import org.apache.tools.ant.TaskContainer; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.taskdefs.Echo; -import java.util.*; + +import java.util.Enumeration; +import java.util.Vector; public class SpecialSeq extends Task implements TaskContainer { /** Optional Vector holding the nested tasks */ private Vector nestedTasks = new Vector(); private FileSet fileset; - + private Echo nestedEcho; - + /** * Add a nested task. - *

+ * * @param nestedTask Nested task to execute - *

*/ public void addTask(Task nestedTask) { nestedTasks.addElement(nestedTask); @@ -60,7 +61,7 @@ public class SpecialSeq extends Task implements TaskContainer { public void addFileset(FileSet fileset) { this.fileset = fileset; } - + public void addNested(Echo nestedEcho) { this.nestedEcho = nestedEcho; } diff --git a/src/etc/testcases/taskdefs/javadoc/java/ClassToJavadoc.java b/src/etc/testcases/taskdefs/javadoc/java/ClassToJavadoc.java index a41bdc158..bd8cab624 100644 --- a/src/etc/testcases/taskdefs/javadoc/java/ClassToJavadoc.java +++ b/src/etc/testcases/taskdefs/javadoc/java/ClassToJavadoc.java @@ -31,7 +31,7 @@ public class ClassToJavadoc { * @see java.lang.Object#toString() */ public String toString() { return this.getClass().getName(); } - + /** * @return An arbitrary string. */ diff --git a/src/etc/testcases/taskdefs/optional/depend/src4/test/ContainsOnlyInner.java b/src/etc/testcases/taskdefs/optional/depend/src4/test/ContainsOnlyInner.java index d00254b98..9694dddb9 100644 --- a/src/etc/testcases/taskdefs/optional/depend/src4/test/ContainsOnlyInner.java +++ b/src/etc/testcases/taskdefs/optional/depend/src4/test/ContainsOnlyInner.java @@ -19,6 +19,5 @@ package test; public class ContainsOnlyInner { void method1() { System.out.println(Outer.Inner.class); - } + } } - diff --git a/src/etc/testcases/taskdefs/rmic/src/AntTimestamp.java b/src/etc/testcases/taskdefs/rmic/src/AntTimestamp.java index d9ba78546..579d2edcd 100644 --- a/src/etc/testcases/taskdefs/rmic/src/AntTimestamp.java +++ b/src/etc/testcases/taskdefs/rmic/src/AntTimestamp.java @@ -39,7 +39,7 @@ public class AntTimestamp implements RemoteTimestamp { * @throws RemoteException */ public long when() throws RemoteException { - Calendar cal=Calendar.getInstance(); + Calendar cal = Calendar.getInstance(); return DateUtils.getPhaseOfMoon(cal); } } diff --git a/src/etc/testcases/taskdefs/rmic/src/RemoteTimestamp.java b/src/etc/testcases/taskdefs/rmic/src/RemoteTimestamp.java index 1834e4a1f..5c9afc893 100644 --- a/src/etc/testcases/taskdefs/rmic/src/RemoteTimestamp.java +++ b/src/etc/testcases/taskdefs/rmic/src/RemoteTimestamp.java @@ -21,6 +21,6 @@ import java.rmi.RemoteException; * this is the interface we remote */ public interface RemoteTimestamp extends Remote { - long when() throws RemoteException ; + long when() throws RemoteException; } diff --git a/src/etc/testcases/types/assertions/AssertionTest.java b/src/etc/testcases/types/assertions/AssertionTest.java index 28a9dc36e..d71720383 100644 --- a/src/etc/testcases/types/assertions/AssertionTest.java +++ b/src/etc/testcases/types/assertions/AssertionTest.java @@ -31,14 +31,14 @@ public class AssertionTest extends TestCase { try { assert true == false; fail("expected an assertion"); - } catch(AssertionError asserto) { + } catch (AssertionError asserto) { //if we got here, all was well } } public void testAssertNotRaised() { - assert(2+2==4); + assert(2 + 2 == 4); } diff --git a/src/etc/testcases/util/unusual.properties b/src/etc/testcases/util/unusual.properties index 9c370faae..3b63de6e7 100644 --- a/src/etc/testcases/util/unusual.properties +++ b/src/etc/testcases/util/unusual.properties @@ -19,7 +19,7 @@ prop\ttwo=contains\ttab prop\nthree=contains\nnewline -prop\rfour=contains\rcarraige return +prop\rfour=contains\rcarriage return prop\ffive=contains\fform feed diff --git a/src/tests/antunit/core/location/src/task/EchoLocation.java b/src/tests/antunit/core/location/src/task/EchoLocation.java index a2031e68d..ce54c03bb 100644 --- a/src/tests/antunit/core/location/src/task/EchoLocation.java +++ b/src/tests/antunit/core/location/src/task/EchoLocation.java @@ -6,7 +6,7 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/src/tests/antunit/core/uuencode/src/task/BaseTask.java b/src/tests/antunit/core/uuencode/src/task/BaseTask.java index 22fb70e37..320f753ff 100644 --- a/src/tests/antunit/core/uuencode/src/task/BaseTask.java +++ b/src/tests/antunit/core/uuencode/src/task/BaseTask.java @@ -63,10 +63,10 @@ abstract public class BaseTask extends Task { FILE_UTILS.close(outputStream); } } - + abstract protected void doit( InputStream is, OutputStream os) throws Exception; - + private void assertAttribute(File file, String attributeName) { if (file == null) { throw new BuildException("Required attribute " + attributeName @@ -74,5 +74,3 @@ abstract public class BaseTask extends Task { } } } - - diff --git a/src/tests/antunit/core/uuencode/src/task/UUDecodeTask.java b/src/tests/antunit/core/uuencode/src/task/UUDecodeTask.java index 8423f8ce8..d74b846f5 100644 --- a/src/tests/antunit/core/uuencode/src/task/UUDecodeTask.java +++ b/src/tests/antunit/core/uuencode/src/task/UUDecodeTask.java @@ -28,4 +28,3 @@ public class UUDecodeTask extends BaseTask { new UUDecoder().decodeBuffer(is, os); } } - diff --git a/src/tests/junit/org/apache/tools/ant/AntAssert.java b/src/tests/junit/org/apache/tools/ant/AntAssert.java index 5bc3caa6a..d23792e6a 100644 --- a/src/tests/junit/org/apache/tools/ant/AntAssert.java +++ b/src/tests/junit/org/apache/tools/ant/AntAssert.java @@ -34,7 +34,8 @@ public class AntAssert { */ public static void assertContains(String message, String needle, String haystack) { String formattedMessage = (message == null ? "" : message + " "); - assertTrue(formattedMessage + String.format("expected message containing: <%s> but got: <%s>", needle, haystack), haystack.contains(needle)); + assertTrue(formattedMessage + String.format("expected message containing: <%s> but got: <%s>", + needle, haystack), haystack.contains(needle)); } /** @@ -55,7 +56,8 @@ public class AntAssert { */ public static void assertNotContains(String message, String needle, String haystack) { String formattedMessage = (message == null ? "" : message + " "); - assertFalse(formattedMessage + String.format("expected message not to contain: <%s> but got: <%s>", needle, haystack), haystack.contains(needle)); + assertFalse(formattedMessage + String.format("expected message not to contain: <%s> but got: <%s>", + needle, haystack), haystack.contains(needle)); } /** diff --git a/src/tests/junit/org/apache/tools/ant/AntClassLoaderDelegationTest.java b/src/tests/junit/org/apache/tools/ant/AntClassLoaderDelegationTest.java index ae5ce6270..6eedf9e0f 100644 --- a/src/tests/junit/org/apache/tools/ant/AntClassLoaderDelegationTest.java +++ b/src/tests/junit/org/apache/tools/ant/AntClassLoaderDelegationTest.java @@ -55,6 +55,7 @@ public class AntClassLoaderDelegationTest { private static final String TEST_RESOURCE = "apache/tools/ant/IncludeTest.class"; + @SuppressWarnings("resource") @Test public void testFindResources() throws Exception { // This path should contain the class files for these testcases: @@ -81,6 +82,7 @@ public class AntClassLoaderDelegationTest { enum2List(acl.getResources(TEST_RESOURCE))); } + @SuppressWarnings("resource") @Test public void testFindIsolateResources() throws Exception { String buildTestcases = System.getProperty("build.tests"); @@ -103,11 +105,12 @@ public class AntClassLoaderDelegationTest { private static List enum2List(Enumeration e) { return Collections.list(e); } - + /** Special loader that just knows how to find TEST_RESOURCE. */ private static final class ParentLoader extends ClassLoader { - - public ParentLoader() {} + + public ParentLoader() { + } protected Enumeration findResources(String name) throws IOException { if (name.equals(TEST_RESOURCE)) { @@ -118,7 +121,7 @@ public class AntClassLoaderDelegationTest { return Collections.enumeration(Collections.EMPTY_SET); } } - + } - + } diff --git a/src/tests/junit/org/apache/tools/ant/AntClassLoaderTest.java b/src/tests/junit/org/apache/tools/ant/AntClassLoaderTest.java index 17c418a4f..bddf729f5 100644 --- a/src/tests/junit/org/apache/tools/ant/AntClassLoaderTest.java +++ b/src/tests/junit/org/apache/tools/ant/AntClassLoaderTest.java @@ -207,6 +207,7 @@ public class AntClassLoaderTest { * @see * https://issues.apache.org/bugzilla/show_bug.cgi?id=46752 */ + @SuppressWarnings("resource") @Test public void testGetResources() throws IOException { AntClassLoader acl = new AntClassLoader(new EmptyLoader(), null, diff --git a/src/tests/junit/org/apache/tools/ant/BuildFileRule.java b/src/tests/junit/org/apache/tools/ant/BuildFileRule.java index 05f7d8e33..52ec87787 100644 --- a/src/tests/junit/org/apache/tools/ant/BuildFileRule.java +++ b/src/tests/junit/org/apache/tools/ant/BuildFileRule.java @@ -28,8 +28,8 @@ import org.junit.rules.ExternalResource; /** * Provides access for JUnit tests to execute Ant targets and access execution details (i.e logs). * - * Example usage: - * + *

Example usage:

+ *
  * public class MyTest {
  *
  *     \@Rule
@@ -42,7 +42,7 @@ import org.junit.rules.ExternalResource;
  *
  *     \@Test
  *     public void testSuccess() {
- *         rule.executeTarget("passingTaget");
+ *         rule.executeTarget("passingTarget");
  *         assertEquals("Incorrect log message", "[taskName] Action Complete", rule.getLog());
  *     }
  *
@@ -57,7 +57,7 @@ import org.junit.rules.ExternalResource;
  *     }
  *
  * }
- * 
+ * 
*/ public class BuildFileRule extends ExternalResource { @@ -102,8 +102,7 @@ public class BuildFileRule extends ExternalResource { /** * Gets any messages that have been logged during the current execution, unless * the logging level has been set above the log level defined in the message. - * - * Only valid if configureProject() has been called. + *

Only valid if configureProject() has been called.

* @return the content of the log. */ public String getFullLog() { @@ -159,7 +158,7 @@ public class BuildFileRule extends ExternalResource { File antFile = new File(System.getProperty("root"), filename); project.setProperty("ant.processid", ProcessUtil.getProcessId("")); project.setProperty("ant.threadname", Thread.currentThread().getName()); - project.setUserProperty("ant.file" , antFile.getAbsolutePath()); + project.setUserProperty("ant.file", antFile.getAbsolutePath()); project.addBuildListener(new AntTestListener(logLevel)); ProjectHelper.configureProject(project, antFile); } @@ -217,7 +216,7 @@ public class BuildFileRule extends ExternalResource { protected static class AntOutputStream extends OutputStream { private StringBuffer buffer; - public AntOutputStream( StringBuffer buffer ) { + public AntOutputStream(StringBuffer buffer) { this.buffer = buffer; } @@ -301,9 +300,9 @@ public class BuildFileRule extends ExternalResource { return; } - if (event.getPriority() == Project.MSG_INFO || - event.getPriority() == Project.MSG_WARN || - event.getPriority() == Project.MSG_ERR) { + if (event.getPriority() == Project.MSG_INFO + || event.getPriority() == Project.MSG_WARN + || event.getPriority() == Project.MSG_ERR) { logBuffer.append(event.getMessage()); } fullLogBuffer.append(event.getMessage()); diff --git a/src/tests/junit/org/apache/tools/ant/BuildFileTest.java b/src/tests/junit/org/apache/tools/ant/BuildFileTest.java index e18d71b8b..02b49e356 100644 --- a/src/tests/junit/org/apache/tools/ant/BuildFileTest.java +++ b/src/tests/junit/org/apache/tools/ant/BuildFileTest.java @@ -19,6 +19,7 @@ package org.apache.tools.ant; import java.io.File; +import java.io.OutputStream; import java.io.PrintStream; import java.net.URL; @@ -139,28 +140,28 @@ public abstract class BuildFileTest extends TestCase { /** * Assert that the given substring is in the output messages. - * @param message Print this message if the test fails. Defaults to - * a meaningful text if null is passed. + * @param message Print this message if the test fails. Defaults to + * a meaningful text if null is passed. * @since Ant1.7 */ public void assertOutputContaining(String message, String substring) { String realOutput = getOutput(); - String realMessage = (message != null) - ? message + String realMessage = (message != null) + ? message : "expecting output to contain \"" + substring + "\" output was \"" + realOutput + "\""; assertTrue(realMessage, realOutput.indexOf(substring) >= 0); } /** * Assert that the given substring is not in the output messages. - * @param message Print this message if the test fails. Defaults to - * a meaningful text if null is passed. + * @param message Print this message if the test fails. Defaults to + * a meaningful text if null is passed. * @since Ant1.7 */ public void assertOutputNotContaining(String message, String substring) { String realOutput = getOutput(); - String realMessage = (message != null) - ? message + String realMessage = (message != null) + ? message : "expecting output to not contain \"" + substring + "\" output was \"" + realOutput + "\""; assertFalse(realMessage, realOutput.indexOf(substring) >= 0); } @@ -209,7 +210,7 @@ public abstract class BuildFileTest extends TestCase { */ public void assertDebuglogContaining(String substring) { String realLog = getFullLog(); - assertTrue("expecting debug log to contain \"" + substring + assertTrue("expecting debug log to contain \"" + substring + "\" log was \"" + realLog + "\"", realLog.indexOf(substring) >= 0); @@ -268,7 +269,7 @@ public abstract class BuildFileTest extends TestCase { } private String cleanBuffer(StringBuffer buffer) { - StringBuffer cleanedBuffer = new StringBuffer(); + StringBuilder cleanedBuffer = new StringBuilder(); for (int i = 0; i < buffer.length(); i++) { char ch = buffer.charAt(i); if (ch != '\r') { @@ -299,7 +300,7 @@ public abstract class BuildFileTest extends TestCase { project = new Project(); project.init(); File antFile = new File(System.getProperty("root"), filename); - project.setUserProperty("ant.file" , antFile.getAbsolutePath()); + project.setUserProperty("ant.file", antFile.getAbsolutePath()); // set two new properties to allow to build unique names when running multithreaded tests project.setProperty("ant.processid", ProcessUtil.getProcessId("")); project.setProperty("ant.threadname", Thread.currentThread().getName()); @@ -480,7 +481,7 @@ public abstract class BuildFileTest extends TestCase { * @param resource the resource to retrieve its url. * @throws junit.framework.AssertionFailedError if the resource is not found. */ - public URL getResource(String resource){ + public URL getResource(String resource) { URL url = getClass().getResource(resource); assertNotNull("Could not find resource :" + resource, url); return url; @@ -489,10 +490,10 @@ public abstract class BuildFileTest extends TestCase { /** * an output stream which saves stuff to our buffer. */ - protected static class AntOutputStream extends java.io.OutputStream { + protected static class AntOutputStream extends OutputStream { private StringBuffer buffer; - public AntOutputStream( StringBuffer buffer ) { + public AntOutputStream(StringBuffer buffer) { this.buffer = buffer; } @@ -580,9 +581,9 @@ public abstract class BuildFileTest extends TestCase { return; } - if (event.getPriority() == Project.MSG_INFO || - event.getPriority() == Project.MSG_WARN || - event.getPriority() == Project.MSG_ERR) { + if (event.getPriority() == Project.MSG_INFO + || event.getPriority() == Project.MSG_WARN + || event.getPriority() == Project.MSG_ERR) { logBuffer.append(event.getMessage()); } fullLogBuffer.append(event.getMessage()); diff --git a/src/tests/junit/org/apache/tools/ant/CaseTest.java b/src/tests/junit/org/apache/tools/ant/CaseTest.java index 04f60be03..a466ea404 100644 --- a/src/tests/junit/org/apache/tools/ant/CaseTest.java +++ b/src/tests/junit/org/apache/tools/ant/CaseTest.java @@ -56,7 +56,7 @@ public class CaseTest { try { buildRule.executeTarget("taskcase"); fail("Build exception should have been thrown due to case sensitivity of name"); - } catch(BuildException ex) { + } catch (BuildException ex) { assertContains("Task names should be case sensitive", "Problem: failed to create task or type ecHO", ex.getMessage()); } } diff --git a/src/tests/junit/org/apache/tools/ant/DefaultLoggerTest.java b/src/tests/junit/org/apache/tools/ant/DefaultLoggerTest.java index 00f4dfa19..303a44b60 100644 --- a/src/tests/junit/org/apache/tools/ant/DefaultLoggerTest.java +++ b/src/tests/junit/org/apache/tools/ant/DefaultLoggerTest.java @@ -34,6 +34,7 @@ public class DefaultLoggerTest { return m.toString(); } + @SuppressWarnings("serial") @Test public void testThrowableMessage() throws Exception { // #43398 BuildException be = new BuildException("oops", new Location("build.xml", 1, 0)); diff --git a/src/tests/junit/org/apache/tools/ant/DirectoryScannerTest.java b/src/tests/junit/org/apache/tools/ant/DirectoryScannerTest.java index baf0b2078..3691d9417 100644 --- a/src/tests/junit/org/apache/tools/ant/DirectoryScannerTest.java +++ b/src/tests/junit/org/apache/tools/ant/DirectoryScannerTest.java @@ -21,8 +21,8 @@ package org.apache.tools.ant; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeTrue; import static org.junit.Assume.assumeFalse; +import static org.junit.Assume.assumeTrue; import java.io.File; import java.io.IOException; @@ -62,7 +62,7 @@ public class DirectoryScannerTest { ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); ds.setIncludes(new String[] {"alpha"}); ds.scan(); - compareFiles(ds, new String[] {} ,new String[] {"alpha"}); + compareFiles(ds, new String[] {}, new String[] {"alpha"}); } @Test @@ -244,7 +244,7 @@ public class DirectoryScannerTest { * Only supports test on Linux at the moment because Java has * no real notion of symlinks built in, so an os-specfic call * to Runtime.exec() must be made to create a link to test against. - * @throws InterruptedException + * @throws InterruptedException if something goes wrong */ @Test public void testSetFollowLinks() throws IOException, InterruptedException { @@ -276,13 +276,13 @@ public class DirectoryScannerTest { boolean haveZipPackage = false; boolean haveTaskdefsPackage = false; - String[] included = ds.getIncludedDirectories(); - for (int i=0; i files = new TreeSet(); - for (int counter = 0; counter < includedFiles.length; counter++) { - files.add(includedFiles[counter].replace(File.separatorChar, '/')); + for (String includedFile : includedFiles) { + files.add(includedFile.replace(File.separatorChar, '/')); } TreeSet directories = new TreeSet(); - for (int counter = 0; counter < includedDirectories.length; counter++) { - directories.add(includedDirectories[counter] - .replace(File.separatorChar, '/')); + for (String includedDirectory : includedDirectories) { + directories.add(includedDirectory + .replace(File.separatorChar, '/')); } String currentfile; Iterator i = files.iterator(); int counter = 0; while (i.hasNext()) { - currentfile = (String) i.next(); + currentfile = i.next(); assertEquals(expectedFiles[counter], currentfile); counter++; } @@ -545,7 +542,7 @@ public class DirectoryScannerTest { Iterator dirit = directories.iterator(); counter = 0; while (dirit.hasNext()) { - currentdirectory = (String) dirit.next(); + currentdirectory = dirit.next(); assertEquals(expectedDirectories[counter], currentdirectory); counter++; } diff --git a/src/tests/junit/org/apache/tools/ant/ExecutorTest.java b/src/tests/junit/org/apache/tools/ant/ExecutorTest.java index 80ec96fb1..b17554c80 100644 --- a/src/tests/junit/org/apache/tools/ant/ExecutorTest.java +++ b/src/tests/junit/org/apache/tools/ant/ExecutorTest.java @@ -53,12 +53,24 @@ public class ExecutorTest implements BuildListener { public void targetStarted(BuildEvent event) { targetCount++; } - public void buildStarted(BuildEvent event) {} - public void buildFinished(BuildEvent event) {} - public void targetFinished(BuildEvent event) {} - public void taskStarted(BuildEvent event) {} - public void taskFinished(BuildEvent event) {} - public void messageLogged(BuildEvent event) {} + + public void buildStarted(BuildEvent event) { + } + + public void buildFinished(BuildEvent event) { + } + + public void targetFinished(BuildEvent event) { + } + + public void taskStarted(BuildEvent event) { + } + + public void taskFinished(BuildEvent event) { + } + + public void messageLogged(BuildEvent event) { + } @Before public void setUp() { diff --git a/src/tests/junit/org/apache/tools/ant/ExtendedTaskdefTest.java b/src/tests/junit/org/apache/tools/ant/ExtendedTaskdefTest.java index 7c8ef759b..d5444f9ea 100644 --- a/src/tests/junit/org/apache/tools/ant/ExtendedTaskdefTest.java +++ b/src/tests/junit/org/apache/tools/ant/ExtendedTaskdefTest.java @@ -50,7 +50,7 @@ public class ExtendedTaskdefTest { try { buildRule.executeTarget("testRun"); fail("BuildException should have been thrown"); - } catch(BuildException ex) { + } catch (BuildException ex) { assertContains("exception thrown by the subclass", "executing the Foo task", ex.getMessage()); } } @@ -60,7 +60,7 @@ public class ExtendedTaskdefTest { try { buildRule.executeTarget("testRun2"); fail("BuildException should have been thrown"); - } catch(BuildException ex) { + } catch (BuildException ex) { assertContains("exception thrown by the subclass", "executing the Foo task", ex.getMessage()); } } diff --git a/src/tests/junit/org/apache/tools/ant/FileUtilities.java b/src/tests/junit/org/apache/tools/ant/FileUtilities.java index a9de5cea4..79b57168f 100644 --- a/src/tests/junit/org/apache/tools/ant/FileUtilities.java +++ b/src/tests/junit/org/apache/tools/ant/FileUtilities.java @@ -58,7 +58,6 @@ public class FileUtilities { } } - /** * Modified the timestamp on a file so it's seconds earlier than it was before. Where file * is a directory, this function recurses into all child files (and directories) and reduces their modified @@ -66,7 +65,7 @@ public class FileUtilities { * @param file the file to change, or the directory to change then recurse into * @param seconds how many seconds to roll the timestamp back by */ - public static void rollbackTimetamps(File file, long seconds) { + public static void rollbackTimestamps(File file, long seconds) { if (null == file || !file.exists()) { return; } @@ -80,7 +79,7 @@ public class FileUtilities { return; } for (File child : children) { - rollbackTimetamps(child, seconds); + rollbackTimestamps(child, seconds); } } } diff --git a/src/tests/junit/org/apache/tools/ant/IntrospectionHelperTest.java b/src/tests/junit/org/apache/tools/ant/IntrospectionHelperTest.java index 424fb8e16..33782e0db 100644 --- a/src/tests/junit/org/apache/tools/ant/IntrospectionHelperTest.java +++ b/src/tests/junit/org/apache/tools/ant/IntrospectionHelperTest.java @@ -19,8 +19,8 @@ package org.apache.tools.ant; import java.io.File; -import java.lang.reflect.Method; import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Enumeration; @@ -30,6 +30,7 @@ import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; + import org.apache.tools.ant.taskdefs.condition.Os; import org.junit.Before; import org.junit.ComparisonFailure; @@ -98,7 +99,8 @@ public class IntrospectionHelperTest { ih = IntrospectionHelper.getHelper(String.class); try { m = ih.getAddTextMethod(); - } catch (BuildException e) {} + } catch (BuildException e) { + } } @Test @@ -221,7 +223,7 @@ public class IntrospectionHelperTest { Class expect = (Class) elemMap.get(name); assertNotNull("Support for "+name+" in IntrospectioNHelperTest?", expect); - assertEquals("Return type of "+name, expect, ih.getElementType(name)); + assertEquals("Return type of " + name, expect, ih.getElementType(name)); elemMap.remove(name); } assertTrue("Found all", elemMap.isEmpty()); @@ -246,7 +248,8 @@ public class IntrospectionHelperTest { try { actualMap.clear(); //TODO we should be asserting a value somewhere in here - } catch (UnsupportedOperationException e) {} + } catch (UnsupportedOperationException e) { + } } @Test @@ -276,7 +279,8 @@ public class IntrospectionHelperTest { return null; } - public void createThree() {} + public void createThree() { + } public Object[] createFour() { return null; @@ -294,19 +298,24 @@ public class IntrospectionHelperTest { throw new NullPointerException(); } - public void addSeven(String s, String s2) {} + public void addSeven(String s, String s2) { + } - public void addEight() {} + public void addEight() { + } public String addNine(String s) { return null; } - public void addTen(String[] s) {} + public void addTen(String[] s) { + } - public void addEleven(int i) {} + public void addEleven(int i) { + } - public void addTwelve(Class c) {} + public void addTwelve(Class c) { + } public void addThirteen(StringBuffer sb) { sb.append("test"); @@ -378,7 +387,7 @@ public class IntrospectionHelperTest { ih.setAttribute(p, this, "ten", "2"); try { ih.setAttribute(p, this, "ten", "3"); - fail(projectBasedir+"2 shouldn't be equals to "+projectBasedir+"3"); + fail(projectBasedir + "2 shouldn't be equals to " + projectBasedir + "3"); } catch (BuildException be) { assertTrue(be.getCause() instanceof AssertionError); } @@ -518,7 +527,8 @@ public class IntrospectionHelperTest { try { actualMap.clear(); //TODO we should be asserting a value somewhere in here - } catch (UnsupportedOperationException e) {} + } catch (UnsupportedOperationException e) { + } } @Test @@ -570,13 +580,17 @@ public class IntrospectionHelperTest { return 0; } - public void setThree() {} + public void setThree() { + } - public void setFour(String s1, String s2) {} + public void setFour(String s1, String s2) { + } - public void setFive(String[] s) {} + public void setFive(String[] s) { + } - public void setSix(Project p) {} + public void setSix(Project p) { + } public void setSeven(String s) { assertEquals("2", s); @@ -593,11 +607,11 @@ public class IntrospectionHelperTest { public void setTen(File f) { String path = f.getAbsolutePath(); if (Os.isFamily("unix") || Os.isFamily("openvms")) { - assertEquals(projectBasedir+"2", path); + assertEquals(projectBasedir + "2", path); } else if (Os.isFamily("netware")) { - assertEquals(projectBasedir+"2", path.toLowerCase(Locale.US)); + assertEquals(projectBasedir + "2", path.toLowerCase(Locale.US)); } else { - assertEquals(":"+projectBasedir+"2", + assertEquals(":" + projectBasedir + "2", path.toLowerCase(Locale.US).substring(1)); } } @@ -642,11 +656,11 @@ public class IntrospectionHelperTest { public void setTwenty(Path p) { String path = p.toAbsolutePath().toString(); if (Os.isFamily("unix") || Os.isFamily("openvms")) { - assertEquals(projectBasedir+"20", path); + assertEquals(projectBasedir + "20", path); } else if (Os.isFamily("netware")) { - assertEquals(projectBasedir+"20", path.toLowerCase(Locale.US)); + assertEquals(projectBasedir + "20", path.toLowerCase(Locale.US)); } else { - assertEquals(":"+projectBasedir+"20", + assertEquals(":" + projectBasedir + "20", path.toLowerCase(Locale.US).substring(1)); } } diff --git a/src/tests/junit/org/apache/tools/ant/MockBuildListener.java b/src/tests/junit/org/apache/tools/ant/MockBuildListener.java index e3a96a851..654872ca8 100644 --- a/src/tests/junit/org/apache/tools/ant/MockBuildListener.java +++ b/src/tests/junit/org/apache/tools/ant/MockBuildListener.java @@ -32,17 +32,29 @@ public class MockBuildListener implements BuildListener { this.project = project; } - public void buildStarted(BuildEvent event) {} - public void buildFinished(BuildEvent event) {} - public void targetStarted(BuildEvent event) {} - public void targetFinished(BuildEvent event) {} - public void taskStarted(BuildEvent event) {} - public void taskFinished(BuildEvent event) {} + public void buildStarted(BuildEvent event) { + } + + public void buildFinished(BuildEvent event) { + } + + public void targetStarted(BuildEvent event) { + } + + public void targetFinished(BuildEvent event) { + } + + public void taskStarted(BuildEvent event) { + } + + public void taskFinished(BuildEvent event) { + } public void messageLogged(final BuildEvent actual) { - if(actual.getPriority()==Project.MSG_DEBUG) + if (actual.getPriority() == Project.MSG_DEBUG) { return; - assertTrue("unexpected messageLogged: "+actual.getMessage(), !buffer.isEmpty()); + } + assertTrue("unexpected messageLogged: "+ actual.getMessage(), !buffer.isEmpty()); assertEquals("unexpected project ", project, actual.getProject()); BuildEvent expected = (BuildEvent) buffer.elementAt(0); diff --git a/src/tests/junit/org/apache/tools/ant/ProjectHelperRepositoryTest.java b/src/tests/junit/org/apache/tools/ant/ProjectHelperRepositoryTest.java index 550c342b7..eec42f783 100644 --- a/src/tests/junit/org/apache/tools/ant/ProjectHelperRepositoryTest.java +++ b/src/tests/junit/org/apache/tools/ant/ProjectHelperRepositoryTest.java @@ -78,7 +78,7 @@ public class ProjectHelperRepositoryTest { public void testNoDefaultContructor() throws Exception { class IncrrectHelper extends ProjectHelper { - // the default constructor is not visible to ant here + // the default constructor is not visible to ant here } ProjectHelperRepository repo = ProjectHelperRepository.getInstance(); diff --git a/src/tests/junit/org/apache/tools/ant/ProjectTest.java b/src/tests/junit/org/apache/tools/ant/ProjectTest.java index 89ed8c367..365e92dfb 100644 --- a/src/tests/junit/org/apache/tools/ant/ProjectTest.java +++ b/src/tests/junit/org/apache/tools/ant/ProjectTest.java @@ -89,7 +89,7 @@ public class ProjectTest { */ String driveSpec = "C:"; String driveSpecLower = "c:"; - + assertEqualsIgnoreDriveCase(driveSpecLower + "\\", p.resolveFile(driveSpec + "/", null).getPath()); assertEqualsIgnoreDriveCase(driveSpecLower + "\\", @@ -168,8 +168,8 @@ public class ProjectTest { private void assertEqualsIgnoreDriveCase(String s1, String s2) { if ((Os.isFamily("dos") || Os.isFamily("netware")) && s1.length() >= 1 && s2.length() >= 1) { - StringBuffer sb1 = new StringBuffer(s1); - StringBuffer sb2 = new StringBuffer(s2); + StringBuilder sb1 = new StringBuilder(s1); + StringBuilder sb2 = new StringBuilder(s2); sb1.setCharAt(0, Character.toUpperCase(s1.charAt(0))); sb2.setCharAt(0, Character.toUpperCase(s2.charAt(0))); assertEquals(sb1.toString(), sb2.toString()); @@ -184,9 +184,9 @@ public class ProjectTest { try { mbl.addBuildEvent(message, Project.MSG_ERR); p.addTaskDefinition(dummyName, taskClass); - fail("expected BuildException(\""+message+"\", Project.MSG_ERR) when adding task " + taskClass); - } - catch(BuildException e) { + fail(String.format("expected BuildException(\"%s\", Project.MSG_ERR) when adding task %s", + message, taskClass)); + } catch (BuildException e) { assertEquals(message, e.getMessage()); mbl.assertEmpty(); assertTrue(!p.getTaskDefinitions().containsKey(dummyName)); @@ -203,23 +203,27 @@ public class ProjectTest { assertEquals(DummyTaskOkNonTask.class, p.getTaskDefinitions().get("OkNonTask")); mbl.assertEmpty(); - assertTaskDefFails(DummyTaskPrivate.class, DummyTaskPrivate.class + " is not public"); - + assertTaskDefFails(DummyTaskPrivate.class, + DummyTaskPrivate.class + " is not public"); assertTaskDefFails(DummyTaskProtected.class, - DummyTaskProtected.class + " is not public"); - - assertTaskDefFails(DummyTaskPackage.class, DummyTaskPackage.class + " is not public"); - - assertTaskDefFails(DummyTaskAbstract.class, DummyTaskAbstract.class + " is abstract"); - assertTaskDefFails(DummyTaskInterface.class, DummyTaskInterface.class + " is abstract"); - - assertTaskDefFails(DummyTaskWithoutDefaultConstructor.class, "No public no-arg constructor in " + DummyTaskWithoutDefaultConstructor.class); - assertTaskDefFails(DummyTaskWithoutPublicConstructor.class, "No public no-arg constructor in " + DummyTaskWithoutPublicConstructor.class); - - assertTaskDefFails(DummyTaskWithoutExecute.class, "No public execute() in " + DummyTaskWithoutExecute.class); - assertTaskDefFails(DummyTaskWithNonPublicExecute.class, "No public execute() in " + DummyTaskWithNonPublicExecute.class); - - mbl.addBuildEvent("return type of execute() should be void but was \"int\" in " + DummyTaskWithNonVoidExecute.class, Project.MSG_WARN); + DummyTaskProtected.class + " is not public"); + assertTaskDefFails(DummyTaskPackage.class, + DummyTaskPackage.class + " is not public"); + assertTaskDefFails(DummyTaskAbstract.class, + DummyTaskAbstract.class + " is abstract"); + assertTaskDefFails(DummyTaskInterface.class, + DummyTaskInterface.class + " is abstract"); + assertTaskDefFails(DummyTaskWithoutDefaultConstructor.class, + "No public no-arg constructor in " + DummyTaskWithoutDefaultConstructor.class); + assertTaskDefFails(DummyTaskWithoutPublicConstructor.class, + "No public no-arg constructor in " + DummyTaskWithoutPublicConstructor.class); + assertTaskDefFails(DummyTaskWithoutExecute.class, + "No public execute() in " + DummyTaskWithoutExecute.class); + assertTaskDefFails(DummyTaskWithNonPublicExecute.class, + "No public execute() in " + DummyTaskWithNonPublicExecute.class); + + mbl.addBuildEvent("return type of execute() should be void but was \"int\" in " + + DummyTaskWithNonVoidExecute.class, Project.MSG_WARN); p.addTaskDefinition("NonVoidExecute", DummyTaskWithNonVoidExecute.class); mbl.assertEmpty(); assertEquals(DummyTaskWithNonVoidExecute.class, p.getTaskDefinitions().get("NonVoidExecute")); @@ -271,12 +275,18 @@ public class ProjectTest { throws InterruptedException { final String FOO = "foo", BAR = "bar"; p.addBuildListener(new BuildListener() { - public void buildStarted(BuildEvent event) {} - public void buildFinished(BuildEvent event) {} - public void targetStarted(BuildEvent event) {} - public void targetFinished(BuildEvent event) {} - public void taskStarted(BuildEvent event) {} - public void taskFinished(BuildEvent event) {} + public void buildStarted(BuildEvent event) { + } + public void buildFinished(BuildEvent event) { + } + public void targetStarted(BuildEvent event) { + } + public void targetFinished(BuildEvent event) { + } + public void taskStarted(BuildEvent event) { + } + public void taskFinished(BuildEvent event) { + } public void messageLogged(final BuildEvent actual) { assertEquals(FOO, actual.getMessage()); // each of the following lines would cause an @@ -309,19 +319,25 @@ public class ProjectTest { } private class DummyTaskPrivate extends Task { - public DummyTaskPrivate() {} - public void execute() {} + @SuppressWarnings("unused") + public DummyTaskPrivate() { + } + public void execute() { + } } protected class DummyTaskProtected extends Task { - public DummyTaskProtected() {} - public void execute() {} + public DummyTaskProtected() { + } + public void execute() { + } } - class DummyTaskPackage extends Task { - public DummyTaskPackage() {} - public void execute() {} + public DummyTaskPackage() { + } + public void execute() { + } } -} \ No newline at end of file +} diff --git a/src/tests/junit/org/apache/tools/ant/TaskContainerTest.java b/src/tests/junit/org/apache/tools/ant/TaskContainerTest.java index 700b7c11d..1fc745fae 100644 --- a/src/tests/junit/org/apache/tools/ant/TaskContainerTest.java +++ b/src/tests/junit/org/apache/tools/ant/TaskContainerTest.java @@ -28,7 +28,7 @@ public class TaskContainerTest { @Rule public BuildFileRule buildRule = new BuildFileRule(); - + @Before public void setUp() { buildRule.configureProject("src/etc/testcases/core/taskcontainer.xml"); diff --git a/src/tests/junit/org/apache/tools/ant/UnknownElementTest.java b/src/tests/junit/org/apache/tools/ant/UnknownElementTest.java index be7e21b84..1bad429c7 100644 --- a/src/tests/junit/org/apache/tools/ant/UnknownElementTest.java +++ b/src/tests/junit/org/apache/tools/ant/UnknownElementTest.java @@ -57,17 +57,22 @@ public class UnknownElementTest { @Ignore("Previously disabled through naming convention") public void XtestTaskFinishedEvent() { buildRule.getProject().addBuildListener(new BuildListener() { - public void buildStarted(BuildEvent event) {} - public void buildFinished(BuildEvent event) {} - public void targetStarted(BuildEvent event) {} - public void targetFinished(BuildEvent event) {} + public void buildStarted(BuildEvent event) { + } + public void buildFinished(BuildEvent event) { + } + public void targetStarted(BuildEvent event) { + } + public void targetFinished(BuildEvent event) { + } public void taskStarted(BuildEvent event) { assertTaskProperties(event.getTask()); } public void taskFinished(BuildEvent event) { assertTaskProperties(event.getTask()); } - public void messageLogged(BuildEvent event) {} + public void messageLogged(BuildEvent event) { + } private void assertTaskProperties(Task ue) { assertNotNull(ue); assertTrue(ue instanceof UnknownElement); @@ -111,5 +116,3 @@ public class UnknownElementTest { } } } - - diff --git a/src/tests/junit/org/apache/tools/ant/filters/ConcatFilterTest.java b/src/tests/junit/org/apache/tools/ant/filters/ConcatFilterTest.java index 38583540c..06cd2f8d9 100644 --- a/src/tests/junit/org/apache/tools/ant/filters/ConcatFilterTest.java +++ b/src/tests/junit/org/apache/tools/ant/filters/ConcatFilterTest.java @@ -43,32 +43,28 @@ public class ConcatFilterTest { + "Line 1" + lSep + "Line 2" + lSep + "Line 3" + lSep - + "Line 4" + lSep - ; + + "Line 4" + lSep; private static final String FILE_PREPEND = "Line 1" + lSep + "Line 2" + lSep + "Line 3" + lSep + "Line 4" + lSep - + "Line 5" + lSep - ; + + "Line 5" + lSep; private static final String FILE_APPEND_WITH = "Line 57" + lSep + "Line 58" + lSep + "Line 59" + lSep + "Line 60" + lSep - + "this-should-be-the-last-line" + lSep - ; + + "this-should-be-the-last-line" + lSep; private static final String FILE_APPEND = "Line 56" + lSep + "Line 57" + lSep + "Line 58" + lSep + "Line 59" + lSep - + "Line 60" + lSep - ; + + "Line 60" + lSep; @Rule public BuildFileRule buildRule = new BuildFileRule(); diff --git a/src/tests/junit/org/apache/tools/ant/filters/DynamicFilterTest.java b/src/tests/junit/org/apache/tools/ant/filters/DynamicFilterTest.java index 5de7f6bc1..85df0cec8 100644 --- a/src/tests/junit/org/apache/tools/ant/filters/DynamicFilterTest.java +++ b/src/tests/junit/org/apache/tools/ant/filters/DynamicFilterTest.java @@ -49,8 +49,6 @@ public class DynamicFilterTest { assertContains("hellO wOrld", content); } - - public static class CustomFilter implements ChainableReader { char replace = 'x'; char with = 'y'; @@ -65,14 +63,13 @@ public class DynamicFilterTest { public Reader chain(final Reader rdr) { return new BaseFilterReader(rdr) { - public int read() - throws IOException - { + public int read() throws IOException { int c = in.read(); - if (c == replace) + if (c == replace) { return with; - else + } else { return c; + } } }; } diff --git a/src/tests/junit/org/apache/tools/ant/filters/HeadTailTest.java b/src/tests/junit/org/apache/tools/ant/filters/HeadTailTest.java index 7c910d12f..21d25a1aa 100644 --- a/src/tests/junit/org/apache/tools/ant/filters/HeadTailTest.java +++ b/src/tests/junit/org/apache/tools/ant/filters/HeadTailTest.java @@ -38,7 +38,7 @@ public class HeadTailTest { @Rule public BuildFileRule buildRule = new BuildFileRule(); - + @Before public void setUp() { buildRule.configureProject("src/etc/testcases/filters/head-tail.xml"); diff --git a/src/tests/junit/org/apache/tools/ant/filters/LineContainsTest.java b/src/tests/junit/org/apache/tools/ant/filters/LineContainsTest.java index 9dcb291be..d10d9516d 100644 --- a/src/tests/junit/org/apache/tools/ant/filters/LineContainsTest.java +++ b/src/tests/junit/org/apache/tools/ant/filters/LineContainsTest.java @@ -32,10 +32,9 @@ import static org.junit.Assert.assertEquals; public class LineContainsTest { - @Rule public BuildFileRule buildRule = new BuildFileRule(); - + @Before public void setUp() { buildRule.configureProject("src/etc/testcases/filters/build.xml"); diff --git a/src/tests/junit/org/apache/tools/ant/filters/TokenFilterTest.java b/src/tests/junit/org/apache/tools/ant/filters/TokenFilterTest.java index daa7f2e62..38835c4ab 100644 --- a/src/tests/junit/org/apache/tools/ant/filters/TokenFilterTest.java +++ b/src/tests/junit/org/apache/tools/ant/filters/TokenFilterTest.java @@ -251,9 +251,7 @@ public class TokenFilterTest { // Helper methods // ----------------------------------------------------- - private String getFileString(String filename) - throws IOException - { + private String getFileString(String filename) throws IOException { Reader r = null; try { r = new FileReader(FILE_UTILS.resolveFile(buildRule.getProject().getBaseDir(),filename)); @@ -265,9 +263,7 @@ public class TokenFilterTest { } - public static class Capitalize - implements TokenFilter.Filter - { + public static class Capitalize implements TokenFilter.Filter { public String filter(String token) { if (token.length() == 0) return token; diff --git a/src/tests/junit/org/apache/tools/ant/launch/LocatorTest.java b/src/tests/junit/org/apache/tools/ant/launch/LocatorTest.java index 0c3c24fda..318458921 100644 --- a/src/tests/junit/org/apache/tools/ant/launch/LocatorTest.java +++ b/src/tests/junit/org/apache/tools/ant/launch/LocatorTest.java @@ -33,7 +33,8 @@ public class LocatorTest { private boolean windows; private boolean unix; private static final String LAUNCHER_JAR = "//morzine/slo/Java/Apache/ant/lib/ant-launcher.jar"; - private static final String SHARED_JAR_URI = "jar:file:"+ LAUNCHER_JAR +"!/org/apache/tools/ant/launch/Launcher.class"; + private static final String SHARED_JAR_URI = "jar:file:" + LAUNCHER_JAR + + "!/org/apache/tools/ant/launch/Launcher.class"; @Before @@ -84,8 +85,8 @@ public class LocatorTest { /** - * this isnt really a valid URI, except maybe in IE - * @throws Exception + * this isn't really a valid URI, except maybe in IE + * @throws Exception if something goes wrong */ public void testNetworkURI() throws Exception { resolveTo("file:\\\\PC03\\jclasses\\lib\\ant-1.7.0.jar", "" @@ -126,7 +127,7 @@ public class LocatorTest { */ @Test public void testAntOnRemoteShare() throws Throwable { - String resolved=Locator.fromJarURI(SHARED_JAR_URI); + String resolved = Locator.fromJarURI(SHARED_JAR_URI); assertResolved(SHARED_JAR_URI, LAUNCHER_JAR, resolved, unix); assertResolved(SHARED_JAR_URI, LAUNCHER_JAR.replace('/', '\\'), resolved, windows); diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/AntLikeTasksAtTopLevelTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/AntLikeTasksAtTopLevelTest.java index 298bf0987..cb0360956 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/AntLikeTasksAtTopLevelTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/AntLikeTasksAtTopLevelTest.java @@ -67,4 +67,4 @@ public class AntLikeTasksAtTopLevelTest { } } -}// AntLikeTasksAtTopLevelTest +} diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/AntTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/AntTest.java index 0d6453c43..1a1fea827 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/AntTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/AntTest.java @@ -415,12 +415,23 @@ public class AntTest { expectedBasedirs = dirs; } - public void buildStarted(BuildEvent event) {} - public void buildFinished(BuildEvent event) {} - public void targetFinished(BuildEvent event){} - public void taskStarted(BuildEvent event) {} - public void taskFinished(BuildEvent event) {} - public void messageLogged(BuildEvent event) {} + public void buildStarted(BuildEvent event) { + } + + public void buildFinished(BuildEvent event) { + } + + public void targetFinished(BuildEvent event) { + } + + public void taskStarted(BuildEvent event) { + } + + public void taskFinished(BuildEvent event) { + } + + public void messageLogged(BuildEvent event) { + } public void targetStarted(BuildEvent event) { if (event.getTarget().getName().equals("")) { @@ -455,12 +466,23 @@ public class AntTest { this.value = value; } - public void buildStarted(BuildEvent event) {} - public void buildFinished(BuildEvent event) {} - public void targetFinished(BuildEvent event){} - public void taskStarted(BuildEvent event) {} - public void taskFinished(BuildEvent event) {} - public void messageLogged(BuildEvent event) {} + public void buildStarted(BuildEvent event) { + } + + public void buildFinished(BuildEvent event) { + } + + public void targetFinished(BuildEvent event) { + } + + public void taskStarted(BuildEvent event) { + } + + public void taskFinished(BuildEvent event) { + } + + public void messageLogged(BuildEvent event) { + } public void targetStarted(BuildEvent event) { if (event.getTarget().getName().equals("")) { @@ -488,7 +510,7 @@ public class AntTest { String[] l1 = expect.list(); String[] l2 = received.list(); if (l1.length == l2.length) { - for (int i=0; i -1); } - } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/ConditionTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/ConditionTest.java index 1b6c1039b..9329512ff 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/ConditionTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/ConditionTest.java @@ -72,7 +72,7 @@ public class ConditionTest { try { buildRule.executeTarget("condition-empty"); fail("BuildException should have been thrown - no conditions"); - } catch(BuildException ex) { + } catch (BuildException ex) { assertEquals("You must nest a condition into ", ex.getMessage()); } } @@ -255,7 +255,7 @@ public class ConditionTest { try { buildRule.executeTarget("contains-incomplete1"); fail("BuildException should have been thrown - Missing contains attribute"); - } catch(BuildException ex) { + } catch (BuildException ex) { assertEquals("both string and substring are required in contains", ex.getMessage()); } } @@ -265,7 +265,7 @@ public class ConditionTest { try { buildRule.executeTarget("contains-incomplete2"); fail("BuildException should have been thrown - Missing contains attribute"); - } catch(BuildException ex) { + } catch (BuildException ex) { assertEquals("both string and substring are required in contains", ex.getMessage()); } } @@ -293,7 +293,7 @@ public class ConditionTest { try { buildRule.executeTarget("istrue-incomplete"); fail("BuildException should have been thrown - Missing attribute"); - } catch(BuildException ex) { + } catch (BuildException ex) { assertEquals("Nothing to test for truth", ex.getMessage()); } } @@ -322,7 +322,7 @@ public class ConditionTest { try { buildRule.executeTarget("isfalse-incomplete"); fail("BuildException should have been thrown - Missing attribute"); - } catch(BuildException ex) { + } catch (BuildException ex) { assertEquals("Nothing to test for falsehood", ex.getMessage()); } } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/CopyTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/CopyTest.java index 719bc4456..fc03f28a4 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/CopyTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/CopyTest.java @@ -60,7 +60,7 @@ public class CopyTest { public void test1() { buildRule.executeTarget("test1"); File f = new File(buildRule.getProject().getProperty("output"), "copytest1.tmp"); - if ( !f.exists()) { + if (!f.exists()) { fail("Copy failed"); } } @@ -69,7 +69,7 @@ public class CopyTest { public void test2() { buildRule.executeTarget("test2"); File f = new File(buildRule.getProject().getProperty("output"), "copytest1dir/copy.xml"); - if ( !f.exists()) { + if (!f.exists()) { fail("Copy failed"); } } @@ -79,7 +79,7 @@ public class CopyTest { buildRule.executeTarget("test3"); File file3 = new File(buildRule.getProject().getProperty("output"), "copytest3.tmp"); //rollback file timestamp instead of delaying test - FileUtilities.rollbackTimetamps(file3, 3); + FileUtilities.rollbackTimestamps(file3, 3); buildRule.executeTarget("test3Part2"); assertTrue(file3.exists()); @@ -91,19 +91,19 @@ public class CopyTest { assertTrue(file3c.exists()); //file length checks rely on touch generating a zero byte file - if(file3.length()==0) { + if (file3.length()==0) { fail("could not overwrite an existing, older file"); } - if(file3c.length()!=0) { + if (file3c.length()!=0) { fail("could not force overwrite an existing, newer file"); } - if(file3b.length()==0) { + if (file3b.length()==0) { fail("unexpectedly overwrote an existing, newer file"); } //file time checks for java1.2+ - assertTrue(file3a.lastModified()==file3.lastModified()); - assertTrue(file3c.lastModified()issue 60644 */ @Test diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/CopydirTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/CopydirTest.java index a7fdd5cb9..adad99465 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/CopydirTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/CopydirTest.java @@ -79,7 +79,7 @@ public class CopydirTest { @Test public void test5() { buildRule.executeTarget("test5"); - java.io.File f = new java.io.File(new File(buildRule.getProject().getProperty("output")), "taskdefs.tmp"); + File f = new File(new File(buildRule.getProject().getProperty("output")), "taskdefs.tmp"); if (!f.exists() || !f.isDirectory()) { fail("Copy failed"); diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/DefaultExcludesTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/DefaultExcludesTest.java index e093d4f76..06ca3a261 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/DefaultExcludesTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/DefaultExcludesTest.java @@ -157,13 +157,13 @@ public class DefaultExcludesTest { private void assertArrayContentsEquals(String message, String[] expected, String[] actual) { // check that both arrays have the same size assertEquals(message + " : string array length match", expected.length, actual.length); - for (int counter=0; counter < expected.length; counter++) { + for (String element : expected) { boolean found = false; for (int i = 0; !found && i < actual.length; i++) { - found |= expected[counter].equals(actual[i]); + found |= element.equals(actual[i]); } assertTrue(message + " : didn't find element " - + expected[counter] + " in array match", found); + + element + " in array match", found); } } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/DirnameTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/DirnameTest.java index 8db1c5ffd..d8703487c 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/DirnameTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/DirnameTest.java @@ -46,7 +46,7 @@ public class DirnameTest { try { buildRule.executeTarget("test1"); fail("Build exception should have been thrown as property attribute is required"); - } catch(BuildException ex) { + } catch (BuildException ex) { assertEquals("property attribute required", ex.getMessage()); } } @@ -56,7 +56,7 @@ public class DirnameTest { try { buildRule.executeTarget("test2"); fail("Build exception should have been thrown as file attribute is required"); - } catch(BuildException ex) { + } catch (BuildException ex) { assertEquals("file attribute required", ex.getMessage()); } } @@ -66,7 +66,7 @@ public class DirnameTest { try { buildRule.executeTarget("test3"); fail("Build exception should have been thrown as property attribute is required"); - } catch(BuildException ex) { + } catch (BuildException ex) { assertEquals("property attribute required", ex.getMessage()); } } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/EchoTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/EchoTest.java index 5c2ae28e8..8f88ff136 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/EchoTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/EchoTest.java @@ -50,7 +50,7 @@ public class EchoTest { echo.setProject(p); echo.setTaskName("testLogBlankEcho"); echo.execute(); - assertEquals("[testLogBlankEcho] ", logger.lastLoggedMessage ); + assertEquals("[testLogBlankEcho] ", logger.lastLoggedMessage); } @Test @@ -67,15 +67,14 @@ public class EchoTest { echo.setFile(removeThis); echo.setEncoding("UTF-8"); echo.execute(); - String x = FileUtils.readFully(new InputStreamReader(new FileInputStream(removeThis), "UTF-8" )); + String x = FileUtils.readFully(new InputStreamReader(new FileInputStream(removeThis), "UTF-8")); assertEquals(x,"\u00e4\u00a9"); } @After public void tearDown() { if (removeThis != null && removeThis.exists()) { - if (!removeThis.delete()) - { + if (!removeThis.delete()) { removeThis.deleteOnExit(); } } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/ExecuteJavaTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/ExecuteJavaTest.java index 069645b3f..9e87af084 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/ExecuteJavaTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/ExecuteJavaTest.java @@ -37,15 +37,15 @@ public class ExecuteJavaTest { private final static int TIME_OUT = 5000; - private final static int CLOCK_ERROR=200; - private final static int TIME_OUT_TEST=TIME_OUT-CLOCK_ERROR; + private final static int CLOCK_ERROR = 200; + private final static int TIME_OUT_TEST = TIME_OUT - CLOCK_ERROR; private ExecuteJava ej; private Project project; private Path cp; @Before - public void setUp(){ + public void setUp() { ej = new ExecuteJava(); ej.setTimeout((long)TIME_OUT); project = new Project(); @@ -64,7 +64,7 @@ public class ExecuteJavaTest { @Test public void testNoTimeOut() throws Exception { - Commandline cmd = getCommandline(TIME_OUT/2); + Commandline cmd = getCommandline(TIME_OUT / 2); ej.setJavaCommand(cmd); ej.execute(project); assertTrue("process should not have been killed", !ej.killedProcess()); @@ -73,24 +73,24 @@ public class ExecuteJavaTest { // test that the watchdog ends the process @Test public void testTimeOut() throws Exception { - Commandline cmd = getCommandline(TIME_OUT*2); + Commandline cmd = getCommandline(TIME_OUT * 2); ej.setJavaCommand(cmd); long now = System.currentTimeMillis(); ej.execute(project); long elapsed = System.currentTimeMillis() - now; assertTrue("process should have been killed", ej.killedProcess()); - assertTrue("elapse time of "+elapsed - +" ms is less than timeout value of "+TIME_OUT_TEST+" ms", + assertTrue("elapse time of " + elapsed + + " ms is less than timeout value of " + TIME_OUT_TEST + " ms", elapsed >= TIME_OUT_TEST); - assertTrue("elapse time of "+elapsed - +" ms is greater than run value of "+(TIME_OUT*2)+" ms", - elapsed < TIME_OUT*2); + assertTrue("elapse time of " + elapsed + + " ms is greater than run value of " + (TIME_OUT * 2) + " ms", + elapsed < TIME_OUT * 2); } @Test public void testNoTimeOutForked() throws Exception { - Commandline cmd = getCommandline(TIME_OUT/2); + Commandline cmd = getCommandline(TIME_OUT / 2); ej.setJavaCommand(cmd); ej.fork(cp); assertTrue("process should not have been killed", !ej.killedProcess()); @@ -99,26 +99,26 @@ public class ExecuteJavaTest { // test that the watchdog ends the process @Test public void testTimeOutForked() throws Exception { - Commandline cmd = getCommandline(TIME_OUT*2); + Commandline cmd = getCommandline(TIME_OUT * 2); ej.setJavaCommand(cmd); long now = System.currentTimeMillis(); ej.fork(cp); long elapsed = System.currentTimeMillis() - now; assertTrue("process should have been killed", ej.killedProcess()); - assertTrue("elapse time of "+elapsed - +" ms is less than timeout value of "+TIME_OUT_TEST+" ms", + assertTrue("elapse time of " + elapsed + + " ms is less than timeout value of " + TIME_OUT_TEST + " ms", elapsed >= TIME_OUT_TEST); - assertTrue("elapse time of "+elapsed - +" ms is greater than run value of "+(TIME_OUT*2)+" ms", - elapsed < TIME_OUT*2); + assertTrue("elapse time of " + elapsed + + " ms is greater than run value of " + (TIME_OUT * 2) + " ms", + elapsed < TIME_OUT * 2); } /** * Dangerous method to obtain the classpath for the test. This is * severely tighted to the build.xml properties. */ - private static String getTestClassPath(){ + private static String getTestClassPath() { String classpath = System.getProperty("build.tests"); if (classpath == null) { System.err.println("WARNING: 'build.tests' property is not available !"); diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/ExecuteWatchdogTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/ExecuteWatchdogTest.java index 1834d5e3f..f23ea3bcf 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/ExecuteWatchdogTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/ExecuteWatchdogTest.java @@ -40,13 +40,13 @@ public class ExecuteWatchdogTest { private final static String TEST_CLASSPATH = getTestClassPath(); - private final static int CLOCK_ERROR=200; - private final static long TIME_OUT_TEST=TIME_OUT-CLOCK_ERROR; + private final static int CLOCK_ERROR = 200; + private final static long TIME_OUT_TEST = TIME_OUT - CLOCK_ERROR; private ExecuteWatchdog watchdog; @Before - public void setUp(){ + public void setUp() { watchdog = new ExecuteWatchdog(TIME_OUT); } @@ -54,7 +54,7 @@ public class ExecuteWatchdogTest { * Dangerous method to obtain the classpath for the test. This is * severely tied to the build.xml properties. */ - private static String getTestClassPath(){ + private static String getTestClassPath() { String classpath = System.getProperty("build.tests"); if (classpath == null) { System.err.println("WARNING: 'build.tests' property is not available !"); @@ -74,10 +74,10 @@ public class ExecuteWatchdogTest { } private String getErrorOutput(Process p) throws Exception { - BufferedReader err = new BufferedReader( new InputStreamReader(p.getErrorStream()) ); - StringBuffer buf = new StringBuffer(); + BufferedReader err = new BufferedReader(new InputStreamReader(p.getErrorStream())); + StringBuilder buf = new StringBuilder(); String line; - while ( (line = err.readLine()) != null){ + while ((line = err.readLine()) != null) { buf.append(line); } return buf.toString(); @@ -85,9 +85,9 @@ public class ExecuteWatchdogTest { private int waitForEnd(Process p) throws Exception { int retcode = p.waitFor(); - if (retcode != 0){ + if (retcode != 0) { String err = getErrorOutput(p); - if (err.length() > 0){ + if (err.length() > 0) { System.err.println("ERROR:"); System.err.println(err); } @@ -97,25 +97,28 @@ public class ExecuteWatchdogTest { @Test public void testNoTimeOut() throws Exception { - Process process = getProcess(TIME_OUT/2); + Process process = getProcess(TIME_OUT / 2); watchdog.start(process); int retCode = waitForEnd(process); - assertTrue("process should not have been killed", !watchdog.killedProcess()); + assertFalse("process should not have been killed", watchdog.killedProcess()); assertFalse(Execute.isFailure(retCode)); } // test that the watchdog ends the process @Test public void testTimeOut() throws Exception { - Process process = getProcess(TIME_OUT*2); + Process process = getProcess(TIME_OUT * 2); long now = System.currentTimeMillis(); watchdog.start(process); - int retCode = process.waitFor(); + @SuppressWarnings("unused") + int retCode = process.waitFor(); long elapsed = System.currentTimeMillis() - now; assertTrue("process should have been killed", watchdog.killedProcess()); - // assertTrue("return code is invalid: " + retCode, retCode!=0); - assertTrue("elapse time of "+elapsed+" ms is less than timeout value of "+TIME_OUT_TEST+" ms", elapsed >= TIME_OUT_TEST); - assertTrue("elapse time of "+elapsed+" ms is greater than run value of "+(TIME_OUT*2)+" ms", elapsed < TIME_OUT*2); + // assertNotEquals("return code is invalid: " + retCode, retCode, 0); + assertTrue("elapse time of " + elapsed + " ms is less than timeout value of " + TIME_OUT_TEST + " ms", + elapsed >= TIME_OUT_TEST); + assertTrue("elapse time of " + elapsed + " ms is greater than run value of " + (TIME_OUT * 2) + " ms", + elapsed < TIME_OUT * 2); } // test a process that runs and failed @@ -130,7 +133,7 @@ public class ExecuteWatchdogTest { @Test public void testManualStop() throws Exception { - final Process process = getProcess(TIME_OUT*2); + final Process process = getProcess(TIME_OUT * 2); watchdog.start(process); // I assume that starting this takes less than TIME_OUT/2 ms... @@ -146,8 +149,8 @@ public class ExecuteWatchdogTest { }; thread.start(); - // wait for TIME_OUT/2, there should be about TIME_OUT/2 ms remaining before timeout - thread.join(TIME_OUT/2); + // wait for TIME_OUT / 2, there should be about TIME_OUT / 2 ms remaining before timeout + thread.join(TIME_OUT / 2); // now stop the watchdog. watchdog.stop(); diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/FailTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/FailTest.java index 8883558d0..5bcc16967 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/FailTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/FailTest.java @@ -43,7 +43,7 @@ public class FailTest { public void test1() { try { buildRule.executeTarget("test1"); - fail("it is required to fail :-)") ; + fail("it is required to fail :-)"); } catch (BuildException ex) { assertEquals("No message", ex.getMessage()); } @@ -53,7 +53,7 @@ public class FailTest { public void test2() { try { buildRule.executeTarget("test2"); - fail("it is required to fail :-)") ; + fail("it is required to fail :-)"); } catch (BuildException ex) { assertEquals("test2", ex.getMessage()); } @@ -63,7 +63,7 @@ public class FailTest { public void testText() { try { buildRule.executeTarget("testText"); - fail("it is required to fail :-)") ; + fail("it is required to fail :-)"); } catch (BuildException ex) { assertEquals("testText", ex.getMessage()); } @@ -75,7 +75,7 @@ public class FailTest { buildRule.getProject().setProperty("foo", ""); try { buildRule.executeTarget("testIf"); - fail("testIf must fail if foo has been set") ; + fail("testIf must fail if foo has been set"); } catch (BuildException ex) { //TODO assert result } @@ -85,7 +85,7 @@ public class FailTest { public void testUnless() { try { buildRule.executeTarget("testUnless"); - fail("testUnless must fail unless foo has been set") ; + fail("testUnless must fail unless foo has been set"); } catch (BuildException ex) { //TODO assert rules } @@ -106,7 +106,7 @@ public class FailTest { buildRule.getProject().setProperty("if", ""); try { buildRule.executeTarget("testIfAndUnless"); - fail("expect fail on defined(if)") ; + fail("expect fail on defined(if)"); } catch (BuildException ex) { assertEquals("if=if and unless=unless", ex.getMessage()); } @@ -129,7 +129,7 @@ public class FailTest { public void testNested1() { try { buildRule.executeTarget("testNested1"); - fail("it is required to fail :-)") ; + fail("it is required to fail :-)"); } catch (BuildException ex) { assertEquals("condition satisfied", ex.getMessage()); } @@ -144,7 +144,7 @@ public class FailTest { public void testNested3() { try { buildRule.executeTarget("testNested3"); - fail("it is required to fail :-)") ; + fail("it is required to fail :-)"); } catch (BuildException ex) { assertEquals("testNested3", ex.getMessage()); } @@ -156,13 +156,13 @@ public class FailTest { + "not permitted in conjunction with if/unless attributes"; char[] c = {'a', 'b', 'c'}; - StringBuffer target = new StringBuffer("testNested4x"); + StringBuilder target = new StringBuilder("testNested4x"); for (int i = 0; i < c.length; i++) { target.setCharAt(target.length() - 1, c[i]); try { buildRule.executeTarget(target.toString()); - fail("it is required to fail :-)") ; + fail("it is required to fail :-)"); } catch (BuildException ex) { assertEquals(specificMessage, ex.getMessage()); } @@ -173,7 +173,7 @@ public class FailTest { public void testNested5() { try { buildRule.executeTarget("testNested5"); - fail("it is required to fail :-)") ; + fail("it is required to fail :-)"); } catch (BuildException ex) { assertEquals("Only one nested condition is allowed.", ex.getMessage()); } @@ -183,7 +183,7 @@ public class FailTest { public void testNested6() { try { buildRule.executeTarget("testNested6"); - fail("it is required to fail :-)") ; + fail("it is required to fail :-)"); } catch (BuildException ex) { assertEquals("testNested6\ntestNested6\ntestNested6", ex.getMessage()); } @@ -194,13 +194,13 @@ public class FailTest { String specificMessage = "A single nested condition is required."; char[] c = {'a', 'b'}; - StringBuffer target = new StringBuffer("testNested7x"); + StringBuilder target = new StringBuilder("testNested7x"); for (int i = 0; i < c.length; i++) { target.setCharAt(target.length() - 1, c[i]); try { buildRule.executeTarget(target.toString()); - fail("it is required to fail :-)") ; + fail("it is required to fail :-)"); } catch (BuildException ex) { assertEquals(specificMessage, ex.getMessage()); } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/FilterTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/FilterTest.java index fdbec6e84..0e40ad878 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/FilterTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/FilterTest.java @@ -126,19 +126,19 @@ public class FilterTest { String line = null; File f = new File(buildRule.getProject().getBaseDir(), filteredFile); if (!f.exists()) { - fail("filter test"+testNumber+" failed"); + fail("filter test" + testNumber + " failed"); } else { BufferedReader in = null; try { in = new BufferedReader(new FileReader(f)); } catch (FileNotFoundException fnfe) { - fail("filter test"+testNumber+" failed, filtered file: " + f.toString() + " not found"); + fail("filter test" + testNumber + " failed, filtered file: " + f.toString() + " not found"); } try { line = in.readLine(); in.close(); } catch (IOException ioe) { - fail("filter test"+testNumber+" failed. IOException while reading filtered file: " + ioe); + fail("filter test" + testNumber + " failed. IOException while reading filtered file: " + ioe); } } f.delete(); diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/FixCrLfTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/FixCrLfTest.java index 06a18cc84..258688de5 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/FixCrLfTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/FixCrLfTest.java @@ -234,7 +234,7 @@ public class FixCrLfTest { public void assertEqualContent(File expect, File result) throws AssertionFailedError, IOException { if (!result.exists()) { - fail("Expected file "+result+" doesn\'t exist"); + fail("Expected file " + result + " doesn\'t exist"); } InputStream inExpect = null; diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/GUnzipTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/GUnzipTest.java index fc731f75d..a7aac5d22 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/GUnzipTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/GUnzipTest.java @@ -17,6 +17,8 @@ */ package org.apache.tools.ant.taskdefs; +import java.io.IOException; + import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildFileRule; import org.apache.tools.ant.FileUtilities; @@ -64,28 +66,28 @@ public class GUnzipTest { } @Test - public void testRealTest() throws java.io.IOException { + public void testRealTest() throws IOException { testRealTest("realTest"); } @Test - public void testRealTestWithResource() throws java.io.IOException { + public void testRealTestWithResource() throws IOException { testRealTest("realTestWithResource"); } - private void testRealTest(String target) throws java.io.IOException { + private void testRealTest(String target) throws IOException { buildRule.executeTarget(target); assertEquals(FileUtilities.getFileContents(buildRule.getProject().resolveFile("../asf-logo.gif")), FileUtilities.getFileContents(buildRule.getProject().resolveFile("asf-logo.gif"))); } @Test - public void testTestGzipTask() throws java.io.IOException { + public void testTestGzipTask() throws IOException { testRealTest("testGzipTask"); } @Test - public void testDocumentationClaimsOnCopy() throws java.io.IOException { + public void testDocumentationClaimsOnCopy() throws IOException { testRealTest("testDocumentationClaimsOnCopy"); } } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/GzipTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/GzipTest.java index 6319317b3..76342b823 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/GzipTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/GzipTest.java @@ -82,7 +82,7 @@ public class GzipTest { } @Test - public void testGZip(){ + public void testGZip() { buildRule.executeTarget("realTest"); String log = buildRule.getLog(); assertTrue("Expecting message starting with 'Building:' but got '" @@ -92,12 +92,12 @@ public class GzipTest { } @Test - public void testResource(){ + public void testResource() { buildRule.executeTarget("realTestWithResource"); } @Test - public void testDateCheck(){ + public void testDateCheck() { buildRule.executeTarget("testDateCheck"); String log = buildRule.getLog(); assertTrue( @@ -106,7 +106,7 @@ public class GzipTest { } @After - public void tearDown(){ + public void tearDown() { buildRule.executeTarget("cleanup"); } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/ImportTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/ImportTest.java index 5fdf8a445..40a52cd4f 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/ImportTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/ImportTest.java @@ -90,8 +90,9 @@ public class ImportTest { try { buildRule.executeTarget("do-import"); fail("Build exception should have been thrown as import only allowed in top level task"); - } catch(BuildException ex) { - assertContains( "not a top level task", "import only allowed as a top-level task", ex.getMessage()); + } catch (BuildException ex) { + assertContains("not a top level task", "import only allowed as a top-level task", + ex.getMessage()); } } @@ -111,7 +112,8 @@ public class ImportTest { "src/etc/testcases/taskdefs/import/same_target.xml"); fail("Expected build exception"); } catch (BuildException ex) { - assertContains("Message did not contain expected contents", "Duplicate target", ex.getMessage()); + assertContains("Message did not contain expected contents", "Duplicate target", + ex.getMessage()); } } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/JarTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/JarTest.java index 1c6fa94a1..0a26606d6 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/JarTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/JarTest.java @@ -137,7 +137,7 @@ public class JarTest { // move the modified date back a couple of seconds rather than delay the test on each run Assume.assumeTrue(jarFile.setLastModified(jarFile.lastModified() - - (FileUtils.getFileUtils().getFileTimestampGranularity() * 3))); + - FileUtils.getFileUtils().getFileTimestampGranularity() * 3)); long jarModifiedDate = jarFile.lastModified(); buildRule.executeTarget(secondTarget); @@ -169,13 +169,13 @@ public class JarTest { private void testRecreate(String firstTarget, String secondTarget) { //Move the modified date on all input back a couple of seconds rather then delay the test to achieve a similar effect - FileUtilities.rollbackTimetamps(buildRule.getProject().getBaseDir(), 5); + FileUtilities.rollbackTimestamps(buildRule.getProject().getBaseDir(), 5); buildRule.executeTarget(firstTarget); File jarFile = new File(getOutputDir(), tempJar); //Move the modified date back a couple of seconds rather then delay the test to achieve a similar effect - FileUtilities.rollbackTimetamps(buildRule.getOutputDir(), 5); + FileUtilities.rollbackTimestamps(buildRule.getOutputDir(), 5); long jarModifiedDate = jarFile.lastModified(); buildRule.executeTarget(secondTarget); @@ -334,7 +334,7 @@ public class JarTest { public void testNoVersionInfoFail() { try { buildRule.executeTarget("testNoVersionInfoFail"); - fail("BuildException expected: Manifest Implemention information missing."); + fail("BuildException expected: Manifest Implementation information missing."); } catch (BuildException ex) { assertContains("No Implementation-Title set.", ex.getMessage()); } @@ -343,33 +343,33 @@ public class JarTest { @Test public void testNoVersionInfoIgnore() { buildRule.executeTarget("testNoVersionInfoIgnore"); - assertTrue(buildRule.getFullLog().indexOf("No Implementation-Title set.") > -1 ); - assertTrue(buildRule.getFullLog().indexOf("No Implementation-Version set.") > -1 ); - assertTrue(buildRule.getFullLog().indexOf("No Implementation-Vendor set.") > -1 ); + assertTrue(buildRule.getFullLog().indexOf("No Implementation-Title set.") > -1); + assertTrue(buildRule.getFullLog().indexOf("No Implementation-Version set.") > -1); + assertTrue(buildRule.getFullLog().indexOf("No Implementation-Vendor set.") > -1); } @Test public void testNoVersionInfoWarn() { buildRule.executeTarget("testNoVersionInfoWarn"); - assertTrue(buildRule.getLog().indexOf("No Implementation-Title set.") > -1 ); - assertTrue(buildRule.getLog().indexOf("No Implementation-Version set.") > -1 ); - assertTrue(buildRule.getLog().indexOf("No Implementation-Vendor set.") > -1 ); + assertTrue(buildRule.getLog().indexOf("No Implementation-Title set.") > -1); + assertTrue(buildRule.getLog().indexOf("No Implementation-Version set.") > -1); + assertTrue(buildRule.getLog().indexOf("No Implementation-Vendor set.") > -1); } @Test public void testNoVersionInfoNoStrict() { buildRule.executeTarget("testNoVersionInfoNoStrict"); - assertFalse(buildRule.getLog().indexOf("No Implementation-Title set.") > -1 ); - assertFalse(buildRule.getLog().indexOf("No Implementation-Version set.") > -1 ); - assertFalse(buildRule.getLog().indexOf("No Implementation-Vendor set.") > -1 ); + assertFalse(buildRule.getLog().indexOf("No Implementation-Title set.") > -1); + assertFalse(buildRule.getLog().indexOf("No Implementation-Version set.") > -1); + assertFalse(buildRule.getLog().indexOf("No Implementation-Vendor set.") > -1); } @Test public void testHasVersionInfo() { buildRule.executeTarget("testHasVersionInfo"); - assertFalse(buildRule.getLog().indexOf("No Implementation-Title set.") > -1 ); - assertFalse(buildRule.getLog().indexOf("No Implementation-Version set.") > -1 ); - assertFalse(buildRule.getLog().indexOf("No Implementation-Vendor set.") > -1 ); + assertFalse(buildRule.getLog().indexOf("No Implementation-Title set.") > -1); + assertFalse(buildRule.getLog().indexOf("No Implementation-Version set.") > -1); + assertFalse(buildRule.getLog().indexOf("No Implementation-Vendor set.") > -1); } } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/JavaTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/JavaTest.java index 8d9957180..ea1bdbfee 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/JavaTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/JavaTest.java @@ -78,14 +78,15 @@ public class JavaTest { //final String propname="tests-classpath.value"; //String testClasspath=System.getProperty(propname); - //System.out.println("Test cp="+testClasspath); - String runFatal=System.getProperty("junit.run.fatal.tests"); - if(runFatal!=null) - runFatalTests=true; + //System.out.println("Test cp=" + testClasspath); + String runFatal = System.getProperty("junit.run.fatal.tests"); + if (runFatal != null) { + runFatalTests = true; + } } @Test - public void testNoJarNoClassname(){ + public void testNoJarNoClassname() { try { buildRule.executeTarget("testNoJarNoClassname"); fail("Build exception should have been thrown - parameter validation"); @@ -173,20 +174,20 @@ public class JavaTest { assertEquals("Command line should have 5 elements", 5, cmdLine.length); assertEquals("Last command line element should be java argument: " + arg, arg, - cmdLine[cmdLine.length-1]); + cmdLine[cmdLine.length - 1]); assertEquals("The command line element at index 3 should be module name: " + moduleName, moduleName, - cmdLine[cmdLine.length-2]); + cmdLine[cmdLine.length - 2]); assertEquals("The command line element at index 2 should be -m", "-m", - cmdLine[cmdLine.length-3]); + cmdLine[cmdLine.length - 3]); } @Test public void testModuleAndClassnameCommandLine() { final String moduleName = "TestModule"; //NOI18N final String className = "org.apache.Test"; //NOI18N - final String moduleClassPair= String.format("%s/%s", moduleName, className); + final String moduleClassPair = String.format("%s/%s", moduleName, className); final String arg = "appArg"; //NOI18N final Java java = new Java(); java.setFork(true); @@ -199,13 +200,13 @@ public class JavaTest { assertEquals("Command line should have 5 elements", 5, cmdLine.length); assertEquals("Last command line element should be java argument: " + arg, arg, - cmdLine[cmdLine.length-1]); + cmdLine[cmdLine.length - 1]); assertEquals("The command line element at index 3 should be module class pair: " + moduleClassPair, moduleClassPair, - cmdLine[cmdLine.length-2]); + cmdLine[cmdLine.length - 2]); assertEquals("The command line element at index 2 should be -m", "-m", - cmdLine[cmdLine.length-3]); + cmdLine[cmdLine.length - 3]); } @Test @@ -395,7 +396,7 @@ public class JavaTest { // wait a little bit for the task to wait for input Thread.sleep(100); - // write some stuff in the input stream to be catched by the input task + // write some stuff in the input stream to be caught by the input task out.write("foo\n".getBytes()); out.flush(); try { @@ -459,21 +460,21 @@ public class JavaTest { * argv[1] = string to print to System.err (optional) */ public static void main(String[] argv) { - int exitCode=0; - if(argv.length>0) { + int exitCode = 0; + if (argv.length > 0) { try { - exitCode=Integer.parseInt(argv[0]); - } catch(NumberFormatException nfe) { - exitCode=-1; + exitCode = Integer.parseInt(argv[0]); + } catch (NumberFormatException nfe) { + exitCode = -1; } } - if(argv.length>1) { + if (argv.length > 1) { System.out.println(argv[1]); } - if(argv.length>2) { + if (argv.length > 2) { System.err.println(argv[2]); } - if(exitCode!=0) { + if (exitCode != 0) { System.exit(exitCode); } } @@ -503,8 +504,7 @@ public class JavaTest { if (argv.length >= 1) { sleepTime = Integer.parseInt(argv[0]); } - if (argv.length >= 2) - { + if (argv.length >= 2) { logFile = argv[1]; } OutputStreamWriter out = null; @@ -515,9 +515,13 @@ public class JavaTest { FileOutputStream fos = new FileOutputStream(dest); out = new OutputStreamWriter(fos); out.write("bye bye\n"); - } catch (Exception ex) {} - finally { - try {out.close();} catch (IOException ioe) {}} + } catch (Exception ex) { + } finally { + try { + out.close(); + } catch (IOException ioe) { + } + } } } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/JavacTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/JavacTest.java index 364a50e22..ce302dcca 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/JavacTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/JavacTest.java @@ -288,7 +288,7 @@ public class JavacTest { final File tmp = new File(System.getProperty("java.io.tmpdir")); //NOI18N final File destDir = new File(tmp, String.format("%stestMP%d", getClass().getName(), - System.currentTimeMillis()/1000)); + System.currentTimeMillis() / 1000)); destDir.mkdirs(); try { final Path p = new Path(project); diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/LoadFileTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/LoadFileTest.java index ce166d9a0..48f47b890 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/LoadFileTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/LoadFileTest.java @@ -38,19 +38,16 @@ public class LoadFileTest { @Rule public final BuildFileRule buildRule = new BuildFileRule(); - @Before public void setUp() { buildRule.configureProject("src/etc/testcases/taskdefs/loadfile.xml"); } - @After public void tearDown() { buildRule.executeTarget("cleanup"); } - /** * A unit test for JUnit */ @@ -64,7 +61,6 @@ public class LoadFileTest { } } - /** * A unit test for JUnit */ @@ -78,7 +74,6 @@ public class LoadFileTest { } } - /** * A unit test for JUnit */ @@ -96,32 +91,27 @@ public class LoadFileTest { * A unit test for JUnit */ @Test - public void testFailOnError() - throws BuildException { + public void testFailOnError() throws BuildException { buildRule.executeTarget("testFailOnError"); assertNull(buildRule.getProject().getProperty("testFailOnError")); } - /** * A unit test for JUnit */ @Test - public void testLoadAFile() - throws BuildException { + public void testLoadAFile() throws BuildException { buildRule.executeTarget("testLoadAFile"); if(buildRule.getProject().getProperty("testLoadAFile").indexOf("eh?")<0) { fail("property is not all in the file"); } } - /** * A unit test for JUnit */ @Test - public void testLoadAFileEnc() - throws BuildException { + public void testLoadAFileEnc() throws BuildException { buildRule.executeTarget("testLoadAFileEnc"); assertNotNull("file load files", buildRule.getProject().getProperty("testLoadAFileEnc")); } @@ -130,8 +120,7 @@ public class LoadFileTest { * A unit test for JUnit */ @Test - public void testEvalProps() - throws BuildException { + public void testEvalProps() throws BuildException { buildRule.executeTarget("testEvalProps"); if(buildRule.getProject().getProperty("testEvalProps").indexOf("rain")<0) { fail("property eval broken"); @@ -142,8 +131,7 @@ public class LoadFileTest { * Test FilterChain and FilterReaders */ @Test - public void testFilterChain() - throws BuildException { + public void testFilterChain() throws BuildException { buildRule.executeTarget("testFilterChain"); if(buildRule.getProject().getProperty("testFilterChain").indexOf("World!")<0) { fail("Filter Chain broken"); @@ -154,8 +142,7 @@ public class LoadFileTest { * Test StripJavaComments filterreader functionality. */ @Test - public final void testStripJavaComments() - throws BuildException { + public final void testStripJavaComments() throws BuildException { buildRule.executeTarget("testStripJavaComments"); final String expected = buildRule.getProject().getProperty("expected"); final String generated = buildRule.getProject().getProperty("testStripJavaComments"); diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/MakeUrlTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/MakeUrlTest.java index 07e53fd2e..592f1d7ec 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/MakeUrlTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/MakeUrlTest.java @@ -100,7 +100,7 @@ public class MakeUrlTest { /** * test that we can round trip by opening a url that exists * - * @throws IOException + * @throws IOException if something goes wrong */ @Test public void testRoundTrip() throws IOException { @@ -142,8 +142,8 @@ public class MakeUrlTest { /** * assert that a property ends with * - * @param property - * @param ending + * @param property String + * @param ending String */ private void assertPropertyEndsWith(String property, String ending) { String result = getProperty(property); @@ -167,8 +167,8 @@ public class MakeUrlTest { /** * get a property from the project * - * @param property - * @return + * @param property String + * @return String */ protected String getProperty(String property) { return buildRule.getProject().getProperty(property); diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestClassPathTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestClassPathTest.java index 695d45c5e..6fb3d1316 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestClassPathTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestClassPathTest.java @@ -17,7 +17,6 @@ */ package org.apache.tools.ant.taskdefs; - import static org.apache.tools.ant.AntAssert.assertContains; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; @@ -231,8 +230,8 @@ public class ManifestClassPathTest { } else { altDriveLetter = "C"; } - new java.io.File(altDriveLetter + ":/foo.txt").getCanonicalPath(); - } catch (java.io.IOException e) { + new File(altDriveLetter + ":/foo.txt").getCanonicalPath(); + } catch (IOException e) { Assume.assumeNoException("Drive " + altDriveLetter + ": doesn't exist or is not ready", e); } buildRule.getProject().setProperty("altDriveLetter", altDriveLetter); diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestTest.java index 6e7943275..a4a1e4778 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestTest.java @@ -134,9 +134,8 @@ public class ManifestTest { @Test public void test5() { buildRule.executeTarget("test5"); - String output = buildRule.getLog(); - boolean hasWarning = output.indexOf("Manifest warning: \"Name\" attributes should not occur in the main section") != -1; - assertTrue("Expected warning about Name in main section", hasWarning); + assertTrue("Expected warning about Name in main section", buildRule.getLog() + .contains("Manifest warning: \"Name\" attributes should not occur in the main section")); } /** @@ -150,9 +149,8 @@ public class ManifestTest { } catch (BuildException ex) { assertContains("Invalid Manifest", ex.getMessage()); } - String output = buildRule.getLog(); - boolean hasWarning = output.indexOf("Manifest sections should start with a \"Name\" attribute") != -1; - assertTrue("Expected warning about section not starting with Name: attribute", hasWarning); + assertTrue("Expected warning about section not starting with Name: attribute", buildRule.getLog() + .contains("Manifest sections should start with a \"Name\" attribute")); } @@ -162,9 +160,8 @@ public class ManifestTest { @Test public void test7() { buildRule.executeTarget("test7"); - - boolean hasWarning = buildRule.getLog().indexOf(Manifest.ERROR_FROM_FORBIDDEN) != -1; - assertTrue("Expected warning about From: attribute", hasWarning); + assertTrue("Expected warning about From: attribute", buildRule.getLog() + .contains(Manifest.ERROR_FROM_FORBIDDEN)); } /** @@ -245,7 +242,8 @@ public class ManifestTest { buildRule.executeTarget("test13"); fail("BuildException expected: Duplicate Attribute"); } catch (BuildException ex) { - assertContains("The attribute \"Test\" may not occur more than once in the same section", ex.getMessage()); + assertContains("The attribute \"Test\" may not occur more than once in the same section", + ex.getMessage()); } } @@ -269,9 +267,9 @@ public class ManifestTest { public void testLongLine() throws IOException, ManifestException { Project p = buildRule.getProject(); p.setUserProperty("test.longline", LONG_LINE); - p.setUserProperty("test.long68name" , LONG_68_NAME); - p.setUserProperty("test.long70name" , LONG_70_NAME); - p.setUserProperty("test.notlongname" , NOT_LONG_NAME); + p.setUserProperty("test.long68name", LONG_68_NAME); + p.setUserProperty("test.long70name", LONG_70_NAME); + p.setUserProperty("test.notlongname", NOT_LONG_NAME); p.setUserProperty("test.value", VALUE); buildRule.executeTarget("testLongLine"); diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/MkdirTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/MkdirTest.java index 637face93..9864a4af6 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/MkdirTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/MkdirTest.java @@ -17,6 +17,8 @@ */ package org.apache.tools.ant.taskdefs; +import java.io.File; + import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildFileRule; import org.junit.Before; @@ -60,7 +62,7 @@ public class MkdirTest { @Test public void test3() { buildRule.executeTarget("test3"); - java.io.File f = new java.io.File(buildRule.getProject().getProperty("output"), "testdir.tmp"); + File f = new File(buildRule.getProject().getProperty("output"), "testdir.tmp"); if (!f.exists() || !f.isDirectory()) { fail("mkdir failed"); } else { diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/MultiMapTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/MultiMapTest.java index 95f9eafde..2d097881c 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/MultiMapTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/MultiMapTest.java @@ -68,12 +68,17 @@ public class MultiMapTest { } public static class TestMapper implements FileNameMapper { - public TestMapper() {} - public void setFrom(String from) {} - public void setTo(String to) {} + public TestMapper() { + } + + public void setFrom(String from) { + } + + public void setTo(String to) { + } + public String[] mapFileName(final String source_file_name) { - return new String[] { - source_file_name, source_file_name+".copy2" }; + return new String[] {source_file_name, source_file_name + ".copy2"}; } } } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/ParallelTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/ParallelTest.java index 3ca7cf78d..97667e461 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/ParallelTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/ParallelTest.java @@ -46,7 +46,7 @@ public class ParallelTest { /** Standard property value for the fail test */ public final static String FAILURE_MESSAGE = "failure"; - /** the build fiel associated with this test */ + /** the build file associated with this test */ public final static String TEST_BUILD_FILE = "src/etc/testcases/taskdefs/parallel.xml"; diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/PropertyTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/PropertyTest.java index 17e7114e5..7cead6678 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/PropertyTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/PropertyTest.java @@ -66,8 +66,7 @@ public class PropertyTest { try { buildRule.executeTarget("test3"); fail("Did not throw exception on circular exception"); - } - catch (BuildException e) { + } catch (BuildException e) { assertTrue("Circular definition not detected - ", e.getMessage().indexOf("was circularly defined") != -1); } @@ -101,8 +100,7 @@ public class PropertyTest { try { buildRule.executeTarget("prefix.fail"); fail("Did not throw exception on invalid use of prefix"); - } - catch (BuildException e) { + } catch (BuildException e) { assertContains("Prefix allowed on non-resource/file load - ", "Prefix is only valid", e.getMessage()); } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/ReplaceTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/ReplaceTest.java index cd485d034..4e40c2861 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/ReplaceTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/ReplaceTest.java @@ -153,7 +153,7 @@ public class ReplaceTest { public void assertEqualContent(File expect, File result) throws AssertionFailedError, IOException { if (!result.exists()) { - fail("Expected file "+result+" doesn\'t exist"); + fail("Expected file " + result + " doesn\'t exist"); } InputStream inExpect = null; diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/RmicAdvancedTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/RmicAdvancedTest.java index f2f186135..3bbef0e93 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/RmicAdvancedTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/RmicAdvancedTest.java @@ -282,7 +282,7 @@ public class RmicAdvancedTest { public void NotestFailingAdapter() throws Exception { try { buildRule.executeTarget("testFailingAdapter"); - fail("Expected failures to propogate"); + fail("Expected failures to propagate"); } catch (BuildException ex) { AntAssert.assertContains(Rmic.ERROR_RMIC_FAILED, ex.getMessage()); } @@ -291,7 +291,7 @@ public class RmicAdvancedTest { /** * test that version 1.1 stubs are good - * @throws Exception + * @throws Exception if something goes wrong */ @Test public void testVersion11() throws Exception { @@ -300,7 +300,7 @@ public class RmicAdvancedTest { /** * test that version 1.1 stubs are good - * @throws Exception + * @throws Exception if something goes wrong */ @Test public void testVersion11Dest() throws Exception { @@ -310,7 +310,7 @@ public class RmicAdvancedTest { /** * test that version 1.2 stubs are good * - * @throws Exception + * @throws Exception if something goes wrong */ @Test public void testVersion12() throws Exception { @@ -320,7 +320,7 @@ public class RmicAdvancedTest { /** * test that version 1.2 stubs are good * - * @throws Exception + * @throws Exception if something goes wrong */ @Test public void testVersion12Dest() throws Exception { @@ -330,7 +330,7 @@ public class RmicAdvancedTest { /** * test that version compat stubs are good * - * @throws Exception + * @throws Exception if something goes wrong */ @Test public void testVersionCompat() throws Exception { @@ -340,7 +340,7 @@ public class RmicAdvancedTest { /** * test that version compat stubs are good * - * @throws Exception + * @throws Exception if something goes wrong */ @Test public void testVersionCompatDest() throws Exception { @@ -350,7 +350,7 @@ public class RmicAdvancedTest { /** * test that passes -Xnew to sun's rmic running in a different VM. * - * @throws Exception + * @throws Exception if something goes wrong */ @Test public void testXnewForked() throws Exception { @@ -360,7 +360,7 @@ public class RmicAdvancedTest { /** * test that passes -Xnew to sun's rmic running in a different VM. * - * @throws Exception + * @throws Exception if something goes wrong */ @Test public void testXnewForkedDest() throws Exception { @@ -370,7 +370,7 @@ public class RmicAdvancedTest { /** * test that runs the new xnew compiler adapter. * - * @throws Exception + * @throws Exception if something goes wrong */ @Test public void testXnewCompiler() throws Exception { @@ -380,7 +380,7 @@ public class RmicAdvancedTest { /** * test that runs the new xnew compiler adapter. * - * @throws Exception + * @throws Exception if something goes wrong */ @Test public void testXnewCompilerDest() throws Exception { @@ -390,7 +390,7 @@ public class RmicAdvancedTest { /** * test that verifies that IDL compiles. * - * @throws Exception + * @throws Exception if something goes wrong */ @Test public void testIDL() throws Exception { @@ -400,7 +400,7 @@ public class RmicAdvancedTest { /** * test that verifies that IDL compiles. * - * @throws Exception + * @throws Exception if something goes wrong */ @Test public void testIDLDest() throws Exception { @@ -410,7 +410,7 @@ public class RmicAdvancedTest { /** * test that verifies that IIOP compiles. * - * @throws Exception + * @throws Exception if something goes wrong */ @Test public void testIIOP() throws Exception { @@ -420,7 +420,7 @@ public class RmicAdvancedTest { /** * test that verifies that IIOP compiles. * - * @throws Exception + * @throws Exception if something goes wrong */ @Test public void testIIOPDest() throws Exception { diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/RmicTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/RmicTest.java index 8d3200c37..a8ef90c20 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/RmicTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/RmicTest.java @@ -88,7 +88,7 @@ public class RmicTest { // check defaults String compiler = rmic.getCompiler(); assertNotNull(compiler); - assertEquals("expected sun or kaffe, but found "+compiler,compiler,"default"); + assertEquals("expected sun or kaffe, but found " + compiler, compiler,"default"); project.setNewProperty("build.rmic", "weblogic"); compiler = rmic.getCompiler(); diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/SQLExecTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/SQLExecTest.java index fbce8a6d5..dac694110 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/SQLExecTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/SQLExecTest.java @@ -26,8 +26,8 @@ import java.io.File; import java.net.URL; import java.util.logging.Logger; -import org.apache.tools.ant.Project; import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; @@ -70,13 +70,13 @@ public class SQLExecTest { // simple test to ensure that the caching does work... @Test - public void testDriverCaching(){ + public void testDriverCaching() { SQLExec sql = createTask(getProperties(NULL)); assertTrue(!SQLExec.getLoaderMap().containsKey(NULL_DRIVER)); try { sql.execute(); fail("BuildException should have been thrown"); - } catch (BuildException e){ + } catch (BuildException e) { assertContains("No suitable Driver", e.getMessage()); } assertTrue(SQLExec.getLoaderMap().containsKey(NULL_DRIVER)); @@ -104,13 +104,13 @@ public class SQLExecTest { @Ignore @Test - public void testOracle(){ + public void testOracle() { doMultipleCalls(1000, ORACLE, true, false); } @Ignore @Test - public void testMySQL(){ + public void testMySQL() { doMultipleCalls(1000, MYSQL, true, false); } @@ -122,15 +122,15 @@ public class SQLExecTest { * @param caching should caching be enabled ? * @param catchexception true to catch exception for each call, false if not. */ - protected void doMultipleCalls(int calls, int database, boolean caching, boolean catchexception){ + protected void doMultipleCalls(int calls, int database, boolean caching, boolean catchexception) { Properties props = getProperties(database); - for (int i = 0; i < calls; i++){ + for (int i = 0; i < calls; i++) { SQLExec sql = createTask(props); sql.setCaching(caching); try { sql.execute(); - } catch (BuildException e){ - if (!catchexception){ + } catch (BuildException e) { + if (!catchexception) { throw e; } } @@ -141,15 +141,15 @@ public class SQLExecTest { * Create a task from a set of properties * @see #getProperties(int) */ - protected SQLExec createTask(Properties props){ + protected SQLExec createTask(Properties props) { SQLExec sql = new SQLExec(); - sql.setProject( new Project() ); - sql.setDriver( props.getProperty(DRIVER) ); - sql.setUserid( props.getProperty(USER) ); - sql.setPassword( props.getProperty(PASSWORD) ); - sql.setUrl( props.getProperty(URL) ); - sql.createClasspath().setLocation( new File(props.getProperty(PATH)) ); - sql.addText( props.getProperty(SQL) ); + sql.setProject(new Project()); + sql.setDriver(props.getProperty(DRIVER)); + sql.setUserid(props.getProperty(USER)); + sql.setPassword(props.getProperty(PASSWORD)); + sql.setUrl(props.getProperty(URL)); + sql.createClasspath().setLocation(new File(props.getProperty(PATH))); + sql.addText(props.getProperty(SQL)); return sql; } @@ -157,7 +157,7 @@ public class SQLExecTest { * try to find the path from a resource (jar file or directory name) * so that it can be used as a classpath to load the resource. */ - protected String findResourcePath(String resource){ + protected String findResourcePath(String resource) { resource = resource.replace('.', '/') + ".class"; URL url = getClass().getClassLoader().getResource(resource); if (url == null) { @@ -180,9 +180,9 @@ public class SQLExecTest { * tweak this to make it run or add your own database. * The driver lib should be dropped into the system classloader. */ - protected Properties getProperties(int database){ + protected Properties getProperties(int database) { Properties props = null; - switch (database){ + switch (database) { case ORACLE: props = getProperties("oracle.jdbc.driver.OracleDriver", "test", "test", "jdbc:oracle:thin:@127.0.0.1:1521:orcl"); break; @@ -201,7 +201,7 @@ public class SQLExecTest { } /** helper method to build properties */ - protected Properties getProperties(String driver, String user, String pwd, String url){ + protected Properties getProperties(String driver, String user, String pwd, String url) { Properties props = new Properties(); props.put(DRIVER, driver); props.put(USER, user); diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/SleepTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/SleepTest.java index f34c26c27..e9db64be2 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/SleepTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/SleepTest.java @@ -33,8 +33,7 @@ public class SleepTest { public final BuildFileRule buildRule = new BuildFileRule(); private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/"; - private final static int ERROR_RANGE=1000; - + private final static int ERROR_RANGE = 1000; @Before public void setUp() { @@ -43,34 +42,34 @@ public class SleepTest { @Test public void test1() { - Timer timer=new Timer(); + Timer timer = new Timer(); buildRule.executeTarget("test1"); timer.stop(); - assertTrue(timer.time()>=0); + assertTrue(timer.time() >= 0); } @Test public void test2() { - Timer timer=new Timer(); + Timer timer = new Timer(); buildRule.executeTarget("test2"); timer.stop(); - assertTrue(timer.time()>=0); + assertTrue(timer.time() >= 0); } @Test public void test3() { - Timer timer=new Timer(); + Timer timer = new Timer(); buildRule.executeTarget("test3"); timer.stop(); - assertTrue(timer.time()>=(2000-ERROR_RANGE)); + assertTrue(timer.time() >= (2000 - ERROR_RANGE)); } @Test public void test4() { - Timer timer=new Timer(); + Timer timer = new Timer(); buildRule.executeTarget("test3"); timer.stop(); - assertTrue(timer.time()>=(2000-ERROR_RANGE) && timer.time()<60000); + assertTrue(timer.time() >= (2000 - ERROR_RANGE) && timer.time() < 60000); } @Test @@ -85,10 +84,10 @@ public class SleepTest { @Test public void test6() { - Timer timer=new Timer(); + Timer timer = new Timer(); buildRule.executeTarget("test6"); timer.stop(); - assertTrue(timer.time()<2000); + assertTrue(timer.time() < 2000); } @@ -96,23 +95,23 @@ public class SleepTest { * inner timer class */ private static class Timer { - long start=0; - long stop=0; + long start = 0; + long stop = 0; public Timer() { start(); } public void start() { - start=System.currentTimeMillis(); + start = System.currentTimeMillis(); } public void stop() { - stop=System.currentTimeMillis(); + stop = System.currentTimeMillis(); } public long time() { - return stop-start; + return stop - start; } } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/StyleTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/StyleTest.java index 24c4e9de7..a45a0984f 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/StyleTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/StyleTest.java @@ -64,7 +64,7 @@ public class StyleTest { public void testTransferParameterSet() throws Exception { expectFileContains("testTransferParameterSet", // target buildRule.getOutputDir().getAbsoluteFile() + "/out.xml", // file - "set='myvalue'"); // exptected string + "set='myvalue'"); // expected string } @Test @@ -207,8 +207,7 @@ public class StyleTest { private void expectFileContains( String target, String filename, String contains) - throws IOException - { + throws IOException { buildRule.executeTarget(target); assertFileContains(filename, contains); } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/SubAntTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/SubAntTest.java index 58ee4f3e9..de067539d 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/SubAntTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/SubAntTest.java @@ -130,12 +130,23 @@ public class SubAntTest { expectedBasedirs = dirs; } - public void buildStarted(BuildEvent event) {} - public void buildFinished(BuildEvent event) {} - public void targetFinished(BuildEvent event){} - public void taskStarted(BuildEvent event) {} - public void taskFinished(BuildEvent event) {} - public void messageLogged(BuildEvent event) {} + public void buildStarted(BuildEvent event) { + } + + public void buildFinished(BuildEvent event) { + } + + public void targetFinished(BuildEvent event) { + } + + public void taskStarted(BuildEvent event) { + } + + public void taskFinished(BuildEvent event) { + } + + public void messageLogged(BuildEvent event) { + } public void targetStarted(BuildEvent event) { if (event.getTarget().getName().equals("")) { diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/TStampTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/TStampTest.java index 71921cbf6..033d1b9ff 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/TStampTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/TStampTest.java @@ -17,13 +17,13 @@ */ package org.apache.tools.ant.taskdefs; +import java.text.SimpleDateFormat; import java.util.Calendar; -import java.util.TimeZone; import java.util.Date; -import java.text.SimpleDateFormat; +import java.util.TimeZone; -import org.apache.tools.ant.Project; import org.apache.tools.ant.Location; +import org.apache.tools.ant.Project; import org.junit.Before; import org.junit.Test; @@ -59,7 +59,7 @@ public class TStampTest { String today = project.getProperty("today"); SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss z"); - sdf.setTimeZone( TimeZone.getTimeZone("GMT") ); + sdf.setTimeZone(TimeZone.getTimeZone("GMT")); String expected = sdf.format(date); assertEquals(expected, today); @@ -68,7 +68,7 @@ public class TStampTest { /** * verifies that custom props have priority over the * originals - * @throws Exception + * @throws Exception if something goes wrong */ @Test public void testWriteOrder() throws Exception { @@ -81,7 +81,7 @@ public class TStampTest { String today = project.getProperty("TODAY"); SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss z"); - sdf.setTimeZone( TimeZone.getTimeZone("GMT") ); + sdf.setTimeZone(TimeZone.getTimeZone("GMT")); String expected = sdf.format(date); assertEquals(expected, today); @@ -91,13 +91,13 @@ public class TStampTest { /** * verifies that custom props have priority over the * originals - * @throws Exception + * @throws Exception if something goes wrong */ @Test public void testPrefix() throws Exception { tstamp.setPrefix("prefix"); tstamp.execute(); - String prop= project.getProperty("prefix.DSTAMP"); + String prop = project.getProperty("prefix.DSTAMP"); assertNotNull(prop); } @@ -110,7 +110,7 @@ public class TStampTest { tstamp.setPrefix("prefix"); tstamp.execute(); - String prop= project.getProperty("prefix.format"); + String prop = project.getProperty("prefix.format"); assertNotNull(prop); } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/TarTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/TarTest.java index 3d77ba1f4..9650dfcfd 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/TarTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/TarTest.java @@ -165,7 +165,7 @@ public class TarTest { File f1 = new File(buildRule.getProject().getProperty("output"), "untar/test8.xml"); if (! f1.exists()) { - fail("The fullpath attribute or the preserveLeadingSlashes attribute does not work propertly"); + fail("The fullpath attribute or the preserveLeadingSlashes attribute does not work properly"); } } @@ -185,7 +185,7 @@ public class TarTest { File f1 = new File(buildRule.getProject().getProperty("output"), "untar/test10.xml"); if (! f1.exists()) { - fail("The fullpath attribute or the preserveLeadingSlashes attribute does not work propertly"); + fail("The fullpath attribute or the preserveLeadingSlashes attribute does not work properly"); } } @@ -195,7 +195,7 @@ public class TarTest { File f1 = new File(buildRule.getProject().getProperty("output"), "untar/test11.xml"); if (! f1.exists()) { - fail("The fullpath attribute or the preserveLeadingSlashes attribute does not work propertly"); + fail("The fullpath attribute or the preserveLeadingSlashes attribute does not work properly"); } } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/TestProcess.java b/src/tests/junit/org/apache/tools/ant/taskdefs/TestProcess.java index 062003fa6..a61ca3cb4 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/TestProcess.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/TestProcess.java @@ -24,23 +24,17 @@ import org.junit.internal.AssumptionViolatedException; * Interactive Testcase for Processdestroyer. * */ -public class TestProcess - implements Runnable -{ +public class TestProcess implements Runnable { private boolean run = true; private boolean done = false; - public void shutdown() - { - if (!done) - { + public void shutdown() { + if (!done) { System.out.println("shutting down TestProcess"); run = false; - synchronized(this) - { - while (!done) - { + synchronized (this) { + while (!done) { try { wait(); } catch (InterruptedException ie) { @@ -53,10 +47,8 @@ public class TestProcess } } - public void run() - { - for (int i = 0; i < 5 && run; i++) - { + public void run() { + for (int i = 0; i < 5 && run; i++) { System.out.println(Thread.currentThread().getName()); try { @@ -66,29 +58,23 @@ public class TestProcess } } - synchronized(this) - { + synchronized (this) { done = true; notifyAll(); } } - public Thread getShutdownHook() - { + public Thread getShutdownHook() { return new TestProcessShutdownHook(); } - private class TestProcessShutdownHook - extends Thread - { - public void run() - { + private class TestProcessShutdownHook extends Thread { + public void run() { shutdown(); } } - public static void main(String[] args) - { + public static void main(String[] args) { TestProcess tp = new TestProcess(); new Thread(tp, "TestProcess thread").start(); Runtime.getRuntime().addShutdownHook(tp.getShutdownHook()); diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/TouchTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/TouchTest.java index 0a968b25a..c19ed33d2 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/TouchTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/TouchTest.java @@ -56,7 +56,7 @@ public class TouchTest { public long getTargetTime() { File file = new File(System.getProperty("root"), TOUCH_FILE); - if(!file.exists()) { + if (!file.exists()) { throw new BuildException("failed to touch file " + file); } return file.lastModified(); @@ -94,7 +94,7 @@ public class TouchTest { */ @Test public void testNow() { - long now=System.currentTimeMillis(); + long now = System.currentTimeMillis(); buildRule.executeTarget("testNow"); long time = getTargetTime(); assertTimesNearlyMatch(time,now,5000); @@ -179,8 +179,8 @@ public class TouchTest { /** * run a target to touch the test file; verify the timestamp is as expected - * @param targetName - * @param timestamp + * @param targetName String + * @param timestamp long */ private void touchFile(String targetName, long timestamp) { buildRule.executeTarget(targetName); @@ -190,8 +190,8 @@ public class TouchTest { /** * assert that two times are within the current FS granularity; - * @param timestamp - * @param time + * @param timestamp long + * @param time long */ public void assertTimesNearlyMatch(long timestamp,long time) { long granularity= FILE_UTILS.getFileTimestampGranularity(); @@ -200,9 +200,9 @@ public class TouchTest { /** * assert that two times are within a specified range - * @param timestamp - * @param time - * @param range + * @param timestamp long + * @param time long + * @param range long */ private void assertTimesNearlyMatch(long timestamp, long time, long range) { assertTrue("Time " + timestamp + " is not within " + range + " ms of " diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/TypeAdapterTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/TypeAdapterTest.java index 14c1c56df..bf8f28d30 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/TypeAdapterTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/TypeAdapterTest.java @@ -20,8 +20,8 @@ package org.apache.tools.ant.taskdefs; import java.lang.reflect.Method; -import org.apache.tools.ant.BuildFileRule; import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; import org.apache.tools.ant.TypeAdapter; @@ -116,8 +116,7 @@ public class TypeAdapterTest { } public static class RunnableAdapter - extends Task implements TypeAdapter - { + extends Task implements TypeAdapter { private String execMethodName = "run"; private Object proxy; @@ -128,14 +127,12 @@ public class TypeAdapterTest { String message = "return type of " + execMethodName + "() should be " + "void but was \"" + execMethod.getReturnType() + - "\" in " - + proxyClass; + "\" in " + proxyClass; log(message, Project.MSG_WARN); } return execMethod; } catch (NoSuchMethodException e) { - String message = "No public "+ execMethodName + - "() method in " + String message = "No public " + execMethodName + "() method in " + proxyClass; log(message, Project.MSG_ERR); throw new BuildException(message); diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/TypedefTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/TypedefTest.java index 242f7c66a..0b938261e 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/TypedefTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/TypedefTest.java @@ -113,7 +113,7 @@ public class TypedefTest { } @Test - public void testNoResourceOnErrorFailAll(){ + public void testNoResourceOnErrorFailAll() { try { buildRule.executeTarget("noresourcefailall"); fail("BuildException expected: the requested resource does not exist"); @@ -123,13 +123,13 @@ public class TypedefTest { } @Test - public void testNoResourceOnErrorFail(){ + public void testNoResourceOnErrorFail() { buildRule.executeTarget("noresourcefail"); assertContains("Could not load definitions from resource ", buildRule.getLog()); } @Test - public void testNoResourceOnErrorNotFail(){ + public void testNoResourceOnErrorNotFail() { buildRule.executeTarget("noresourcenotfail"); assertContains("Could not load definitions from resource ", buildRule.getLog()); } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/UntarTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/UntarTest.java index e0f7eb2a1..ea0c60cf1 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/UntarTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/UntarTest.java @@ -25,6 +25,7 @@ import org.junit.Rule; import org.junit.Test; import java.io.File; +import java.io.IOException; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -43,32 +44,32 @@ public class UntarTest { } @Test - public void testRealTest() throws java.io.IOException { + public void testRealTest() throws IOException { testLogoExtraction("realTest"); } @Test - public void testRealGzipTest() throws java.io.IOException { + public void testRealGzipTest() throws IOException { testLogoExtraction("realGzipTest"); } @Test - public void testRealBzip2Test() throws java.io.IOException { + public void testRealBzip2Test() throws IOException { testLogoExtraction("realBzip2Test"); } @Test - public void testTestTarTask() throws java.io.IOException { + public void testTestTarTask() throws IOException { testLogoExtraction("testTarTask"); } @Test - public void testTestGzipTarTask() throws java.io.IOException { + public void testTestGzipTarTask() throws IOException { testLogoExtraction("testGzipTarTask"); } @Test - public void testTestBzip2TarTask() throws java.io.IOException { + public void testTestBzip2TarTask() throws IOException { testLogoExtraction("testBzip2TarTask"); } @@ -91,11 +92,11 @@ public class UntarTest { } @Test - public void testResourceCollection() throws java.io.IOException { + public void testResourceCollection() throws IOException { testLogoExtraction("resourceCollection"); } - private void testLogoExtraction(String target) throws java.io.IOException { + private void testLogoExtraction(String target) throws IOException { buildRule.executeTarget(target); assertEquals(FileUtilities.getFileContents(buildRule.getProject().resolveFile("../asf-logo.gif")), FileUtilities.getFileContents(new File(buildRule.getProject().getProperty("output"), "untar/asf-logo.gif"))); diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/UnzipTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/UnzipTest.java index 199756112..661d6e984 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/UnzipTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/UnzipTest.java @@ -74,14 +74,14 @@ public class UnzipTest { @Test - public void testRealTest() throws java.io.IOException { + public void testRealTest() throws IOException { buildRule.executeTarget("realTest"); assertLogoUncorrupted(); } /** * test that the logo gif file has not been corrupted - * @throws IOException + * @throws IOException if something goes wrong */ private void assertLogoUncorrupted() throws IOException { assertEquals(FileUtilities.getFileContents(buildRule.getProject().resolveFile("../asf-logo.gif")), @@ -90,13 +90,13 @@ public class UnzipTest { } @Test - public void testTestZipTask() throws java.io.IOException { + public void testTestZipTask() throws IOException { buildRule.executeTarget("testZipTask"); assertLogoUncorrupted(); } @Test - public void testTestUncompressedZipTask() throws java.io.IOException { + public void testTestUncompressedZipTask() throws IOException { buildRule.executeTarget("testUncompressedZipTask"); assertLogoUncorrupted(); } @@ -204,7 +204,7 @@ public class UnzipTest { } /** - * assert that a file doesnt exist, relative to the project + * assert that a file doesn't exist, relative to the project * * @param message message if there is no mpatch * @param filename filename to resolve against the project diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/UpToDateTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/UpToDateTest.java index 4428b93ad..97a3c8cee 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/UpToDateTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/UpToDateTest.java @@ -43,7 +43,7 @@ public class UpToDateTest { File srcDir = buildRule.getProject().resolveFile("source"); assumeTrue("Could not change modification timestamp of source directory", srcDir.setLastModified(srcDir.lastModified() - - (3 * FileUtils.getFileUtils().getFileTimestampGranularity()))); + - 3 * FileUtils.getFileUtils().getFileTimestampGranularity())); } @After diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/XmlPropertyTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/XmlPropertyTest.java index 89069173b..1cb722f70 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/XmlPropertyTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/XmlPropertyTest.java @@ -79,7 +79,7 @@ public class XmlPropertyTest { } @Test - public void testNone () throws IOException { + public void testNone() throws IOException { doTest("testNone", false, false, false, false, false); } @@ -89,47 +89,47 @@ public class XmlPropertyTest { } @Test - public void testCollapse () throws IOException { + public void testCollapse() throws IOException { doTest("testCollapse", false, true, false, false, false); } @Test - public void testSemantic () throws IOException { + public void testSemantic() throws IOException { doTest("testSemantic", false, false, true, false, false); } @Test - public void testKeeprootCollapse () throws IOException { + public void testKeeprootCollapse() throws IOException { doTest("testKeeprootCollapse", true, true, false, false, false); } @Test - public void testKeeprootSemantic () throws IOException { + public void testKeeprootSemantic() throws IOException { doTest("testKeeprootSemantic", true, false, true, false, false); } @Test - public void testCollapseSemantic () throws IOException { + public void testCollapseSemantic() throws IOException { doTest("testCollapseSemantic", false, true, true, false, false); } @Test - public void testKeeprootCollapseSemantic () throws IOException { + public void testKeeprootCollapseSemantic() throws IOException { doTest("testKeeprootCollapseSemantic", true, true, true, false, false); } @Test - public void testInclude () throws IOException { + public void testInclude() throws IOException { doTest("testInclude", false, false, false, true, false); } @Test - public void testSemanticInclude () throws IOException { + public void testSemanticInclude() throws IOException { doTest("testSemanticInclude", false, false, true, true, false); } @Test - public void testSemanticLocal () throws IOException { + public void testSemanticLocal() throws IOException { doTest("testSemanticInclude", false, false, true, false, true); } @@ -152,7 +152,7 @@ public class XmlPropertyTest { // What's the working directory? If local, then its the // folder of the input file. Otherwise, its the "current" dir.. File workingDir; - if ( localRoot ) { + if (localRoot) { workingDir = inputFile.getParentFile(); } else { workingDir = FILE_UTILS.resolveFile(new File("."), "."); @@ -206,13 +206,13 @@ public class XmlPropertyTest { * but some other properties may get set in the XmlProperty due * to generic Project/Task configuration. */ - private static void ensureProperties (String msg, File inputFile, + private static void ensureProperties(String msg, File inputFile, File workingDir, Project p, Properties properties) { Hashtable xmlproperties = p.getProperties(); // Every key identified by the Properties must have been loaded. - Enumeration propertyKeyEnum = properties.propertyNames(); - while(propertyKeyEnum.hasMoreElements()){ + Enumeration propertyKeyEnum = properties.propertyNames(); + while (propertyKeyEnum.hasMoreElements()) { String currentKey = propertyKeyEnum.nextElement().toString(); String assertMsg = msg + "-" + inputFile.getName() + " Key=" + currentKey; @@ -227,10 +227,9 @@ public class XmlPropertyTest { // that the object was created with the given id. // We don't have an adequate way of testing the actual // *value* of the Path object, though... - String id = currentKey; - Object obj = p.getReferences().get(id); + Object obj = p.getReferences().get(currentKey); - if ( obj == null ) { + if (obj == null) { fail(assertMsg + " Object ID does not exist."); } @@ -286,13 +285,10 @@ public class XmlPropertyTest { String currentKey = referenceKeyEnum.nextElement().toString(); Object currentValue = references.get(currentKey); - if (currentValue instanceof Path) { - } else if (currentValue instanceof String) { - } else { - if( ! currentKey.startsWith("ant.") ) { - fail(msg + "-" + inputFile.getName() + " Key=" - + currentKey + " is not a recognized type."); - } + if (!(currentValue instanceof Path) && !(currentValue instanceof String) + && !currentKey.startsWith("ant.")) { + fail(msg + "-" + inputFile.getName() + " Key=" + + currentKey + " is not a recognized type."); } } } @@ -301,7 +297,7 @@ public class XmlPropertyTest { * Munge the name of the input file to find an appropriate goldfile, * based on hardwired naming conventions. */ - private static File getGoldfile (File input, boolean keepRoot, + private static File getGoldfile(File input, boolean keepRoot, boolean collapse, boolean semantic, boolean include, boolean localRoot) { // Substitute .xml with .properties @@ -358,14 +354,13 @@ public class XmlPropertyTest { return true; } else { return (file.getPath().indexOf("taskdefs") > 0 && - file.getPath().toLowerCase().endsWith(".xml") ); + file.getPath().toLowerCase().endsWith(".xml")); } } }; File[] files = startingDir.listFiles(filter); - for (int i=0;i iterator() { return Collections.singleton(r).iterator(); } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/ZipTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/ZipTest.java index d1340b504..276157d60 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/ZipTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/ZipTest.java @@ -101,7 +101,7 @@ public class ZipTest { @After public void tearDown() { try { - if ( zfPrefixAddsDir != null) { + if (zfPrefixAddsDir != null) { zfPrefixAddsDir.close(); } @@ -189,21 +189,25 @@ public class ZipTest { public void testEmptySkip() { buildRule.executeTarget("testEmptySkip"); } + // Bugzilla Report 30365 @Test public void testZipEmptyDir() { buildRule.executeTarget("zipEmptyDir"); } + // Bugzilla Report 40258 @Test public void testZipEmptyDirFilesOnly() { buildRule.executeTarget("zipEmptyDirFilesOnly"); } + @Test public void testZipEmptyCreate() { buildRule.executeTarget("zipEmptyCreate"); assertContains("Note: creating empty", buildRule.getLog()); } + // Bugzilla Report 25513 @Test public void testCompressionLevel() { diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapterTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapterTest.java index 63203bfd2..5595873ab 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapterTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapterTest.java @@ -40,7 +40,7 @@ import static org.junit.Assert.assertEquals; public class DefaultCompilerAdapterTest { private static class LogCapturingJavac extends Javac { - private StringBuffer sb = new StringBuffer(); + private StringBuilder sb = new StringBuilder(); public void log(String msg, int msgLevel) { sb.append(msg); } @@ -58,7 +58,9 @@ public class DefaultCompilerAdapterTest { return cmd; } - public boolean execute() { return false; } + public boolean execute() { + return false; + } /** * public to avoid classloader issues. @@ -70,7 +72,9 @@ public class DefaultCompilerAdapterTest { private static class SourceTargetHelperNoOverride extends DefaultCompilerAdapter { - public boolean execute() { return false; } + public boolean execute() { + return false; + } /** * public to avoid classloader issues. @@ -357,6 +361,7 @@ public class DefaultCompilerAdapterTest { src.mkdir(); final File java1 = createFile(src,"main/m1/lin/classes/org/apache/ant/tests/J1.java"); final File java2 = createFile(src,"main/m3/sol/classes/org/apache/ant/tests/J2.java"); + @SuppressWarnings("unused") final File java3 = createFile(src,"main/m3/sol/classes/org/apache/ant/invisible/J3.java"); final File build = new File(workDir, "build"); build.mkdirs(); @@ -501,7 +506,7 @@ public class DefaultCompilerAdapterTest { final File destDir = new File(tmp, String.format("%s%s%d", getClass().getName(), testName, - System.currentTimeMillis()/1000)); + System.currentTimeMillis() / 1000)); destDir.mkdirs(); return destDir; } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsReachableTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsReachableTest.java index d036834ce..a58fb970d 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsReachableTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsReachableTest.java @@ -68,7 +68,7 @@ public class IsReachableTest { try { buildRule.executeTarget("testBoth"); fail("Build exception expected: error on two targets"); - } catch(BuildException ex) { + } catch (BuildException ex) { assertEquals(IsReachable.ERROR_BOTH_TARGETS, ex.getMessage()); } } @@ -78,7 +78,7 @@ public class IsReachableTest { try { buildRule.executeTarget("testNoTargets"); fail("Build exception expected: no params"); - } catch(BuildException ex) { + } catch (BuildException ex) { assertEquals(IsReachable.ERROR_NO_HOSTNAME, ex.getMessage()); } } @@ -88,7 +88,7 @@ public class IsReachableTest { try { buildRule.executeTarget("testBadTimeout"); fail("Build exception expected: error on -ve timeout"); - } catch(BuildException ex) { + } catch (BuildException ex) { assertEquals(IsReachable.ERROR_BAD_TIMEOUT, ex.getMessage()); } } @@ -99,7 +99,7 @@ public class IsReachableTest { try { buildRule.executeTarget("testFile"); fail("Build exception expected: error on file URL"); - } catch(BuildException ex) { + } catch (BuildException ex) { assertEquals(IsReachable.ERROR_NO_HOST_IN_URL, ex.getMessage()); } } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/cvslib/ChangeLogParserTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/cvslib/ChangeLogParserTest.java index 3dfaf8dd2..fd065d1e4 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/cvslib/ChangeLogParserTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/cvslib/ChangeLogParserTest.java @@ -20,9 +20,9 @@ package org.apache.tools.ant.taskdefs.cvslib; import org.junit.Test; import java.util.Calendar; +import java.util.Date; import java.util.Locale; import java.util.TimeZone; -import java.util.Date; import static org.junit.Assert.assertEquals; diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/cvslib/ChangeLogWriterTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/cvslib/ChangeLogWriterTest.java index a2531d8e9..ba464a91c 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/cvslib/ChangeLogWriterTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/cvslib/ChangeLogWriterTest.java @@ -17,21 +17,21 @@ */ package org.apache.tools.ant.taskdefs.cvslib; -import java.util.Date; -import java.io.PrintWriter; -import java.io.OutputStreamWriter; -import java.io.ByteArrayOutputStream; import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.InputStream; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.util.Date; import org.apache.tools.ant.util.JAXPUtils; import org.junit.Test; -import org.xml.sax.XMLReader; -import org.xml.sax.InputSource; +import org.xml.sax.Attributes; import org.xml.sax.ContentHandler; -import org.xml.sax.SAXException; +import org.xml.sax.InputSource; import org.xml.sax.Locator; -import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.XMLReader; /** * Test for the cvslib ChangeLogWriter @@ -65,11 +65,12 @@ public class ChangeLogWriterTest { public void startDocument() throws SAXException { } - public void characters(char ch[], int start, int length) throws SAXException { + public void characters(char[] ch, int start, int length) throws SAXException { + @SuppressWarnings("unused") String debug = new String(ch, start, length); } - public void ignorableWhitespace(char ch[], int start, int length) throws SAXException { + public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException { } public void endPrefixMapping(String prefix) throws SAXException { diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/dir2/A.java b/src/tests/junit/org/apache/tools/ant/taskdefs/dir2/A.java index 5186ac4c7..437e0bc70 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/dir2/A.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/dir2/A.java @@ -24,14 +24,14 @@ public class A { System.out.println(a); } - static A a=new A(); + static A a = new A(); static { System.out.println("A CLASS INITIALIZATION"); } protected static void setA(A oa) { - a=oa; + a = oa; } public String toString() { diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/email/EmailAddressTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/email/EmailAddressTest.java index 31ecafbae..00befcd7a 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/email/EmailAddressTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/email/EmailAddressTest.java @@ -30,83 +30,83 @@ public class EmailAddressTest { @Test public void test1() { - expectNameAddress( new EmailAddress("address (name)") ); + expectNameAddress(new EmailAddress("address (name)")); } @Test public void test2() { - expectNameAddress( new EmailAddress("(name) address") ); + expectNameAddress(new EmailAddress("(name) address")); } @Test public void test3() { - expectNameAddress( new EmailAddress("name
") ); + expectNameAddress(new EmailAddress("name
")); } @Test public void test4() { - expectNameAddress( new EmailAddress("
name") ); + expectNameAddress(new EmailAddress("
name")); } @Test public void test5() { - expectNameAddress( new EmailAddress("
(name)") ); + expectNameAddress(new EmailAddress("
(name)")); } @Test public void test6() { - expectNameAddress( new EmailAddress("(name)
") ); + expectNameAddress(new EmailAddress("(name)
")); } @Test public void test7() { - expectNameAddress2( new EmailAddress("address ()") ); + expectNameAddress2(new EmailAddress("address ()")); } @Test public void test8() { - expectNameAddress2( new EmailAddress("() address") ); + expectNameAddress2(new EmailAddress("() address")); } @Test public void test9() { - expectNameAddress3( new EmailAddress("address") ); + expectNameAddress3(new EmailAddress("address")); } @Test public void testA() { - expectNameAddress3( new EmailAddress("
") ); + expectNameAddress3(new EmailAddress("
")); } @Test public void testB() { - expectNameAddress3( new EmailAddress("
") ); + expectNameAddress3(new EmailAddress("
")); } @Test public void testC() { - expectNameAddress3( new EmailAddress("< address >") ); + expectNameAddress3(new EmailAddress("< address >")); } @Test public void testD() { - expectNameAddress3( new EmailAddress(" < address > ") ); + expectNameAddress3(new EmailAddress(" < address > ")); } private void expectNameAddress(EmailAddress e) { - assertEquals( "name", e.getName() ); - assertEquals( "address", e.getAddress() ); + assertEquals("name", e.getName()); + assertEquals("address", e.getAddress()); } // where the name contains <> private void expectNameAddress2(EmailAddress e) { - assertEquals( "", e.getName() ); - assertEquals( "address", e.getAddress() ); + assertEquals("", e.getName()); + assertEquals("address", e.getAddress()); } // where only an address is supplied private void expectNameAddress3(EmailAddress e) { assertNull("Expected null, found <" + e.getName() + ">", e.getName()); - assertEquals( "address", e.getAddress() ); + assertEquals("address", e.getAddress()); } } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ANTLRTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ANTLRTest.java index 925844830..127de51cc 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ANTLRTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ANTLRTest.java @@ -188,7 +188,7 @@ public class ANTLRTest { buildRule.executeTarget("test9"); assertNotContains("Skipped grammar file.", buildRule.getFullLog()); - FileUtilities.rollbackTimetamps(buildRule.getOutputDir(), 5); + FileUtilities.rollbackTimestamps(buildRule.getOutputDir(), 5); buildRule.executeTarget("normalRecompile"); assertNotContains("Skipped grammar file.", buildRule.getFullLog()); @@ -200,7 +200,7 @@ public class ANTLRTest { buildRule.executeTarget("test9"); assertNotContains("Skipped grammar file.", buildRule.getFullLog()); - FileUtilities.rollbackTimetamps(buildRule.getOutputDir(), 5); + FileUtilities.rollbackTimestamps(buildRule.getOutputDir(), 5); buildRule.executeTarget("supergrammarChangeRecompile"); assertNotContains("Skipped grammar file.", buildRule.getFullLog()); diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/AbstractXSLTLiaisonTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/AbstractXSLTLiaisonTest.java index 4e1ee7a9d..d7dedfc6c 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/AbstractXSLTLiaisonTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/AbstractXSLTLiaisonTest.java @@ -34,7 +34,7 @@ import org.junit.Test; import org.w3c.dom.Document; /** - * Abtract testcase for XSLTLiaison. + * Abstract testcase for XSLTLiaison. * Override createLiaison for each XSLTLiaison. * * Stephane Bailliez @@ -51,12 +51,12 @@ public abstract class AbstractXSLTLiaisonTest { } // to override - protected abstract XSLTLiaison createLiaison() throws Exception ; + protected abstract XSLTLiaison createLiaison() throws Exception; /** load the file from the caller classloader that loaded this class */ protected File getFile(String name) throws FileNotFoundException { URL url = getClass().getResource(name); - if (url == null){ + if (url == null) { throw new FileNotFoundException("Unable to load '" + name + "' from classpath"); } return new File(FILE_UTILS.fromURI(url.toExternalForm())); diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java index 0b301f911..cbd66b694 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java @@ -50,7 +50,7 @@ import org.junit.Test; */ public class EchoPropertiesTest { - private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/optional/"; + private static final String TASKDEFS_DIR = "src/etc/testcases/taskdefs/optional/"; private static final String GOOD_OUTFILE = "test.properties"; private static final String GOOD_OUTFILE_XML = "test.xml"; private static final String PREFIX_OUTFILE = "test-prefix.properties"; @@ -59,20 +59,17 @@ public class EchoPropertiesTest { @Rule public BuildFileRule buildRule = new BuildFileRule(); - @Before public void setUp() { buildRule.configureProject(TASKDEFS_DIR + "echoproperties.xml"); buildRule.getProject().setProperty("test.property", TEST_VALUE); } - @After public void tearDown() { buildRule.executeTarget("cleanup"); } - @Test public void testEchoToLog() { buildRule.executeTarget("testEchoToLog"); @@ -82,17 +79,15 @@ public class EchoPropertiesTest { @Test public void testEchoWithEmptyPrefixToLog() { buildRule.executeTarget("testEchoWithEmptyPrefixToLog"); - assertContains("test.property="+TEST_VALUE, buildRule.getLog()); + assertContains("test.property=" + TEST_VALUE, buildRule.getLog()); } - @Test public void testReadBadFile() { try { buildRule.executeTarget("testReadBadFile"); fail("BuildException should have been thrown on bad file"); - } - catch(BuildException ex) { + } catch(BuildException ex) { assertContains("srcfile is a directory","srcfile is a directory!", ex.getMessage()); } } @@ -103,32 +98,28 @@ public class EchoPropertiesTest { assertContains("srcfile is a directory!", buildRule.getLog()); } - @Test public void testEchoToBadFile() { try { buildRule.executeTarget("testEchoToBadFile"); fail("BuildException should have been thrown on destination file being a directory"); - } catch(BuildException ex) { + } catch (BuildException ex) { assertContains("destfile is a directory", "destfile is a directory!", ex.getMessage()); } } - @Test public void testEchoToBadFileNoFail() { buildRule.executeTarget("testEchoToBadFileNoFail"); assertContains("destfile is a directory!", buildRule.getLog()); } - @Test public void testEchoToGoodFile() throws Exception { buildRule.executeTarget("testEchoToGoodFile"); assertGoodFile(); } - @Test public void testEchoToGoodFileXml() throws Exception { buildRule.executeTarget("testEchoToGoodFileXml"); @@ -149,21 +140,21 @@ public class EchoPropertiesTest { } finally { try { fr.close(); - } catch(IOException e) {} + } catch (IOException e) { + } try { br.close(); - } catch(IOException e) {} + } catch (IOException e) { + } } } - @Test public void testEchoToGoodFileFail() throws Exception { buildRule.executeTarget("testEchoToGoodFileFail"); assertGoodFile(); } - @Test public void testEchoToGoodFileNoFail() throws Exception { buildRule.executeTarget("testEchoToGoodFileNoFail"); @@ -194,23 +185,26 @@ public class EchoPropertiesTest { public void testWithPrefixAndRegex() throws Exception { try { buildRule.executeTarget("testWithPrefixAndRegex"); - fail("BuildException should have been thrown on Prefix and RegEx beng set"); + fail("BuildException should have been thrown on Prefix and RegEx being set"); } catch (BuildException ex) { - assertEquals("The target must fail with prefix and regex attributes set", "Please specify either prefix or regex, but not both", ex.getMessage()); + assertEquals("The target must fail with prefix and regex attributes set", + "Please specify either prefix or regex, but not both", ex.getMessage()); } } @Test public void testWithEmptyPrefixAndRegex() throws Exception { buildRule.executeTarget("testEchoWithEmptyPrefixToLog"); - assertContains("test.property="+TEST_VALUE, buildRule.getLog()); + assertContains("test.property=" + TEST_VALUE, buildRule.getLog()); } @Test public void testWithRegex() throws Exception { - assumeTrue("Test skipped because no regexp matcher is present.", RegexpMatcherFactory.regexpMatcherPresent(buildRule.getProject())); + assumeTrue("Test skipped because no regexp matcher is present.", + RegexpMatcherFactory.regexpMatcherPresent(buildRule.getProject())); buildRule.executeTarget("testWithRegex"); - // the following line has been changed from checking ant.home to ant.version so the test will still work when run outside of an ant script + // the following line has been changed from checking ant.home to ant.version + // so the test will still work when run outside of an Ant script assertContains("ant.version=", buildRule.getFullLog()); } @@ -226,14 +220,17 @@ public class EchoPropertiesTest { protected Properties loadPropFile(String relativeFilename) throws IOException { File f = createRelativeFile(relativeFilename); - Properties props=new Properties(); - InputStream in=null; + Properties props = new Properties(); + InputStream in = null; try { - in=new BufferedInputStream(new FileInputStream(f)); + in = new BufferedInputStream(new FileInputStream(f)); props.load(in); } finally { - if(in!=null) { - try { in.close(); } catch(IOException e) {} + if (in != null) { + try { + in.close(); + } catch (IOException e) { + } } } return props; @@ -241,20 +238,18 @@ public class EchoPropertiesTest { protected void assertGoodFile() throws Exception { File f = createRelativeFile(GOOD_OUTFILE); - assertTrue("Did not create "+f.getAbsolutePath(), + assertTrue("Did not create " + f.getAbsolutePath(), f.exists()); - Properties props=loadPropFile(GOOD_OUTFILE); + Properties props = loadPropFile(GOOD_OUTFILE); props.list(System.out); assertEquals("test property not found ", TEST_VALUE, props.getProperty("test.property")); } - protected String toAbsolute(String filename) { return createRelativeFile(filename).getAbsolutePath(); } - protected File createRelativeFile(String filename) { if (filename.equals(".")) { return buildRule.getProject().getBaseDir(); diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/JspcTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/JspcTest.java index cde44d093..d1a0f57f1 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/JspcTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/JspcTest.java @@ -37,15 +37,15 @@ import static org.junit.Assert.fail; /** * Tests the Jspc task. - * + *

* created 07 March 2002 + *

* @since Ant 1.5 */ public class JspcTest { private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/optional/"; - @Rule public BuildFileRule buildRule = new BuildFileRule(); @@ -54,26 +54,21 @@ public class JspcTest { buildRule.configureProject(TASKDEFS_DIR + "jspc.xml"); } - - @Test public void testSimple() { executeJspCompile("testSimple", "simple_jsp.java"); } - @Test public void testUriroot() throws Exception { executeJspCompile("testUriroot", "uriroot_jsp.java"); } - @Test public void testXml() throws Exception { executeJspCompile("testXml", "xml_jsp.java"); } - /** * try a keyword in a file */ @@ -82,7 +77,6 @@ public class JspcTest { executeJspCompile("testKeyword", "default_jsp.java"); } - /** * what happens to 1nvalid-classname */ @@ -92,7 +86,6 @@ public class JspcTest { "_1nvalid_0002dclassname_jsp.java"); } - @Test public void testNoTld() throws Exception { try { @@ -103,7 +96,6 @@ public class JspcTest { } } - @Test public void testNotAJspFile() throws Exception { buildRule.executeTarget("testNotAJspFile"); @@ -130,7 +122,6 @@ public class JspcTest { assertJavaFileCreated(javafile); } - /** * verify that a named file was created * @@ -157,11 +148,11 @@ public class JspcTest { */ @Test public void testJasperNameManglerSelection() { - JspCompilerAdapter adapter= + JspCompilerAdapter adapter = JspCompilerAdapterFactory.getCompiler("jasper", null,null); - JspMangler mangler=adapter.createMangler(); + JspMangler mangler = adapter.createMangler(); assertTrue(mangler instanceof JspNameMangler); - adapter= JspCompilerAdapterFactory.getCompiler("jasper41", null, null); + adapter = JspCompilerAdapterFactory.getCompiler("jasper41", null, null); mangler = adapter.createMangler(); assertTrue(mangler instanceof Jasper41Mangler); } @@ -184,16 +175,15 @@ public class JspcTest { /** * assert our mapping rules - * @param mangler - * @param filename - * @param classname + * @param mangler JspMangler + * @param filename String + * @param classname String */ protected void assertMapped(JspMangler mangler, String filename, String classname) { String mappedname = mangler.mapJspToJavaName(new File(filename)); - assertTrue(filename+" should have mapped to "+classname - +" but instead mapped to "+mappedname, + assertTrue(filename + " should have mapped to " + classname + + " but instead mapped to " + mappedname, classname.equals(mappedname)); } - } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/Native2AsciiTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/Native2AsciiTest.java index 1e8acc98a..748225e65 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/Native2AsciiTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/Native2AsciiTest.java @@ -19,6 +19,7 @@ package org.apache.tools.ant.taskdefs.optional; import java.io.File; +import java.io.IOException; import org.apache.tools.ant.BuildFileRule; import org.apache.tools.ant.util.FileUtils; @@ -48,7 +49,7 @@ public class Native2AsciiTest { } @Test - public void testIso8859_1() throws java.io.IOException { + public void testIso8859_1() throws IOException { buildRule.executeTarget("testIso8859-1"); File in = buildRule.getProject().resolveFile("expected/iso8859-1.test"); File out = new File(buildRule.getProject().getProperty("output"), "iso8859-1.test"); diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PropertyFileTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PropertyFileTest.java index d74c7982a..8b1e08175 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PropertyFileTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PropertyFileTest.java @@ -62,7 +62,7 @@ public class PropertyFileTest { @Test public void testNonExistingFile() { PropertyFile props = new PropertyFile(); - props.setProject( buildRule.getProject() ); + props.setProject(buildRule.getProject()); File file = new File("this-file-does-not-exist.properties"); props.setFile(file); assertFalse("Properties file exists before test.", file.exists()); @@ -199,6 +199,7 @@ public class PropertyFileTest { fos.close(); } + @SuppressWarnings("unused") private static final String projectFilePath = "src/etc/testcases/taskdefs/optional/propertyfile.xml", diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ReplaceRegExpTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ReplaceRegExpTest.java index 2c7111568..be1685bc0 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ReplaceRegExpTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ReplaceRegExpTest.java @@ -24,10 +24,10 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import java.util.Properties; import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.util.Properties; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -126,7 +126,7 @@ public class ReplaceRegExpTest { - (FileUtils.getFileUtils().getFileTimestampGranularity() * 3))); long ts1 = testFile.lastModified(); buildRule.executeTarget("testPreserve"); - assertEquals(ts1 , testFile.lastModified()); + assertEquals(ts1, testFile.lastModified()); } } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java index b383ca9c3..f3f765598 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java @@ -81,8 +81,7 @@ public class RhinoScriptTest { buildRule.executeTarget("useSrcAndEncoding"); fail("should have failed with reader's encoding [" + readerEncoding + "] different from the writer's encoding [" + buildRule.getProject().getProperty("useSrcAndEncoding.encoding") + "]"); - } - catch(BuildException e) { + } catch (BuildException e) { assertTrue(e.getMessage().matches("expected but was ")); } } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java index 648e6440e..d11893ac3 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java @@ -93,7 +93,10 @@ public class TraXLiaisonTest extends AbstractXSLTLiaisonTest } }); // Tickle #52382: - System.setSecurityManager(new SecurityManager() {public void checkPermission(Permission perm) {}}); + System.setSecurityManager(new SecurityManager() { + public void checkPermission(Permission perm) { + } + }); liaison.transform(in, out); } finally { out.delete(); @@ -123,7 +126,10 @@ public class TraXLiaisonTest extends AbstractXSLTLiaisonTest File in = getFile("/taskdefs/optional/xsltliaison-in.xsl"); try { liaison.addParam("xalan-version", "2"); - System.setSecurityManager(new SecurityManager() {public void checkPermission(Permission perm) {}}); + System.setSecurityManager(new SecurityManager() { + public void checkPermission(Permission perm) { + } + }); liaison.transform(in, out); } finally { out.delete(); @@ -138,11 +144,11 @@ public class TraXLiaisonTest extends AbstractXSLTLiaisonTest liaison.addParam("param", "value"); File in = getFile("/taskdefs/optional/xsltliaison-in.xml"); // test for 10 consecutives transform - for (int i = 0; i < 50; i++){ + for (int i = 0; i < 50; i++) { File out = new File("xsltliaison" + i + ".tmp"); try { liaison.transform(in, out); - } catch (Exception e){ + } catch (Exception e) { throw new BuildException("failed in transform " + i, e); } finally { out.delete(); @@ -151,9 +157,9 @@ public class TraXLiaisonTest extends AbstractXSLTLiaisonTest } @Test - public void testSystemId(){ + public void testSystemId() { File file = null; - if ( File.separatorChar == '\\' ){ + if (File.separatorChar == '\\') { file = new File("d:\\jdk"); } else { file = new File("/user/local/bin"); @@ -164,7 +170,7 @@ public class TraXLiaisonTest extends AbstractXSLTLiaisonTest } public void log(String message) { - throw new AssertionFailedError("Liaison sent message: "+message); + throw new AssertionFailedError("Liaison sent message: " + message); } } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/depend/DependTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/depend/DependTest.java index b119f3797..15876b127 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/depend/DependTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/depend/DependTest.java @@ -61,8 +61,8 @@ public class DependTest { buildRule.executeTarget("src1setup"); buildRule.executeTarget("compile"); - FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("tempsrc.dir")), 5); - FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("classes.dir")), 5); + FileUtilities.rollbackTimestamps(new File(buildRule.getProject().getProperty("tempsrc.dir")), 5); + FileUtilities.rollbackTimestamps(new File(buildRule.getProject().getProperty("classes.dir")), 5); buildRule.executeTarget("testdirect"); Hashtable files = getResultFiles(); @@ -82,8 +82,8 @@ public class DependTest { buildRule.executeTarget("src1setup"); buildRule.executeTarget("compile"); - FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("tempsrc.dir")), 5); - FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("classes.dir")), 5); + FileUtilities.rollbackTimestamps(new File(buildRule.getProject().getProperty("tempsrc.dir")), 5); + FileUtilities.rollbackTimestamps(new File(buildRule.getProject().getProperty("classes.dir")), 5); buildRule.executeTarget("testclosure"); Hashtable files = getResultFiles(); @@ -101,8 +101,8 @@ public class DependTest { buildRule.executeTarget("src2setup"); buildRule.executeTarget("compile"); - FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("tempsrc.dir")), 5); - FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("classes.dir")), 5); + FileUtilities.rollbackTimestamps(new File(buildRule.getProject().getProperty("tempsrc.dir")), 5); + FileUtilities.rollbackTimestamps(new File(buildRule.getProject().getProperty("classes.dir")), 5); buildRule.executeTarget("testinner"); @@ -119,8 +119,8 @@ public class DependTest { buildRule.executeTarget("src3setup"); buildRule.executeTarget("compile"); - FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("tempsrc.dir")), 5); - FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("classes.dir")), 5); + FileUtilities.rollbackTimestamps(new File(buildRule.getProject().getProperty("tempsrc.dir")), 5); + FileUtilities.rollbackTimestamps(new File(buildRule.getProject().getProperty("classes.dir")), 5); buildRule.executeTarget("testinnerinner"); assertEquals("Depend did not leave correct number of files", 0, @@ -135,7 +135,7 @@ public class DependTest { try { buildRule.executeTarget("testnosource"); fail("Build exception expected: No source specified"); - } catch(BuildException ex) { + } catch (BuildException ex) { assertContains("srcdir attribute must be set", ex.getMessage()); } } @@ -148,7 +148,7 @@ public class DependTest { try { buildRule.executeTarget("testemptysource"); fail("Build exception expected: No source specified"); - } catch(BuildException ex) { + } catch (BuildException ex) { assertContains("srcdir attribute must be non-empty", ex.getMessage()); } } @@ -198,8 +198,8 @@ public class DependTest { buildRule.executeTarget("src5setup"); buildRule.executeTarget("compile"); - FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("tempsrc.dir")), 5); - FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("classes.dir")), 5); + FileUtilities.rollbackTimestamps(new File(buildRule.getProject().getProperty("tempsrc.dir")), 5); + FileUtilities.rollbackTimestamps(new File(buildRule.getProject().getProperty("classes.dir")), 5); buildRule.executeTarget("testnonpublic"); String log = buildRule.getLog(); diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/i18n/TranslateTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/i18n/TranslateTest.java index 812979c3c..e58e5ce99 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/i18n/TranslateTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/i18n/TranslateTest.java @@ -43,8 +43,6 @@ public class TranslateTest { private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/optional/i18n/translate"; - - @Before public void setUp() { buildRule.configureProject(TASKDEFS_DIR + "/translate.xml"); @@ -53,9 +51,11 @@ public class TranslateTest { @Test public void test1() throws IOException { buildRule.executeTarget("test1"); - assertTrue("translation of "+ TASKDEFS_DIR + "/input/template.txt",compareFiles(new File(buildRule.getProject().getBaseDir(), "expected/de/template.txt"), - new File(buildRule.getOutputDir(), "de/template.txt"))); + assertTrue("translation of " + TASKDEFS_DIR + "/input/template.txt", + compareFiles(new File(buildRule.getProject().getBaseDir(), "expected/de/template.txt"), + new File(buildRule.getOutputDir(), "de/template.txt"))); } + private boolean compareFiles(File file1, File file2) throws IOException { if (!file1.exists() || !file2.exists()) { return false; @@ -69,13 +69,14 @@ public class TranslateTest { byte[] buffer1 = new byte[BUF_SIZE]; byte[] buffer2 = new byte[BUF_SIZE]; + @SuppressWarnings("resource") FileInputStream fis1 = new FileInputStream(file1); + @SuppressWarnings("resource") FileInputStream fis2 = new FileInputStream(file2); - int index = 0; int read = 0; while ((read = fis1.read(buffer1)) != -1) { fis2.read(buffer2); - for (int i = 0; i < read; ++i, ++index) { + for (int i = 0; i < read; ++i) { if (buffer1[i] != buffer2[i]) { return false; } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/image/ImageTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/image/ImageTest.java index eeece1c15..85747ab17 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/image/ImageTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/image/ImageTest.java @@ -66,8 +66,7 @@ public class ImageTest { AntAssert.assertContains("Processing File", buildRule.getLog()); File f = new File(buildRule.getOutputDir(), LARGEIMAGE); - assertTrue( - "Did not create "+f.getAbsolutePath(), + assertTrue("Did not create " + f.getAbsolutePath(), f.exists()); } @@ -107,8 +106,7 @@ public class ImageTest { buildRule.executeTarget("testSimpleScaleWithMapper"); AntAssert.assertContains("Processing File", buildRule.getLog()); File f = new File(buildRule.getOutputDir(), "scaled-" + LARGEIMAGE); - assertTrue( - "Did not create "+f.getAbsolutePath(), + assertTrue("Did not create " + f.getAbsolutePath(), f.exists()); } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTest.java index 545b7cbc0..df4dccdd6 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTest.java @@ -83,7 +83,7 @@ public class JDependTest { @Test public void testTimeout() { buildRule.executeTarget("fork-xml"); - AntAssert.assertContains( "JDepend FAILED - Timed out", buildRule.getLog()); + AntAssert.assertContains("JDepend FAILED - Timed out", buildRule.getLog()); } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/BatchTestTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/BatchTestTest.java index aa483f6dc..a5ad2fef8 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/BatchTestTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/BatchTestTest.java @@ -18,9 +18,8 @@ package org.apache.tools.ant.taskdefs.optional.junit; - -import static org.junit.Assert.fail; import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.fail; import org.junit.Test; diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/DOMUtilTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/DOMUtilTest.java index c32240121..7f996df63 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/DOMUtilTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/DOMUtilTest.java @@ -44,10 +44,7 @@ public class DOMUtilTest { public class FooNodeFilter implements DOMUtil.NodeFilter { public boolean accept(Node node) { - if (node.getNodeName().equals("foo")) { - return true; - } - return false; + return node.getNodeName().equals("foo"); } } } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitClassLoaderTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitClassLoaderTest.java index 4baf74181..175df5f99 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitClassLoaderTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitClassLoaderTest.java @@ -29,7 +29,7 @@ import org.junit.Test; public class JUnitClassLoaderTest { @Test - public void testContextClassLoader(){ + public void testContextClassLoader() { ClassLoader context = Thread.currentThread().getContextClassLoader(); ClassLoader caller = getClass().getClassLoader(); assertSame(context, caller); diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitReportTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitReportTest.java index a7ebbc6a2..e99c4625e 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitReportTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitReportTest.java @@ -26,10 +26,11 @@ import static org.junit.Assert.fail; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileReader; -import java.io.InputStream; import java.io.IOException; +import java.io.InputStream; import java.net.URL; import java.security.Permission; + import javax.xml.transform.TransformerFactory; import javax.xml.transform.TransformerFactoryConfigurationError; @@ -63,8 +64,8 @@ public class JUnitReportTest { @Test public void testNoFileJUnitNoFrames() { buildRule.executeTarget("reports1"); - assertFalse("No file junit-noframes.html expected", (new File(System.getProperty("root"), "src/etc/testcases/taskdefs/optional/junitreport/test/html/junit-noframes.html").exists())); - + assertFalse("No file junit-noframes.html expected", new File(System.getProperty("root"), + "src/etc/testcases/taskdefs/optional/junitreport/test/html/junit-noframes.html").exists()); } public void assertIndexCreated() { @@ -83,11 +84,11 @@ public class JUnitReportTest { private void commonIndexFileAssertions(File reportFile) throws IOException { // tests one the file object - assertTrue("No index.html present. Not generated?", reportFile.exists() ); - assertTrue("Cant read the report file.", reportFile.canRead() ); - assertTrue("File shouldn't be empty.", reportFile.length() > 0 ); + assertTrue("No index.html present. Not generated?", reportFile.exists()); + assertTrue("Can't read the report file.", reportFile.canRead()); + assertTrue("File shouldn't be empty.", reportFile.length() > 0); // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report - URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) ); + URL reportUrl = new URL(FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath())); InputStream reportStream = reportUrl.openStream(); try { assertTrue("This shouldn't be an empty stream.", reportStream.available() > 0); @@ -194,7 +195,10 @@ public class JUnitReportTest { throw new RuntimeException(exc); } try { - System.setSecurityManager(new SecurityManager() {public void checkPermission(Permission perm) {}}); + System.setSecurityManager(new SecurityManager() { + public void checkPermission(Permission perm) { + } + }); buildRule.executeTarget("testWithStyleFromClasspath"); commonIndexFileAssertions(); } finally { @@ -215,7 +219,10 @@ public class JUnitReportTest { return super.getResourceAsStream(name); } }); - System.setSecurityManager(new SecurityManager() {public void checkPermission(Permission perm) {}}); + System.setSecurityManager(new SecurityManager() { + public void checkPermission(Permission perm) { + } + }); buildRule.executeTarget("testWithStyleFromClasspath"); commonIndexFileAssertions(); } finally { diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskTest.java index c3930057b..07baeee1c 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskTest.java @@ -35,7 +35,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.Arrays; -import java.util.Collections; import java.util.Set; import java.util.TreeSet; @@ -44,13 +43,12 @@ import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathFactory; -import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildFileRule; import org.apache.tools.ant.MagicNames; import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.launcher.CommandLauncher; -import org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.ForkMode; import org.apache.tools.ant.types.Path; import org.apache.tools.ant.util.JavaEnvUtils; import org.apache.tools.ant.util.LoaderUtils; @@ -141,7 +139,7 @@ public class JUnitTaskTest { public void testFailureRecorder() { if (JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_1_5)) { try { - Class clazz =Class.forName("junit.framework.JUnit4TestAdapter"); + Class clazz = Class.forName("junit.framework.JUnit4TestAdapter"); Assume.assumeFalse("Skipping test since it fails with JUnit 4", clazz != null); } catch (ClassNotFoundException e) { // OK, this is JUnit3, can run test @@ -364,16 +362,25 @@ public class JUnitTaskTest { XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); - assertEquals("Incorrect number of skipped tests in header", 4, Integer.parseInt(xpath.compile("//testsuite/@skipped").evaluate(doc))); - assertEquals("Incorrect number of error tests in header", 1, Integer.parseInt(xpath.compile("//testsuite/@errors").evaluate(doc))); - assertEquals("Incorrect number of failure tests in header", 2, Integer.parseInt(xpath.compile("//testsuite/@failures").evaluate(doc))); - assertEquals("Incorrect number of tests in header", 8, Integer.parseInt(xpath.compile("//testsuite/@tests").evaluate(doc))); - - - assertEquals("Incorrect ignore message on explicit ignored test", "Please don't ignore me!", xpath.compile("//testsuite/testcase[@name='explicitIgnoreTest']/skipped/@message").evaluate(doc)); - assertEquals("No message should be set on Ignored tests with no Ignore annotation text", 0, ((Node)xpath.compile("//testsuite/testcase[@name='explicitlyIgnoreTestNoMessage']/skipped").evaluate(doc, XPathConstants.NODE)).getAttributes().getLength()); - assertEquals("Incorrect ignore message on implicit ignored test", "This test will be ignored", xpath.compile("//testsuite/testcase[@name='implicitlyIgnoreTest']/skipped/@message").evaluate(doc)); - assertNotNull("Implicit ignore test should have an ignore element", xpath.compile("//testsuite/testcase[@name='implicitlyIgnoreTestNoMessage']/skipped").evaluate(doc, XPathConstants.NODE)); + assertEquals("Incorrect number of skipped tests in header", 4, + Integer.parseInt(xpath.compile("//testsuite/@skipped").evaluate(doc))); + assertEquals("Incorrect number of error tests in header", 1, + Integer.parseInt(xpath.compile("//testsuite/@errors").evaluate(doc))); + assertEquals("Incorrect number of failure tests in header", 2, + Integer.parseInt(xpath.compile("//testsuite/@failures").evaluate(doc))); + assertEquals("Incorrect number of tests in header", 8, + Integer.parseInt(xpath.compile("//testsuite/@tests").evaluate(doc))); + + + assertEquals("Incorrect ignore message on explicit ignored test", "Please don't ignore me!", + xpath.compile("//testsuite/testcase[@name='explicitIgnoreTest']/skipped/@message").evaluate(doc)); + assertEquals("No message should be set on Ignored tests with no Ignore annotation text", 0, + ((Node)xpath.compile("//testsuite/testcase[@name='explicitlyIgnoreTestNoMessage']/skipped") + .evaluate(doc, XPathConstants.NODE)).getAttributes().getLength()); + assertEquals("Incorrect ignore message on implicit ignored test", "This test will be ignored", + xpath.compile("//testsuite/testcase[@name='implicitlyIgnoreTest']/skipped/@message").evaluate(doc)); + assertNotNull("Implicit ignore test should have an ignore element", + xpath.compile("//testsuite/testcase[@name='implicitlyIgnoreTestNoMessage']/skipped").evaluate(doc, XPathConstants.NODE)); } @@ -386,26 +393,44 @@ public class JUnitTaskTest { public void testNonTestsSkipped() throws Exception { buildRule.executeTarget("testNonTests"); - assertFalse("Test result should not exist as test was skipped - TEST-org.example.junit.NonTestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.NonTestMissed.xml").exists()); - assertFalse("Test result should not exist as test was skipped - TEST-org.example.junit.JUnit3NonTestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.JUnit3TestMissed.xml").exists()); - assertFalse("Test result should not exist as test was skipped - TEST-org.example.junit.AbstractTestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractTestMissed.xml").exists()); - assertFalse("Test result should not exist as test was skipped - TEST-org.example.junit.AbstractJUnit3TestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractJUnit3TestMissed.xml").exists()); - assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.AbstractTestNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractTestNotMissed.xml").exists()); - assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.AbstractJUnit3TestNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractJUnit3TestNotMissed.xml").exists()); - assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.TestNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.TestNotMissed.xml").exists()); - assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.JUnit3TestNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.JUnit3TestNotMissed.xml").exists()); - assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.TestWithSuiteNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.TestWithSuiteNotMissed.xml").exists()); + assertFalse("Test result should not exist as test was skipped - TEST-org.example.junit.NonTestMissed.xml", + new File(buildRule.getOutputDir(), "TEST-org.example.junit.NonTestMissed.xml").exists()); + assertFalse("Test result should not exist as test was skipped - TEST-org.example.junit.JUnit3NonTestMissed.xml", + new File(buildRule.getOutputDir(), "TEST-org.example.junit.JUnit3TestMissed.xml").exists()); + assertFalse("Test result should not exist as test was skipped - TEST-org.example.junit.AbstractTestMissed.xml", + new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractTestMissed.xml").exists()); + assertFalse("Test result should not exist as test was skipped - TEST-org.example.junit.AbstractJUnit3TestMissed.xml", + new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractJUnit3TestMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.AbstractTestNotMissed.xml", + new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractTestNotMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.AbstractJUnit3TestNotMissed.xml", + new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractJUnit3TestNotMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.TestNotMissed.xml", + new File(buildRule.getOutputDir(), "TEST-org.example.junit.TestNotMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.JUnit3TestNotMissed.xml", + new File(buildRule.getOutputDir(), "TEST-org.example.junit.JUnit3TestNotMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.TestWithSuiteNotMissed.xml", + new File(buildRule.getOutputDir(), "TEST-org.example.junit.TestWithSuiteNotMissed.xml").exists()); buildRule.executeTarget("testNonTestsRun"); - assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.NonTestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.NonTestMissed.xml").exists()); - assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.JUnit3NonTestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.JUnit3NonTestMissed.xml").exists()); - assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.TestNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.TestNotMissed.xml").exists()); - assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.JUnit3TestNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.JUnit3TestNotMissed.xml").exists()); - assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.AbstractTestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractTestMissed.xml").exists()); - assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.AbstractTestNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractTestNotMissed.xml").exists()); - assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.AbstractJUnit3TestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractJUnit3TestMissed.xml").exists()); - assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.JUnit3NonTestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.JUnit3NonTestMissed.xml").exists()); - assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.TestWithSuiteNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.TestWithSuiteNotMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.NonTestMissed.xml", + new File(buildRule.getOutputDir(), "TEST-org.example.junit.NonTestMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.JUnit3NonTestMissed.xml", + new File(buildRule.getOutputDir(), "TEST-org.example.junit.JUnit3NonTestMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.TestNotMissed.xml", + new File(buildRule.getOutputDir(), "TEST-org.example.junit.TestNotMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.JUnit3TestNotMissed.xml", + new File(buildRule.getOutputDir(), "TEST-org.example.junit.JUnit3TestNotMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.AbstractTestMissed.xml", + new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractTestMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.AbstractTestNotMissed.xml", + new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractTestNotMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.AbstractJUnit3TestMissed.xml", + new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractJUnit3TestMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.JUnit3NonTestMissed.xml", + new File(buildRule.getOutputDir(), "TEST-org.example.junit.JUnit3NonTestMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.TestWithSuiteNotMissed.xml", + new File(buildRule.getOutputDir(), "TEST-org.example.junit.TestWithSuiteNotMissed.xml").exists()); } @@ -441,7 +466,7 @@ public class JUnitTaskTest { final File tmp = new File(System.getProperty("java.io.tmpdir")); //NOI18N final File workDir = new File(tmp, String.format("%s_testJCP%d", //NOI18N getClass().getName(), - System.currentTimeMillis()/1000)); + System.currentTimeMillis() / 1000)); workDir.mkdirs(); try { final File modulesDir = new File(workDir,"modules"); //NOI18N @@ -473,7 +498,7 @@ public class JUnitTaskTest { String resCp = null; String resMp = null; Set resExports = new TreeSet<>(); - for (int i = 1; i< mockProcLauncher.cmd.length; i++) { + for (int i = 1; i < mockProcLauncher.cmd.length; i++) { if ("-classpath".equals(mockProcLauncher.cmd[i])) { //NOI18N resCp = mockProcLauncher.cmd[++i]; } else if ("--module-path".equals(mockProcLauncher.cmd[i])) { //NOI18N @@ -500,10 +525,10 @@ public class JUnitTaskTest { final File tmp = new File(System.getProperty("java.io.tmpdir")); //NOI18N final File workDir = new File(tmp, String.format("%s_testJMP%d", //NOI18N getClass().getName(), - System.currentTimeMillis()/1000)); + System.currentTimeMillis() / 1000)); workDir.mkdirs(); try { - final File modulesDir = new File(workDir,"modules"); //NOI18N + final File modulesDir = new File(workDir, "modules"); //NOI18N modulesDir.mkdirs(); final Project project = new Project(); @@ -530,7 +555,7 @@ public class JUnitTaskTest { String resCp = null; String resMp = null; Set resExports = new TreeSet<>(); - for (int i = 1; i< mockProcLauncher.cmd.length; i++) { + for (int i = 1; i < mockProcLauncher.cmd.length; i++) { if ("-classpath".equals(mockProcLauncher.cmd[i])) { //NOI18N resCp = mockProcLauncher.cmd[++i]; } else if ("--module-path".equals(mockProcLauncher.cmd[i])) { //NOI18N diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestListenerTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestListenerTest.java index 49c1fb4ed..0067203d9 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestListenerTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestListenerTest.java @@ -26,7 +26,7 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; -public class JUnitTestListenerTest{ +public class JUnitTestListenerTest { @Rule public BuildFileRule buildRule = new BuildFileRule(); diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunnerTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunnerTest.java index 7c0fa16bb..2579c8247 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunnerTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunnerTest.java @@ -17,10 +17,11 @@ */ package org.apache.tools.ant.taskdefs.optional.junit; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.io.OutputStream; import java.io.PrintWriter; import java.io.StringWriter; @@ -36,13 +37,11 @@ import org.junit.Test; * They must be enhanced with time. * */ -public class JUnitTestRunnerTest{ - - +public class JUnitTestRunnerTest { // check that a valid method name generates no errors @Test - public void testValidMethod(){ + public void testValidMethod() { TestRunner runner = createRunnerForTestMethod(ValidMethodTestCase.class,"testA"); runner.run(); assertEquals(runner.getFormatter().getError(), JUnitTestRunner.SUCCESS, runner.getRetCode()); @@ -50,7 +49,7 @@ public class JUnitTestRunnerTest{ // check that having an invalid method name generates an error @Test - public void testInvalidMethod(){ + public void testInvalidMethod() { TestRunner runner = createRunnerForTestMethod(InvalidMethodTestCase.class,"testInvalid"); runner.run(); String error = runner.getFormatter().getError(); @@ -60,7 +59,7 @@ public class JUnitTestRunnerTest{ // check that having no suite generates no errors @Test - public void testNoSuite(){ + public void testNoSuite() { TestRunner runner = createRunner(NoSuiteTestCase.class); runner.run(); assertEquals(runner.getFormatter().getError(), JUnitTestRunner.SUCCESS, runner.getRetCode()); @@ -68,7 +67,7 @@ public class JUnitTestRunnerTest{ // check that a suite generates no errors @Test - public void testSuite(){ + public void testSuite() { TestRunner runner = createRunner(SuiteTestCase.class); runner.run(); assertEquals(runner.getFormatter().getError(), JUnitTestRunner.SUCCESS, runner.getRetCode()); @@ -76,7 +75,7 @@ public class JUnitTestRunnerTest{ // check that an invalid suite generates an error. @Test - public void testInvalidSuite(){ + public void testInvalidSuite() { TestRunner runner = createRunner(InvalidSuiteTestCase.class); runner.run(); String error = runner.getFormatter().getError(); @@ -87,7 +86,7 @@ public class JUnitTestRunnerTest{ // check that something which is not a testcase generates no errors // at first even though this is incorrect. @Test - public void testNoTestCase(){ + public void testNoTestCase() { TestRunner runner = createRunner(NoTestCase.class); runner.run(); // On junit3 this is a FAILURE, on junit4 this is an ERROR @@ -102,7 +101,7 @@ public class JUnitTestRunnerTest{ // check that an exception in the constructor is noticed @Test - public void testInvalidTestCase(){ + public void testInvalidTestCase() { TestRunner runner = createRunner(InvalidTestCase.class); runner.run(); // On junit3 this is a FAILURE, on junit4 this is an ERROR @@ -118,7 +117,7 @@ public class JUnitTestRunnerTest{ // check that JUnit 4 synthetic AssertionFailedError gets message and cause from AssertionError @Test - public void testJUnit4AssertionError(){ + public void testJUnit4AssertionError() { TestRunner runner = createRunnerForTestMethod(AssertionErrorTest.class,"throwsAssertionError"); runner.run(); @@ -130,12 +129,12 @@ public class JUnitTestRunnerTest{ assertEquals("cause message", cause.getMessage()); } - protected TestRunner createRunner(Class clazz){ + protected TestRunner createRunner(Class clazz) { return new TestRunner(new JUnitTest(clazz.getName()), null, true, true, true); } - protected TestRunner createRunnerForTestMethod(Class clazz, String method){ + protected TestRunner createRunnerForTestMethod(Class clazz, String method) { return new TestRunner(new JUnitTest(clazz.getName()), new String[] {method}, true, true, true); } @@ -144,7 +143,7 @@ public class JUnitTestRunnerTest{ private final static class TestRunner extends JUnitTestRunner { private ResultFormatter formatter = new ResultFormatter(); TestRunner(JUnitTest test, String[] methods, boolean haltonerror, - boolean filtertrace, boolean haltonfailure){ + boolean filtertrace, boolean haltonfailure) { super(test, methods, haltonerror, filtertrace, haltonfailure, false, false, TestRunner.class.getClassLoader()); // use the classloader that loaded this class otherwise @@ -152,7 +151,7 @@ public class JUnitTestRunnerTest{ // is ran in non-forked mode. addFormatter(formatter); } - ResultFormatter getFormatter(){ + ResultFormatter getFormatter() { return formatter; } } @@ -161,13 +160,20 @@ public class JUnitTestRunnerTest{ private final static class ResultFormatter implements JUnitResultFormatter { private AssertionFailedError failure; private Throwable error; - public void setSystemOutput(String output){} - public void setSystemError(String output){} - public void startTestSuite(JUnitTest suite) throws BuildException{} - public void endTestSuite(JUnitTest suite) throws BuildException{} - public void setOutput(java.io.OutputStream out){} - public void startTest(junit.framework.Test t) {} - public void endTest(junit.framework.Test test) {} + public void setSystemOutput(String output) { + } + public void setSystemError(String output) { + } + public void startTestSuite(JUnitTest suite) throws BuildException{ + } + public void endTestSuite(JUnitTest suite) throws BuildException{ + } + public void setOutput(OutputStream out) { + } + public void startTest(junit.framework.Test t) { + } + public void endTest(junit.framework.Test test) { + } public void addFailure(junit.framework.Test test, AssertionFailedError t) { failure = t; } @@ -177,8 +183,8 @@ public class JUnitTestRunnerTest{ public void addError(junit.framework.Test test, Throwable t) { error = t; } - String getError(){ - if (error == null){ + String getError() { + if (error == null) { return ""; } StringWriter sw = new StringWriter(); @@ -191,54 +197,64 @@ public class JUnitTestRunnerTest{ } public static class InvalidMethodTestCase extends TestCase { - public InvalidMethodTestCase(String name){ super(name); } - public void testA(){ + public InvalidMethodTestCase(String name) { + super(name); + } + public void testA() { throw new NullPointerException("thrown on purpose"); } } public static class ValidMethodTestCase extends TestCase { - public ValidMethodTestCase(String name){ super(name); } - public void testA(){ + public ValidMethodTestCase(String name) { + super(name); + } + public void testA() { // expected to be executed } - public void testB(){ + public void testB() { // should not be executed throw new NullPointerException("thrown on purpose"); } } public static class InvalidTestCase extends TestCase { - public InvalidTestCase(String name){ + public InvalidTestCase(String name) { super(name); throw new NullPointerException("thrown on purpose"); } } public static class NoSuiteTestCase extends TestCase { - public NoSuiteTestCase(String name){ super(name); } - public void testA(){} + public NoSuiteTestCase(String name) { + super(name); + } + public void testA() { + } } public static class SuiteTestCase extends NoSuiteTestCase { - public SuiteTestCase(String name){ super(name); } - public static junit.framework.Test suite(){ + public SuiteTestCase(String name) { + super(name); + } + public static junit.framework.Test suite() { return new TestSuite(SuiteTestCase.class); } } public static class InvalidSuiteTestCase extends NoSuiteTestCase { - public InvalidSuiteTestCase(String name){ super(name); } - public static junit.framework.Test suite(){ + public InvalidSuiteTestCase(String name) { + super(name); + } + public static junit.framework.Test suite() { throw new NullPointerException("thrown on purpose"); } } public static class AssertionErrorTest { - @Test public void throwsAssertionError() { - AssertionError assertionError = new AssertionError("failure message"); - assertionError.initCause(new RuntimeException("cause message")); - throw assertionError; + @Test + public void throwsAssertionError() { + throw new AssertionError("failure message", new RuntimeException("cause message")); } } } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitVersionHelperTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitVersionHelperTest.java index 2f3fdb7fc..a4b8ce932 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitVersionHelperTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitVersionHelperTest.java @@ -32,12 +32,9 @@ public class JUnitVersionHelperTest { @Test public void testMyOwnName() { assertEquals("testMyOwnName", - JUnitVersionHelper.getTestCaseName( - JUnit4TestAdapterCache.getDefault().asTest( - Description.createTestDescription(JUnitVersionHelperTest.class, "testMyOwnName") - ) - ) - ); + JUnitVersionHelper.getTestCaseName(JUnit4TestAdapterCache.getDefault() + .asTest(Description.createTestDescription(JUnitVersionHelperTest.class, + "testMyOwnName")))); } @Test @@ -76,27 +73,38 @@ public class JUnitVersionHelperTest { } public static class Foo implements junit.framework.Test { - public int countTestCases() {return 0;} - public void run(TestResult result) {} + public int countTestCases() { + return 0; + } + public void run(TestResult result) { + } } public static class Foo1 extends Foo { - public String getName() {return "I'm a foo";} + public String getName() { + return "I'm a foo"; + } } public static class Foo2 extends Foo { - public int getName() {return 1;} + public int getName() { + return 1; + } } public static class Foo3 extends Foo { } public static class Foo4 extends Foo { - public String name() {return "I'm a foo, too";} + public String name() { + return "I'm a foo, too"; + } } public static class Foo5 extends TestCase { - public String getName() {return "overridden getName";} + public String getName() { + return "overridden getName"; + } } } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/Sleeper.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/Sleeper.java index 150989483..ab8ccda2d 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/Sleeper.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/Sleeper.java @@ -17,7 +17,6 @@ */ package org.apache.tools.ant.taskdefs.optional.junit; - import org.junit.Test; public class Sleeper { diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregatorTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregatorTest.java index c8636b003..c3530ae61 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregatorTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregatorTest.java @@ -44,7 +44,9 @@ public class XMLResultAggregatorTest { } final File d = new File(System.getProperty("java.io.tmpdir"), "XMLResultAggregatorTest"); if (d.exists()) { - new Delete() {{removeDir(d);}}; // is there no utility method for this? + new Delete() { + { removeDir(d); } + }; // is there no utility method for this? } assertTrue(d.getAbsolutePath(), d.mkdir()); File xml = new File(d, "x.xml"); @@ -72,7 +74,8 @@ public class XMLResultAggregatorTest { FileSet fs = new FileSet(); fs.setFile(xml); task.addFileSet(fs); - /* getResourceAsStream override unnecessary on JDK 7. Ought to work around JAXP #6723276 in JDK 6, but causes a TypeCheckError in FunctionCall for reasons TBD: + /* getResourceAsStream override unnecessary on JDK 7. + * Ought to work around JAXP #6723276 in JDK 6, but causes a TypeCheckError in FunctionCall for reasons TBD: Thread.currentThread().setContextClassLoader(new ClassLoader(ClassLoader.getSystemClassLoader().getParent()) { public InputStream getResourceAsStream(String name) { if (name.startsWith("META-INF/services/")) { @@ -85,7 +88,10 @@ public class XMLResultAggregatorTest { // Use the JRE's Xerces, not lib/optional/xerces.jar: Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader().getParent()); // Tickle #51668: - System.setSecurityManager(new SecurityManager() {public void checkPermission(Permission perm) {}}); + System.setSecurityManager(new SecurityManager() { + public void checkPermission(Permission perm) { + } + }); task.execute(); assertTrue(new File(d, "index.html").isFile()); } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/net/FTPTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/net/FTPTest.java index c7fab261f..f8c89f267 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/net/FTPTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/net/FTPTest.java @@ -60,7 +60,7 @@ public class FTPTest { private FTPClient ftp; - private boolean loginSuceeded = false; + private boolean loginSucceeded = false; private String loginFailureMessage; @@ -95,7 +95,7 @@ public class FTPTest { if (connectionSucceeded) { try { ftp.login(remoteUser, password); - loginSuceeded = true; + loginSucceeded = true; } catch (IOException ioe) { loginFailureMessage = "could not log on to " + remoteHost + " as user " + remoteUser; } @@ -105,7 +105,7 @@ public class FTPTest { @After public void tearDown() { try { - if (ftp!= null) { + if (ftp != null) { ftp.disconnect(); } } catch (IOException ioe) { @@ -118,8 +118,7 @@ public class FTPTest { boolean result = true; try { ftp.cwd(remoteDir); - } - catch (Exception ex) { + } catch (Exception ex) { System.out.println("could not change directory to " + remoteTmpDir); result = false; } @@ -128,45 +127,42 @@ public class FTPTest { @Test public void test1() { - Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue(loginFailureMessage, loginSucceeded); Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); ds.setIncludes(new String[] {"alpha"}); ds.scan(); - compareFiles(ds, new String[] {} ,new String[] {"alpha"}); + compareFiles(ds, new String[] {}, new String[] {"alpha"}); } @Test public void test2() { - Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue(loginFailureMessage, loginSucceeded); Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); ds.setIncludes(new String[] {"alpha/"}); ds.scan(); - compareFiles(ds, new String[] {"alpha/beta/beta.xml", - "alpha/beta/gamma/gamma.xml"}, + compareFiles(ds, new String[] {"alpha/beta/beta.xml", "alpha/beta/gamma/gamma.xml"}, new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"}); } @Test public void test3() { - Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue(loginFailureMessage, loginSucceeded); Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); ds.scan(); - compareFiles(ds, new String[] {"alpha/beta/beta.xml", - "alpha/beta/gamma/gamma.xml"}, - new String[] {"alpha", "alpha/beta", - "alpha/beta/gamma"}); + compareFiles(ds, new String[] {"alpha/beta/beta.xml", "alpha/beta/gamma/gamma.xml"}, + new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"}); } @Test public void testFullPathMatchesCaseSensitive() { - Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue(loginFailureMessage, loginSucceeded); Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); @@ -177,34 +173,32 @@ public class FTPTest { @Test public void testFullPathMatchesCaseInsensitive() { - Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue(loginFailureMessage, loginSucceeded); Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); ds.setCaseSensitive(false); ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); ds.setIncludes(new String[] {"alpha/beta/gamma/GAMMA.XML"}); ds.scan(); - compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"}, - new String[] {}); + compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"}, new String[] {}); } @Test public void test2ButCaseInsensitive() { - Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue(loginFailureMessage, loginSucceeded); Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); ds.setIncludes(new String[] {"ALPHA/"}); ds.setCaseSensitive(false); ds.scan(); - compareFiles(ds, new String[] {"alpha/beta/beta.xml", - "alpha/beta/gamma/gamma.xml"}, + compareFiles(ds, new String[] {"alpha/beta/beta.xml", "alpha/beta/gamma/gamma.xml"}, new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"}); } @Test public void test2bisButCaseInsensitive() { - Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue(loginFailureMessage, loginSucceeded); Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); @@ -241,10 +235,10 @@ public class FTPTest { @Test public void testGetFollowSymlinksTrue() { Assume.assumeTrue("System does not support Symlinks", supportsSymlinks); - Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue(loginFailureMessage, loginSucceeded); Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); buildRule.getProject().executeTarget("ftp-get-directory-symbolic-link"); - FileSet fsDestination = (FileSet) buildRule.getProject().getReference("fileset-destination-without-selector"); + FileSet fsDestination = buildRule.getProject().getReference("fileset-destination-without-selector"); DirectoryScanner dsDestination = fsDestination.getDirectoryScanner(buildRule.getProject()); dsDestination.scan(); compareFiles(dsDestination, new String[] {"alpha/beta/gamma/gamma.xml"}, @@ -254,20 +248,19 @@ public class FTPTest { @Test public void testGetFollowSymlinksFalse() { Assume.assumeTrue("System does not support Symlinks", supportsSymlinks); - Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue(loginFailureMessage, loginSucceeded); Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); buildRule.getProject().executeTarget("ftp-get-directory-no-symbolic-link"); FileSet fsDestination = (FileSet) buildRule.getProject().getReference("fileset-destination-without-selector"); DirectoryScanner dsDestination = fsDestination.getDirectoryScanner(buildRule.getProject()); dsDestination.scan(); - compareFiles(dsDestination, new String[] {}, - new String[] {}); + compareFiles(dsDestination, new String[] {}, new String[] {}); } @Test public void testAllowSymlinks() { Assume.assumeTrue("System does not support Symlinks", supportsSymlinks); - Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue(loginFailureMessage, loginSucceeded); Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); buildRule.getProject().executeTarget("symlink-setup"); FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); @@ -282,7 +275,7 @@ public class FTPTest { @Test public void testProhibitSymlinks() { Assume.assumeTrue("System does not support Symlinks", supportsSymlinks); - Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue(loginFailureMessage, loginSucceeded); Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); buildRule.getProject().executeTarget("symlink-setup"); FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); @@ -296,7 +289,7 @@ public class FTPTest { @Test public void testFileSymlink() { Assume.assumeTrue("System does not support Symlinks", supportsSymlinks); - Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue(loginFailureMessage, loginSucceeded); Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); buildRule.getProject().executeTarget("symlink-file-setup"); FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); @@ -311,10 +304,9 @@ public class FTPTest { // father and child pattern test @Test public void testOrderOfIncludePatternsIrrelevant() { - Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue(loginFailureMessage, loginSucceeded); Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); - String [] expectedFiles = {"alpha/beta/beta.xml", - "alpha/beta/gamma/gamma.xml"}; + String [] expectedFiles = {"alpha/beta/beta.xml", "alpha/beta/gamma/gamma.xml"}; String [] expectedDirectories = {"alpha/beta", "alpha/beta/gamma" }; FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); @@ -331,49 +323,43 @@ public class FTPTest { @Test public void testPatternsDifferInCaseScanningSensitive() { - Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue(loginFailureMessage, loginSucceeded); Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); ds.setIncludes(new String[] {"alpha/", "ALPHA/"}); ds.scan(); - compareFiles(ds, new String[] {"alpha/beta/beta.xml", - "alpha/beta/gamma/gamma.xml"}, + compareFiles(ds, new String[] {"alpha/beta/beta.xml", "alpha/beta/gamma/gamma.xml"}, new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"}); } @Test public void testPatternsDifferInCaseScanningInsensitive() { - Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue(loginFailureMessage, loginSucceeded); Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); ds.setIncludes(new String[] {"alpha/", "ALPHA/"}); ds.setCaseSensitive(false); ds.scan(); - compareFiles(ds, new String[] {"alpha/beta/beta.xml", - "alpha/beta/gamma/gamma.xml"}, + compareFiles(ds, new String[] {"alpha/beta/beta.xml", "alpha/beta/gamma/gamma.xml"}, new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"}); } @Test public void testFullpathDiffersInCaseScanningSensitive() { - Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue(loginFailureMessage, loginSucceeded); Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); - ds.setIncludes(new String[] { - "alpha/beta/gamma/gamma.xml", - "alpha/beta/gamma/GAMMA.XML" - }); + ds.setIncludes(new String[] {"alpha/beta/gamma/gamma.xml", "alpha/beta/gamma/GAMMA.XML"}); ds.scan(); - compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"}, - new String[] {}); + compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"}, new String[] {}); } @Test public void testFullpathDiffersInCaseScanningInsensitive() { - Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue(loginFailureMessage, loginSucceeded); Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); @@ -389,7 +375,7 @@ public class FTPTest { @Test public void testParentDiffersInCaseScanningSensitive() { - Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue(loginFailureMessage, loginSucceeded); Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); @@ -402,89 +388,63 @@ public class FTPTest { @Test public void testParentDiffersInCaseScanningInsensitive() { - Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue(loginFailureMessage, loginSucceeded); Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); ds.setIncludes(new String[] {"alpha/", "ALPHA/beta/"}); ds.setCaseSensitive(false); ds.scan(); - compareFiles(ds, new String[] {"alpha/beta/beta.xml", - "alpha/beta/gamma/gamma.xml"}, - new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"}); + compareFiles(ds, new String[] {"alpha/beta/beta.xml", "alpha/beta/gamma/gamma.xml"}, + new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"}); } @Test public void testExcludeOneFile() { - Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue(loginFailureMessage, loginSucceeded); Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); - ds.setIncludes(new String[] { - "**/*.xml" - }); - ds.setExcludes(new String[] { - "alpha/beta/b*xml" - }); + ds.setIncludes(new String[] {"**/*.xml"}); + ds.setExcludes(new String[] {"alpha/beta/b*xml"}); ds.scan(); - compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"}, - new String[] {}); + compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"}, new String[] {}); } @Test public void testExcludeHasPrecedence() { - Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue(loginFailureMessage, loginSucceeded); Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); - ds.setIncludes(new String[] { - "alpha/**" - }); - ds.setExcludes(new String[] { - "alpha/**" - }); + ds.setIncludes(new String[] {"alpha/**"}); + ds.setExcludes(new String[] {"alpha/**"}); ds.scan(); - compareFiles(ds, new String[] {}, - new String[] {}); - + compareFiles(ds, new String[] {}, new String[] {}); } @Test public void testAlternateIncludeExclude() { - Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue(loginFailureMessage, loginSucceeded); Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); - ds.setIncludes(new String[] { - "alpha/**", - "alpha/beta/gamma/**" - }); - ds.setExcludes(new String[] { - "alpha/beta/**" - }); + ds.setIncludes(new String[] {"alpha/**", "alpha/beta/gamma/**"}); + ds.setExcludes(new String[] {"alpha/beta/**"}); ds.scan(); - compareFiles(ds, new String[] {}, - new String[] {"alpha"}); - + compareFiles(ds, new String[] {}, new String[] {"alpha"}); } @Test public void testAlternateExcludeInclude() { - Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue(loginFailureMessage, loginSucceeded); Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); - ds.setExcludes(new String[] { - "alpha/**", - "alpha/beta/gamma/**" - }); - ds.setIncludes(new String[] { - "alpha/beta/**" - }); + ds.setExcludes(new String[] {"alpha/**", "alpha/beta/gamma/**"}); + ds.setIncludes(new String[] {"alpha/beta/**"}); ds.scan(); - compareFiles(ds, new String[] {}, - new String[] {}); - + compareFiles(ds, new String[] {}, new String[] {}); } /** @@ -492,26 +452,23 @@ public class FTPTest { */ @Test public void testChildrenOfExcludedDirectory() { - Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue(loginFailureMessage, loginSucceeded); Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); buildRule.getProject().executeTarget("children-of-excluded-dir-setup"); FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); ds.setExcludes(new String[] {"alpha/**"}); ds.scan(); - compareFiles(ds, new String[] {"delta/delta.xml"}, - new String[] {"delta"}); + compareFiles(ds, new String[] {"delta/delta.xml"}, new String[] {"delta"}); ds = myFTPTask.newScanner(ftp); Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); ds.setExcludes(new String[] {"alpha"}); ds.scan(); - compareFiles(ds, new String[] {"alpha/beta/beta.xml", - "alpha/beta/gamma/gamma.xml", - "delta/delta.xml"}, + compareFiles(ds, new String[] {"alpha/beta/beta.xml", "alpha/beta/gamma/gamma.xml", + "delta/delta.xml"}, new String[] {"alpha/beta", "alpha/beta/gamma", "delta"}); - } /** @@ -634,11 +591,8 @@ public class FTPTest { */ @Test public void testConfiguration1() { - int[] expectedCounts = { - 1,1,0,1,0,0,0 - }; + int[] expectedCounts = {1, 1, 0, 1, 0, 0, 0}; performConfigTest("configuration.1", expectedCounts); - } /** @@ -646,11 +600,8 @@ public class FTPTest { */ @Test public void testConfiguration2() { - int[] expectedCounts = { - 1,0,0,1,1,0,0 - }; + int[] expectedCounts = {1, 0, 0, 1, 1, 0, 0}; performConfigTest("configuration.2", expectedCounts); - } /** @@ -658,18 +609,13 @@ public class FTPTest { */ @Test public void testConfiguration3() { - int[] expectedCounts = { - 1,0,1,0,0,1,0 - }; + int[] expectedCounts = {1, 0, 1, 0, 0, 1, 0}; performConfigTest("configuration.3", expectedCounts); - } @Test public void testConfigurationLang() { - int[] expectedCounts = { - 1,1,0,0,0,0,1 - }; + int[] expectedCounts = {1, 1, 0, 0, 0, 0, 1}; performConfigTest("configuration.lang.good", expectedCounts); try { @@ -684,9 +630,7 @@ public class FTPTest { */ @Test public void testConfigurationNone() { - int[] expectedCounts = { - 0,0,0,0,0,0,0 - }; + int[] expectedCounts = {0, 0, 0, 0, 0, 0, 0}; performConfigTest("configuration.none", expectedCounts); } @@ -700,17 +644,17 @@ public class FTPTest { "custom config: system key = WINDOWS", "custom config: default date format = yyyy/MM/dd HH:mm", "custom config: server language code = de" - }; LogCounter counter = new LogCounter(); - for (int i=0; i < messages.length; i++) { - counter.addLogMessageToSearch(messages[i]); + for (String message : messages) { + counter.addLogMessageToSearch(message); } buildRule.getProject().addBuildListener(counter); buildRule.getProject().executeTarget(target); - for (int i=0; i < messages.length; i++) { - assertEquals("target "+target+":message "+ i, expectedCounts[i], counter.getMatchCount(messages[i])); + for (int i = 0; i < messages.length; i++) { + assertEquals("target " + target + ":message " + i, + expectedCounts[i], counter.getMatchCount(messages[i])); } } @@ -726,26 +670,26 @@ public class FTPTest { private void compareFiles(DirectoryScanner ds, String[] expectedFiles, String[] expectedDirectories) { - String includedFiles[] = ds.getIncludedFiles(); - String includedDirectories[] = ds.getIncludedDirectories(); + String[] includedFiles = ds.getIncludedFiles(); + String[] includedDirectories = ds.getIncludedDirectories(); assertEquals("file present: ", expectedFiles.length, includedFiles.length); assertEquals("directories present: ", expectedDirectories.length, includedDirectories.length); - for (int counter=0; counter < includedFiles.length; counter++) { + for (int counter = 0; counter < includedFiles.length; counter++) { includedFiles[counter] = includedFiles[counter].replace(File.separatorChar, '/'); } Arrays.sort(includedFiles); - for (int counter=0; counter < includedDirectories.length; counter++) { + for (int counter = 0; counter < includedDirectories.length; counter++) { includedDirectories[counter] = includedDirectories[counter] .replace(File.separatorChar, '/'); } Arrays.sort(includedDirectories); - for (int counter=0; counter < includedFiles.length; counter++) { + for (int counter = 0; counter < includedFiles.length; counter++) { assertEquals(expectedFiles[counter], includedFiles[counter]); } - for (int counter=0; counter < includedDirectories.length; counter++) { + for (int counter = 0; counter < includedDirectories.length; counter++) { assertEquals(expectedDirectories[counter], includedDirectories[counter]); counter++; } @@ -771,31 +715,34 @@ public class FTPTest { } protected void getFile(FTPClient ftp, String dir, String filename) - throws IOException, BuildException - { + throws IOException, BuildException { if (this.simulatedFailuresLeft > 0) { this.simulatedFailuresLeft--; throw new IOException("Simulated failure for testing"); } super.getFile(ftp, dir, filename); } + protected void executeRetryable(RetryHandler h, Retryable r, - String filename) throws IOException - { + String filename) throws IOException { + this.simulatedFailuresLeft = this.numberOfFailuresToSimulate; super.executeRetryable(h, r, filename); } } + public static class oneFailureFTP extends myRetryableFTP { public oneFailureFTP() { super(1); } } + public static class twoFailureFTP extends myRetryableFTP { public twoFailureFTP() { super(2); } } + public static class threeFailureFTP extends myRetryableFTP { public threeFailureFTP() { super(3); @@ -807,6 +754,7 @@ public class FTPTest { super(new Random().nextInt(Short.MAX_VALUE)); } } + public void testGetWithSelectorRetryable1() { buildRule.getProject().addTaskDefinition("ftp", oneFailureFTP.class); try { @@ -864,14 +812,15 @@ public class FTPTest { }; LogCounter counter = new LogCounter(); - for (int i=0; i < messages.length; i++) { - counter.addLogMessageToSearch(messages[i]); + for (String message : messages) { + counter.addLogMessageToSearch(message); } buildRule.getProject().addBuildListener(counter); buildRule.getProject().executeTarget(target); - for (int i=0; i < messages.length; i++) { - assertEquals("target "+target+":message "+ i, expectedCounts[i], counter.getMatchCount(messages[i])); + for (int i = 0; i < messages.length; i++) { + assertEquals("target " + target + ":message " + i, + expectedCounts[i], counter.getMatchCount(messages[i])); } } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/sos/SOSTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/sos/SOSTest.java index c45ec17e8..1354e5290 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/sos/SOSTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/sos/SOSTest.java @@ -320,7 +320,7 @@ public class SOSTest { try { buildRule.executeTarget(target); fail(errorMessage); - } catch(BuildException ex) { + } catch (BuildException ex) { assertEquals(exceptionMessage, ex.getMessage()); } } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ssh/ScpTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ssh/ScpTest.java index 2e00042ef..7694ce5fa 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ssh/ScpTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ssh/ScpTest.java @@ -60,27 +60,26 @@ import static org.junit.Assert.fail; */ public class ScpTest { + private Scp scpTask; private File tempDir; private String sshHostUri = System.getProperty("scp.host"); - private int port = Integer.parseInt( System.getProperty( "scp.port", "22" ) ); + private int port = Integer.parseInt(System.getProperty("scp.port", "22")); private String knownHosts = System.getProperty("scp.known.hosts"); private List cleanUpList = new ArrayList(); - public ScpTest() { + @Before + public void setUp() { + scpTask = createTask(); if (System.getProperty("scp.tmp") != null) { tempDir = new File(System.getProperty("scp.tmp")); } - } - - @Before - public void setUp() { cleanUpList.clear(); } @After public void tearDown() { - for( Iterator i = cleanUpList.iterator(); i.hasNext(); ) { + for (Iterator i = cleanUpList.iterator(); i.hasNext();) { File file = (File) i.next(); file.delete(); } @@ -92,77 +91,73 @@ public class ScpTest { File uploadFile = createTemporaryFile(); // upload - Scp scpTask = createTask(); - scpTask.setFile( uploadFile.getPath() ); - scpTask.setTodir( sshHostUri ); + scpTask.setFile(uploadFile.getPath()); + scpTask.setTodir(sshHostUri); scpTask.execute(); - File testFile = new File( tempDir.getPath() + File.separator + - "download-testSingleFileUploadAndDownload.test" ); - addCleanup(testFile ); + File testFile = new File(tempDir.getPath() + File.separator + + "download-testSingleFileUploadAndDownload.test"); + addCleanup(testFile); assertFalse("Assert that the testFile does not exist.", testFile.exists()); // download scpTask = createTask(); - scpTask.setFile( sshHostUri + "/" + uploadFile.getName() ); - scpTask.setTodir( testFile.getPath() ); + scpTask.setFile(sshHostUri + "/" + uploadFile.getName()); + scpTask.setTodir(testFile.getPath()); scpTask.execute(); - assertTrue( "Assert that the testFile exists.", testFile.exists() ); - compareFiles( uploadFile, testFile ); + assertTrue("Assert that the testFile exists.", testFile.exists()); + compareFiles(uploadFile, testFile); } @Test public void testMultiUploadAndDownload() throws IOException { assertNotNull("system property scp.tmp must be set", tempDir); List uploadList = new ArrayList(); - for( int i = 0; i < 5; i++ ) { - uploadList.add( createTemporaryFile() ); + for (int i = 0; i < 5; i++) { + uploadList.add(createTemporaryFile()); } - Scp scp = createTask(); FilenameSelector selector = new FilenameSelector(); - selector.setName( "scp*" ); + selector.setName("scp*"); FileSet fileset = new FileSet(); - fileset.setDir( tempDir ); - fileset.addFilename( selector ); - scp.addFileset( fileset ); - scp.setTodir( sshHostUri ); - scp.execute(); + fileset.setDir(tempDir); + fileset.addFilename(selector); + scpTask.addFileset(fileset); + scpTask.setTodir(sshHostUri); + scpTask.execute(); - File multi = new File( tempDir, "multi" ); + File multi = new File(tempDir, "multi"); multi.mkdir(); - addCleanup( multi ); + addCleanup(multi); - Scp scp2 = createTask(); - scp2.setFile( sshHostUri + "/scp*" ); - scp2.setTodir( multi.getPath() ); - scp2.execute(); + scpTask = createTask(); + scpTask.setFile(sshHostUri + "/scp*"); + scpTask.setTodir(multi.getPath()); + scpTask.execute(); FilesMatch match = new FilesMatch(); - for( Iterator i = uploadList.iterator(); i.hasNext(); ) { - File f = (File)i.next(); - match.setFile1( f ); - File f2 = new File( multi, f.getName() ); - match.setFile2( f2 ); - assertTrue("Assert file '" + f.getPath() + "' and file '" + - f2.getPath() + "'", match.eval() ); + for (Iterator i = uploadList.iterator(); i.hasNext();) { + File f = (File) i.next(); + match.setFile1(f); + File f2 = new File(multi, f.getName()); + match.setFile2(f2); + assertTrue("Assert file '" + f.getPath() + "' and file '" + + f2.getPath() + "'", match.eval()); } } @Test public void testMultiResourceCollectionUpload() throws IOException { assertNotNull("system property scp.tmp must be set", tempDir); - List uploadList = new ArrayList(); + List uploadList = new ArrayList<>(); for (int i = 0; i < 5; i++) { uploadList.add(createTemporaryFile()); } - Scp scp = createTask(); - // reverse order resource collection Sort sort = new Sort(); - sort.setProject(scp.getProject()); + sort.setProject(scpTask.getProject()); Reverse reverse = new Reverse(); reverse.add(new Name()); sort.add(reverse); @@ -170,56 +165,53 @@ public class ScpTest { FilenameSelector selector = new FilenameSelector(); selector.setName("scp*"); FileSet fileset = new FileSet(); - fileset.setProject(scp.getProject()); + fileset.setProject(scpTask.getProject()); fileset.setDir(tempDir); fileset.addFilename(selector); sort.add(fileset); - scp.add(sort); + scpTask.add(sort); - scp.setTodir(sshHostUri); - scp.execute(); + scpTask.setTodir(sshHostUri); + scpTask.execute(); } @Test public void testRemoteToDir() throws IOException { - Scp scpTask = createTask(); // first try an invalid URI try { - scpTask.setRemoteTodir( "host:/a/path/without/an/at" ); + scpTask.setRemoteTodir("host:/a/path/without/an/at"); fail("Expected a BuildException to be thrown due to invalid" + " remoteToDir"); - } - catch (BuildException e) - { + } catch (BuildException e) { // expected //TODO we should be asserting a value in here } // And this one should work - scpTask.setRemoteTodir( "user:password@host:/a/path/with/an/at" ); + scpTask.setRemoteTodir("user:password@host:/a/path/with/an/at"); // no exception } - public void addCleanup( File file ) { - cleanUpList.add( file ); + private void addCleanup(File file) { + cleanUpList.add(file); } private void compareFiles(File src, File dest) { FilesMatch match = new FilesMatch(); - match.setFile1( src ); - match.setFile2( dest ); + match.setFile1(src); + match.setFile2(dest); - assertTrue( "Assert files are equal.", match.eval() ); + assertTrue("Assert files are equal.", match.eval()); } private File createTemporaryFile() throws IOException { File uploadFile; - uploadFile = File.createTempFile( "scp", "test", tempDir ); - FileWriter writer = new FileWriter( uploadFile ); + uploadFile = File.createTempFile("scp", "test", tempDir); + FileWriter writer = new FileWriter(uploadFile); writer.write("Can you hear me now?\n"); writer.close(); - addCleanup( uploadFile ); + addCleanup(uploadFile); return uploadFile; } @@ -227,13 +219,13 @@ public class ScpTest { Scp scp = new Scp(); Project p = new Project(); p.init(); - scp.setProject( p ); - if( knownHosts != null ) { - scp.setKnownhosts( knownHosts ); + scp.setProject(p); + if (knownHosts != null) { + scp.setKnownhosts(knownHosts); } else { - scp.setTrust( true ); + scp.setTrust(true); } - scp.setPort( port ); + scp.setPort(port); return scp; } } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/unix/SymlinkTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/unix/SymlinkTest.java index e36d6838b..b5f4bbf2f 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/unix/SymlinkTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/unix/SymlinkTest.java @@ -17,11 +17,11 @@ */ /* - * Since the initial version of this file was deveolped on the clock on + * Since the initial version of this file was developed on the clock on * an NSF grant I should say the following boilerplate: * * This material is based upon work supported by the National Science - * Foundaton under Grant No. EIA-0196404. Any opinions, findings, and + * Foundation under Grant No. EIA-0196404. Any opinions, findings, and * conclusions or recommendations expressed in this material are those * of the author and do not necessarily reflect the views of the * National Science Foundation. @@ -192,7 +192,7 @@ public class SymlinkTest { buildRule.executeTarget("test-fileutils"); SymbolicLinkUtils su = SymbolicLinkUtils.getSymbolicLinkUtils(); - java.io.File f = new File(buildRule.getOutputDir(), "file1"); + File f = new File(buildRule.getOutputDir(), "file1"); assertTrue(f.exists()); assertFalse(f.isDirectory()); assertTrue(f.isFile()); @@ -260,7 +260,7 @@ public class SymlinkTest { f.getName())); // it is not possible to find out that symbolic links pointing - // to inexistent files or directories are symbolic links + // to nonexistent files or directories are symbolic links // it used to be possible to detect this on Mac // this is not true under Snow Leopard and JDK 1.5 // Removing special handling of MacOS until someone shouts diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/vss/MSVSSTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/vss/MSVSSTest.java index aa96d8d51..772c6c1f7 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/vss/MSVSSTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/vss/MSVSSTest.java @@ -65,7 +65,7 @@ public class MSVSSTest implements MSVSSConstants { private Project project; @Before - public void setUp(){ + public void setUp() { project = new Project(); project.setBasedir("."); project.init(); @@ -82,8 +82,7 @@ public class MSVSSTest implements MSVSSConstants { @Test public void testGetCommandLine() { String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_GET, DS_VSS_PROJECT_PATH, - MSVSS.FLAG_OVERRIDE_WORKING_DIR + project.getBaseDir() - .getAbsolutePath() + MSVSS.FLAG_OVERRIDE_WORKING_DIR + project.getBaseDir().getAbsolutePath() + File.separator + LOCAL_PATH, MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_RECURSION, MSVSS.FLAG_VERSION + VERSION, MSVSS.FLAG_LOGIN + VSS_USERNAME + "," + VSS_PASSWORD, FLAG_FILETIME_UPDATED, FLAG_SKIP_WRITABLE}; @@ -238,7 +237,7 @@ public class MSVSSTest implements MSVSSConstants { // Get today's date SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss z"); - sdf.setTimeZone( TimeZone.getTimeZone("GMT") ); + sdf.setTimeZone(TimeZone.getTimeZone("GMT")); String expected = sdf.format(date); // Set up a VSSHistory task @@ -270,7 +269,7 @@ public class MSVSSTest implements MSVSSConstants { try { buildRule.executeTarget(target); fail(failMessage); - } catch(BuildException ex) { + } catch (BuildException ex) { assertEquals(exceptionMessage, ex.getMessage()); } } @@ -462,8 +461,8 @@ public class MSVSSTest implements MSVSSConstants { // Count the number of empty strings int cnt = 0; - for (int i = 0; i < genLength; i++) { - if (sGeneratedCmdLine[i].equals("")) { + for (String argument : sGeneratedCmdLine) { + if (argument.equals("")) { cnt++; } } diff --git a/src/tests/junit/org/apache/tools/ant/types/AddTypeTest.java b/src/tests/junit/org/apache/tools/ant/types/AddTypeTest.java index 4f95c35a6..6dfbcf6d4 100644 --- a/src/tests/junit/org/apache/tools/ant/types/AddTypeTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/AddTypeTest.java @@ -69,13 +69,13 @@ public class AddTypeTest { @Test public void testNestedB() { buildRule.executeTarget("nested.b"); - AntAssert.assertContains( "add B called", buildRule.getLog()); + AntAssert.assertContains("add B called", buildRule.getLog()); } @Test public void testNestedC() { buildRule.executeTarget("nested.c"); - AntAssert.assertContains( "add C called", buildRule.getLog()); + AntAssert.assertContains("add C called", buildRule.getLog()); } @Test @@ -91,19 +91,19 @@ public class AddTypeTest { @Test public void testConditionType() { buildRule.executeTarget("condition.type"); - AntAssert.assertContains( "beforeafter", buildRule.getLog()); + AntAssert.assertContains("beforeafter", buildRule.getLog()); } @Test public void testConditionTask() { buildRule.executeTarget("condition.task"); - AntAssert.assertContains( "My Condition execution", buildRule.getLog()); + AntAssert.assertContains("My Condition execution", buildRule.getLog()); } @Test public void testConditionConditionType() { buildRule.executeTarget("condition.condition.type"); - AntAssert.assertContains( "My Condition eval", buildRule.getLog()); + AntAssert.assertContains("My Condition eval", buildRule.getLog()); } @Test @@ -137,19 +137,25 @@ public class AddTypeTest { // The following will be used as types and tasks - public static interface A {} - public static interface B {} - public static interface C extends A {} - public static interface AB extends A, B {} + public interface A { + } + public interface B { + } + public interface C extends A { + } + public interface AB extends A, B { + } - public static class AImpl implements A{} - public static class BImpl implements B{} - public static class CImpl implements C{} - public static class ABImpl implements AB{} + public static class AImpl implements A { + } + public static class BImpl implements B { + } + public static class CImpl implements C { + } + public static class ABImpl implements AB { + } - public static class NestedContainer - extends Task - { + public static class NestedContainer extends Task { public void add(A el) { log("add A called"); } @@ -161,9 +167,7 @@ public class AddTypeTest { } } - public static class MyCondition - implements Condition - { + public static class MyCondition implements Condition { Project project; public void setProject(Project project) { this.project = project; @@ -177,8 +181,7 @@ public class AddTypeTest { } } - public static class MyValue - { + public static class MyValue { private String text = "NOT SET YET"; public void addText(String text) { this.text = text; @@ -188,9 +191,7 @@ public class AddTypeTest { } } - public static class MyAddConfigured - extends Task - { + public static class MyAddConfigured extends Task { MyValue value; public void addConfigured(MyValue value) { log("value is " + value); @@ -204,9 +205,7 @@ public class AddTypeTest { } } - public static class MyAddConfiguredValue - extends Task - { + public static class MyAddConfiguredValue extends Task { MyValue value; public void addConfiguredValue(MyValue value) { log("value is " + value); diff --git a/src/tests/junit/org/apache/tools/ant/types/AssertionsTest.java b/src/tests/junit/org/apache/tools/ant/types/AssertionsTest.java index 03d0c975c..5e54f45dd 100644 --- a/src/tests/junit/org/apache/tools/ant/types/AssertionsTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/AssertionsTest.java @@ -43,14 +43,14 @@ public class AssertionsTest { /** * runs a test and expects an assertion thrown in forked code - * @param target + * @param target String */ private void expectAssertion(String target) { try { buildRule.executeTarget(target); fail("BuildException should have been thrown by assertion fail in task"); } catch (BuildException ex) { - assertContains("assertion not thrown in "+target, "Java returned: 1", ex.getMessage()); + assertContains("assertion not thrown in " + target, "Java returned: 1", ex.getMessage()); } } diff --git a/src/tests/junit/org/apache/tools/ant/types/CommandlineJavaTest.java b/src/tests/junit/org/apache/tools/ant/types/CommandlineJavaTest.java index abfb70f73..53aa27c70 100644 --- a/src/tests/junit/org/apache/tools/ant/types/CommandlineJavaTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/CommandlineJavaTest.java @@ -88,7 +88,7 @@ public class CommandlineJavaTest { c.createClasspath(project).setLocation(project.resolveFile("build.xml")); c.createClasspath(project).setLocation(project.resolveFile( - System.getProperty(MagicNames.ANT_HOME)+"/lib/ant.jar")); + System.getProperty(MagicNames.ANT_HOME) + "/lib/ant.jar")); s = c.getCommandline(); assertEquals("with classpath", 6, s.length); // assertEquals("with classpath", "java", s[0]); diff --git a/src/tests/junit/org/apache/tools/ant/types/CommandlineTest.java b/src/tests/junit/org/apache/tools/ant/types/CommandlineTest.java index e8e444292..ce728e88f 100644 --- a/src/tests/junit/org/apache/tools/ant/types/CommandlineTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/CommandlineTest.java @@ -35,8 +35,8 @@ public class CommandlineTest { public void testTokenizer() { String[] s = Commandline.translateCommandline("1 2 3"); assertEquals("Simple case", 3, s.length); - for (int i=0; i<3; i++) { - assertEquals(""+(i+1), s[i]); + for (int i = 0; i < 3; i++) { + assertEquals("" + (i + 1), s[i]); } s = Commandline.translateCommandline(""); diff --git a/src/tests/junit/org/apache/tools/ant/types/DescriptionTest.java b/src/tests/junit/org/apache/tools/ant/types/DescriptionTest.java index 31b56f91f..aeb7911ed 100644 --- a/src/tests/junit/org/apache/tools/ant/types/DescriptionTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/DescriptionTest.java @@ -36,24 +36,28 @@ public class DescriptionTest { @Test public void test1() { buildRule.configureProject("src/etc/testcases/types/description1.xml"); - assertEquals("Single description failed", "Test Project Description", buildRule.getProject().getDescription()); + assertEquals("Single description failed", "Test Project Description", + buildRule.getProject().getDescription()); } @Test public void test2() { buildRule.configureProject("src/etc/testcases/types/description2.xml"); - assertEquals("Multi line description failed", "Multi Line\nProject Description", buildRule.getProject().getDescription()); + assertEquals("Multi line description failed", "Multi Line\nProject Description", + buildRule.getProject().getDescription()); } @Test public void test3() { buildRule.configureProject("src/etc/testcases/types/description3.xml"); - assertEquals("Multi instance description failed", "Multi Instance Project Description", buildRule.getProject().getDescription()); + assertEquals("Multi instance description failed", "Multi Instance Project Description", + buildRule.getProject().getDescription()); } @Test public void test4() { buildRule.configureProject("src/etc/testcases/types/description4.xml"); - assertEquals("Multi instance nested description failed", "Multi Instance Nested Project Description", buildRule.getProject().getDescription()); + assertEquals("Multi instance nested description failed", "Multi Instance Nested Project Description", + buildRule.getProject().getDescription()); } } diff --git a/src/tests/junit/org/apache/tools/ant/types/EnumeratedAttributeTest.java b/src/tests/junit/org/apache/tools/ant/types/EnumeratedAttributeTest.java index dcb8a78bf..b20412ec1 100644 --- a/src/tests/junit/org/apache/tools/ant/types/EnumeratedAttributeTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/EnumeratedAttributeTest.java @@ -36,11 +36,11 @@ public class EnumeratedAttributeTest { @Test public void testContains() { EnumeratedAttribute t1 = new TestNormal(); - for (int i=0; i=0 ) { + if (buildRule.getLog().indexOf("testLogInputString can-cat") >= 0) { AntAssert.assertContains("Using input string", buildRule.getFullLog()); } } diff --git a/src/tests/junit/org/apache/tools/ant/types/ResourceOutputTest.java b/src/tests/junit/org/apache/tools/ant/types/ResourceOutputTest.java index b66335a3b..25a653df1 100644 --- a/src/tests/junit/org/apache/tools/ant/types/ResourceOutputTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/ResourceOutputTest.java @@ -50,7 +50,7 @@ public class ResourceOutputTest { public void setUp() { project = new Project(); project.init(); - project.setUserProperty("basedir" , basedir.getAbsolutePath()); + project.setUserProperty("basedir", basedir.getAbsolutePath()); } @Test diff --git a/src/tests/junit/org/apache/tools/ant/types/TarFileSetTest.java b/src/tests/junit/org/apache/tools/ant/types/TarFileSetTest.java index b30168aa7..efaa47482 100644 --- a/src/tests/junit/org/apache/tools/ant/types/TarFileSetTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/TarFileSetTest.java @@ -43,7 +43,7 @@ public class TarFileSetTest extends AbstractFileSetTest { @Test public final void testAttributes() { - TarFileSet f = (TarFileSet)getInstance(); + TarFileSet f = (TarFileSet) getInstance(); //check that dir and src are incompatible f.setSrc(new File("example.tar")); try { @@ -54,7 +54,7 @@ public class TarFileSetTest extends AbstractFileSetTest { } catch (BuildException be) { assertEquals("Cannot set both dir and src attributes",be.getMessage()); } - f = (TarFileSet)getInstance(); + f = (TarFileSet) getInstance(); //check that dir and src are incompatible f.setDir(new File("examples")); try { @@ -66,7 +66,7 @@ public class TarFileSetTest extends AbstractFileSetTest { assertEquals("Cannot set both dir and src attributes",be.getMessage()); } //check that fullpath and prefix are incompatible - f = (TarFileSet)getInstance(); + f = (TarFileSet) getInstance(); f.setSrc(new File("example.tar")); f.setPrefix("/examples"); try { @@ -77,7 +77,7 @@ public class TarFileSetTest extends AbstractFileSetTest { } catch (BuildException be) { assertEquals("Cannot set both fullpath and prefix attributes", be.getMessage()); } - f = (TarFileSet)getInstance(); + f = (TarFileSet) getInstance(); f.setSrc(new File("example.tar")); f.setFullpath("/doc/manual/index.html"); try { @@ -89,7 +89,7 @@ public class TarFileSetTest extends AbstractFileSetTest { assertEquals("Cannot set both fullpath and prefix attributes", be.getMessage()); } // check that reference tarfilesets cannot have specific attributes - f = (TarFileSet)getInstance(); + f = (TarFileSet) getInstance(); f.setRefid(new Reference(getProject(), "test")); try { f.setSrc(new File("example.tar")); @@ -101,18 +101,22 @@ public class TarFileSetTest extends AbstractFileSetTest { + "attribute when using refid", be.getMessage()); } // check that a reference tarfileset gets the same attributes as the original - f = (TarFileSet)getInstance(); + f = (TarFileSet) getInstance(); f.setSrc(new File("example.tar")); f.setPrefix("/examples"); f.setFileMode("600"); f.setDirMode("530"); getProject().addReference("test",f); - TarFileSet zid=(TarFileSet)getInstance(); + TarFileSet zid = (TarFileSet) getInstance(); zid.setRefid(new Reference(getProject(), "test")); - assertTrue("src attribute copied by copy constructor",zid.getSrc(getProject()).equals(f.getSrc(getProject()))); - assertTrue("prefix attribute copied by copy constructor",f.getPrefix(getProject()).equals(zid.getPrefix(getProject()))); - assertTrue("file mode attribute copied by copy constructor",f.getFileMode(getProject())==zid.getFileMode(getProject())); - assertTrue("dir mode attribute copied by copy constructor",f.getDirMode(getProject())==zid.getDirMode(getProject())); + assertTrue("src attribute copied by copy constructor", + zid.getSrc(getProject()).equals(f.getSrc(getProject()))); + assertTrue("prefix attribute copied by copy constructor", + f.getPrefix(getProject()).equals(zid.getPrefix(getProject()))); + assertTrue("file mode attribute copied by copy constructor", + f.getFileMode(getProject()) == zid.getFileMode(getProject())); + assertTrue("dir mode attribute copied by copy constructor", + f.getDirMode(getProject()) == zid.getDirMode(getProject())); } diff --git a/src/tests/junit/org/apache/tools/ant/types/XMLCatalogTest.java b/src/tests/junit/org/apache/tools/ant/types/XMLCatalogTest.java index c1adc30db..2422c7999 100644 --- a/src/tests/junit/org/apache/tools/ant/types/XMLCatalogTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/XMLCatalogTest.java @@ -120,7 +120,6 @@ public class XMLCatalogTest { @Test public void testNonExistentEntry() throws IOException, SAXException, TransformerException { - ResourceLocation dtd = new ResourceLocation(); dtd.setPublicId("PUBLIC ID ONE"); dtd.setLocation("i/dont/exist.dtd"); @@ -175,8 +174,8 @@ public class XMLCatalogTest { catalog.setRefid(new Reference(project, "catalog")); try { - InputSource result = catalog.resolveEntity("PUBLIC ID ONE", - "i/dont/exist.dtd"); + @SuppressWarnings("unused") + InputSource result = catalog.resolveEntity("PUBLIC ID ONE", "i/dont/exist.dtd"); fail("Can make XMLCatalog a Reference to itself."); } catch (BuildException be) { assertEquals("This data type contains a circular reference.", @@ -198,8 +197,7 @@ public class XMLCatalogTest { catalog1.setRefid(new Reference(project, "catalog2")); try { - catalog1.resolveEntity("PUBLIC ID ONE", - "i/dont/exist.dtd"); + catalog1.resolveEntity("PUBLIC ID ONE", "i/dont/exist.dtd"); fail("Can make circular reference"); } catch (BuildException be) { assertEquals("This data type contains a circular reference.", @@ -222,10 +220,7 @@ public class XMLCatalogTest { InputSource result = catalog.resolveEntity("-//stevo//DTD doc 1.0//EN", "nap:chemical+brothers"); assertNotNull(result); - assertEquals(toURLString(dtdFile), - result.getSystemId()); - - + assertEquals(toURLString(dtdFile), result.getSystemId()); } @Test @@ -241,14 +236,12 @@ public class XMLCatalogTest { InputSource result = catalog.resolveEntity("-//stevo//DTD doc 1.0//EN", "nap:chemical+brothers"); assertNotNull(result); - assertEquals(toURLString(dtdFile), - result.getSystemId()); + assertEquals(toURLString(dtdFile), result.getSystemId()); } @Test public void testEntryReference() throws IOException, SAXException, TransformerException { - String publicId = "-//stevo//DTD doc 1.0//EN"; String sysid = "src/etc/testcases/taskdefs/optional/xml/doc.dtd"; @@ -278,23 +271,18 @@ public class XMLCatalogTest { catalog1.setRefid(new Reference(project, "catalog")); catalog2.setRefid(new Reference(project, "catalog1")); - InputSource isResult = catalog2.resolveEntity(publicId, - "nap:chemical+brothers"); + InputSource isResult = catalog2.resolveEntity(publicId, "nap:chemical+brothers"); assertNotNull(isResult); - assertEquals(toURLString(dtdFile), - isResult.getSystemId()); - + assertEquals(toURLString(dtdFile), isResult.getSystemId()); Source result = catalog.resolve(uri, null); assertNotNull(result); - assertEquals(toURLString(xmlFile), - result.getSystemId()); + assertEquals(toURLString(xmlFile), result.getSystemId()); } @Test public void testNestedCatalog() throws IOException, SAXException, TransformerException { - String publicId = "-//stevo//DTD doc 1.0//EN"; String dtdLoc = "src/etc/testcases/taskdefs/optional/xml/doc.dtd"; @@ -316,22 +304,18 @@ public class XMLCatalogTest { XMLCatalog catalog1 = newCatalog(); catalog1.addConfiguredXMLCatalog(catalog); - InputSource isResult = catalog1.resolveEntity(publicId, - "nap:chemical+brothers"); + InputSource isResult = catalog1.resolveEntity(publicId, "nap:chemical+brothers"); assertNotNull(isResult); - assertEquals(toURLString(dtdFile), - isResult.getSystemId()); + assertEquals(toURLString(dtdFile), isResult.getSystemId()); Source result = catalog.resolve(uri, null); assertNotNull(result); - assertEquals(toURLString(xmlFile), - result.getSystemId()); + assertEquals(toURLString(xmlFile), result.getSystemId()); } @Test public void testResolverBase() throws MalformedURLException, TransformerException { - String uri = "http://foo.com/bar/blah.xml"; String uriLoc = "etc/testcases/taskdefs/optional/xml/about.xml"; String base = toURLString(project.getBaseDir()) + "/src/"; @@ -344,15 +328,12 @@ public class XMLCatalogTest { Source result = catalog.resolve(uri, base); assertNotNull(result); - assertEquals(toURLString(xmlFile), - result.getSystemId()); + assertEquals(toURLString(xmlFile), result.getSystemId()); } @Test public void testClasspath() throws IOException, TransformerException, SAXException { - - String publicId = "-//stevo//DTD doc 1.0//EN"; String dtdLoc = "testcases/taskdefs/optional/xml/doc.dtd"; String path1 = project.getBaseDir().toString() + "/src/etc"; @@ -377,8 +358,7 @@ public class XMLCatalogTest { aPath.append(new Path(project, path2)); catalog.setClasspath(aPath); - InputSource isResult = catalog.resolveEntity(publicId, - "nap:chemical+brothers"); + InputSource isResult = catalog.resolveEntity(publicId, "nap:chemical+brothers"); assertNotNull(isResult); String resultStr1 = new URL(isResult.getSystemId()).getFile(); assertTrue(toURLString(dtdFile).endsWith(resultStr1)); diff --git a/src/tests/junit/org/apache/tools/ant/types/ZipFileSetTest.java b/src/tests/junit/org/apache/tools/ant/types/ZipFileSetTest.java index e7b14c191..f9265feee 100644 --- a/src/tests/junit/org/apache/tools/ant/types/ZipFileSetTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/ZipFileSetTest.java @@ -30,7 +30,7 @@ import static org.junit.Assert.fail; /** * JUnit 3 testcases for org.apache.tools.ant.types.ZipFileSet. * - *

This doesn't actually test much, mainly reference handling. + *

This doesn't actually test much, mainly reference handling.

* */ @@ -42,7 +42,7 @@ public class ZipFileSetTest extends AbstractFileSetTest { @Test public final void testAttributes() { - ZipFileSet f = (ZipFileSet)getInstance(); + ZipFileSet f = (ZipFileSet) getInstance(); //check that dir and src are incompatible f.setSrc(new File("example.zip")); try { @@ -51,9 +51,9 @@ public class ZipFileSetTest extends AbstractFileSetTest { + f.getDataTypeName() + " when a src is already present"); } catch (BuildException be) { - assertEquals("Cannot set both dir and src attributes",be.getMessage()); + assertEquals("Cannot set both dir and src attributes", be.getMessage()); } - f = (ZipFileSet)getInstance(); + f = (ZipFileSet) getInstance(); //check that dir and src are incompatible f.setDir(new File("examples")); try { @@ -62,10 +62,10 @@ public class ZipFileSetTest extends AbstractFileSetTest { + f.getDataTypeName() + " when a dir is already present"); } catch (BuildException be) { - assertEquals("Cannot set both dir and src attributes",be.getMessage()); + assertEquals("Cannot set both dir and src attributes", be.getMessage()); } //check that fullpath and prefix are incompatible - f = (ZipFileSet)getInstance(); + f = (ZipFileSet) getInstance(); f.setSrc(new File("example.zip")); f.setPrefix("/examples"); try { @@ -76,7 +76,7 @@ public class ZipFileSetTest extends AbstractFileSetTest { } catch (BuildException be) { assertEquals("Cannot set both fullpath and prefix attributes", be.getMessage()); } - f = (ZipFileSet)getInstance(); + f = (ZipFileSet) getInstance(); f.setSrc(new File("example.zip")); f.setFullpath("/doc/manual/index.html"); try { @@ -88,7 +88,7 @@ public class ZipFileSetTest extends AbstractFileSetTest { assertEquals("Cannot set both fullpath and prefix attributes", be.getMessage()); } // check that reference zipfilesets cannot have specific attributes - f = (ZipFileSet)getInstance(); + f = (ZipFileSet) getInstance(); f.setRefid(new Reference(getProject(), "test")); try { f.setSrc(new File("example.zip")); @@ -100,18 +100,22 @@ public class ZipFileSetTest extends AbstractFileSetTest { + "attribute when using refid", be.getMessage()); } // check that a reference zipfileset gets the same attributes as the original - f = (ZipFileSet)getInstance(); + f = (ZipFileSet) getInstance(); f.setSrc(new File("example.zip")); f.setPrefix("/examples"); f.setFileMode("600"); f.setDirMode("530"); getProject().addReference("test",f); - ZipFileSet zid=(ZipFileSet)getInstance(); + ZipFileSet zid = (ZipFileSet) getInstance(); zid.setRefid(new Reference(getProject(), "test")); - assertTrue("src attribute copied by copy constructor",zid.getSrc(getProject()).equals(f.getSrc(getProject()))); - assertTrue("prefix attribute copied by copy constructor",f.getPrefix(getProject()).equals(zid.getPrefix(getProject()))); - assertTrue("file mode attribute copied by copy constructor",f.getFileMode(getProject())==zid.getFileMode(getProject())); - assertTrue("dir mode attribute copied by copy constructor",f.getDirMode(getProject())==zid.getDirMode(getProject())); + assertTrue("src attribute copied by copy constructor", + zid.getSrc(getProject()).equals(f.getSrc(getProject()))); + assertTrue("prefix attribute copied by copy constructor", + f.getPrefix(getProject()).equals(zid.getPrefix(getProject()))); + assertEquals("file mode attribute copied by copy constructor", + f.getFileMode(getProject()), zid.getFileMode(getProject())); + assertEquals("dir mode attribute copied by copy constructor", + f.getDirMode(getProject()), zid.getDirMode(getProject())); } diff --git a/src/tests/junit/org/apache/tools/ant/types/mappers/MapperResult.java b/src/tests/junit/org/apache/tools/ant/types/mappers/MapperResult.java index a982bcbb6..a52cabf35 100644 --- a/src/tests/junit/org/apache/tools/ant/types/mappers/MapperResult.java +++ b/src/tests/junit/org/apache/tools/ant/types/mappers/MapperResult.java @@ -80,7 +80,7 @@ public class MapperResult extends Task { if (result == null) { flattened = NULL_MAPPER_RESULT; } else { - StringBuffer b = new StringBuffer(); + StringBuilder b = new StringBuilder(); for (int i = 0; i < result.length; ++i) { if (i != 0) { b.append("|"); diff --git a/src/tests/junit/org/apache/tools/ant/types/resources/FileResourceTest.java b/src/tests/junit/org/apache/tools/ant/types/resources/FileResourceTest.java index 10fa131a7..690ace60c 100644 --- a/src/tests/junit/org/apache/tools/ant/types/resources/FileResourceTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/resources/FileResourceTest.java @@ -20,7 +20,6 @@ package org.apache.tools.ant.types.resources; import java.io.File; import org.apache.tools.ant.Project; - import org.junit.Before; import org.junit.Test; diff --git a/src/tests/junit/org/apache/tools/ant/types/resources/LazyResourceCollectionTest.java b/src/tests/junit/org/apache/tools/ant/types/resources/LazyResourceCollectionTest.java index 4f9d56533..0076c6db8 100644 --- a/src/tests/junit/org/apache/tools/ant/types/resources/LazyResourceCollectionTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/resources/LazyResourceCollectionTest.java @@ -22,7 +22,6 @@ import java.util.Iterator; import java.util.List; import java.util.NoSuchElementException; - import org.apache.tools.ant.types.Resource; import org.apache.tools.ant.types.ResourceCollection; import org.junit.Test; diff --git a/src/tests/junit/org/apache/tools/ant/types/resources/TarResourceTest.java b/src/tests/junit/org/apache/tools/ant/types/resources/TarResourceTest.java index a9593f090..f848f7da7 100644 --- a/src/tests/junit/org/apache/tools/ant/types/resources/TarResourceTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/resources/TarResourceTest.java @@ -24,6 +24,7 @@ import org.junit.Rule; import org.junit.Test; import java.io.File; +import java.io.IOException; import static org.apache.tools.ant.FileUtilities.getFileContents; import static org.junit.Assert.assertEquals; @@ -46,7 +47,7 @@ public class TarResourceTest { } @Test - public void testUncompressSource() throws java.io.IOException { + public void testUncompressSource() throws IOException { buildRule.executeTarget("uncompressSource"); assertEquals(getFileContents(buildRule.getProject().resolveFile("../../asf-logo.gif")), getFileContents(new File(buildRule.getProject().getProperty("output"), "asf-logo.gif"))); diff --git a/src/tests/junit/org/apache/tools/ant/types/selectors/BaseSelectorRule.java b/src/tests/junit/org/apache/tools/ant/types/selectors/BaseSelectorRule.java index d5613b266..643dbeb0c 100644 --- a/src/tests/junit/org/apache/tools/ant/types/selectors/BaseSelectorRule.java +++ b/src/tests/junit/org/apache/tools/ant/types/selectors/BaseSelectorRule.java @@ -20,7 +20,6 @@ package org.apache.tools.ant.types.selectors; import java.io.File; - import org.apache.tools.ant.BuildFileRule; @@ -100,21 +99,20 @@ public class BaseSelectorRule extends BuildFileRule { * a string of "T"s amd "F"s. */ public String mirrorSelectionString(FileSelector selector) { - return selectionString(mirrordir,mirrorfiles,selector); + return selectionString(mirrordir, mirrorfiles, selector); } /** * Worker method for the two convenience methods above. Applies a * selector on a set of files passed in and returns a string of - * "T"s amd "F"s from applying the selector to each file. + * "T"s and "F"s from applying the selector to each file. */ public String selectionString(File basedir, File[] files, FileSelector selector) { StringBuilder buf = new StringBuilder(); for (int x = 0; x < files.length; x++) { - if (selector.isSelected(basedir,filenames[x],files[x])) { + if (selector.isSelected(basedir, filenames[x], files[x])) { buf.append('T'); - } - else { + } else { buf.append('F'); } } diff --git a/src/tests/junit/org/apache/tools/ant/types/selectors/BaseSelectorTest.java b/src/tests/junit/org/apache/tools/ant/types/selectors/BaseSelectorTest.java index 2332778e6..e9c0e9903 100644 --- a/src/tests/junit/org/apache/tools/ant/types/selectors/BaseSelectorTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/selectors/BaseSelectorTest.java @@ -79,7 +79,7 @@ public abstract class BaseSelectorTest extends BuildFileTest { */ public BaseSelector getSelector() { BaseSelector selector = getInstance(); - selector.setProject( getProject() ); + selector.setProject(getProject()); return selector; } @@ -135,12 +135,11 @@ public abstract class BaseSelectorTest extends BuildFileTest { * "T"s amd "F"s from applying the selector to each file. */ public String selectionString(File basedir, File[] files, FileSelector selector) { - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); for (int x = 0; x < files.length; x++) { - if (selector.isSelected(basedir,filenames[x],files[x])) { + if (selector.isSelected(basedir, filenames[x], files[x])) { buf.append('T'); - } - else { + } else { buf.append('F'); } } @@ -173,13 +172,10 @@ public abstract class BaseSelectorTest extends BuildFileTest { int length1 = expected.length(); int length2 = result.length(); int min = (length1 > length2) ? length2 : length1; - StringBuffer sb = new StringBuffer(); - for (int i=0; i filelist.length()) ? filelist.length() : filenames.length; - for (int i=0; i iterator() { @@ -63,6 +63,8 @@ public class MockCache implements Cache { } private void log(String msg) { - if (debug) System.out.println(this+msg); + if (debug) { + System.out.println(this + msg); + } } } diff --git a/src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java b/src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java index aa04b0900..496b7aef9 100644 --- a/src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java @@ -19,8 +19,8 @@ package org.apache.tools.ant.types.selectors; -// Java import java.io.File; +import java.io.FileWriter; import java.text.RuleBasedCollator; import java.util.Comparator; import java.util.Iterator; @@ -168,19 +168,19 @@ public class ModifiedSelectorTest { @Test public void testCustomAlgorithm() { String algo = getAlgoName("org.apache.tools.ant.types.selectors.modifiedselector.HashvalueAlgorithm"); - assertTrue("Wrong algorithm used: "+algo, algo.startsWith("HashvalueAlgorithm")); + assertTrue("Wrong algorithm used: " + algo, algo.startsWith("HashvalueAlgorithm")); } @Test public void testCustomAlgorithm2() { String algo = getAlgoName("org.apache.tools.ant.types.selectors.MockAlgorithm"); - assertTrue("Wrong algorithm used: "+algo, algo.startsWith("MockAlgorithm")); + assertTrue("Wrong algorithm used: " + algo, algo.startsWith("MockAlgorithm")); } @Test public void testCustomClasses() { - Assume.assumeNotNull("Ant home not set", selectorRule.getProject().getProperty("ant.home") ); + Assume.assumeNotNull("Ant home not set", selectorRule.getProject().getProperty("ant.home")); BFT bft = new BFT(); bft.setUp(); try { @@ -261,13 +261,19 @@ public class ModifiedSelectorTest { sel.isSelected(base, "file2", file2); assertFalse("Cache must not be saved after 2nd selection.", cache.saved); switch (kind) { - case 1 : project.fireTaskFinished(); break; - case 2 : project.fireTargetFinished(); break; - case 3 : project.fireBuildFinished(); break; + case 1 : + project.fireTaskFinished(); + break; + case 2 : + project.fireTargetFinished(); + break; + case 3 : + project.fireBuildFinished(); + break; } - assertTrue("Cache must be saved after " + kinds[kind-1] + "Finished-Event.", cache.saved); + assertTrue("Cache must be saved after " + kinds[kind - 1] + "Finished-Event.", cache.saved); - // MockCache doesnt create a file - therefore no cleanup needed + // MockCache doesn't create a file - therefore no cleanup needed } @@ -291,8 +297,12 @@ public class ModifiedSelectorTest { int posEnd = s1.indexOf(" comparator="); String algo = s1.substring(posStart, posEnd); // '<' and '>' are only used if the algorithm has properties - if (algo.startsWith("<")) algo = algo.substring(1); - if (algo.endsWith(">")) algo = algo.substring(0, algo.length()-1); + if (algo.startsWith("<")) { + algo = algo.substring(1); + } + if (algo.endsWith(">")) { + algo = algo.substring(0, algo.length() - 1); + } // return the clean value return algo; } @@ -436,10 +446,10 @@ public class ModifiedSelectorTest { Object returned = it2.next(); boolean ok = (key1.equals(returned) || key2.equals(returned)); String msg = "Iterator returned unexpected value." - + " key1.equals(returned)="+key1.equals(returned) - + " key2.equals(returned)="+key2.equals(returned) - + " returned="+returned - + " ok="+ok; + + " key1.equals(returned)=" + key1.equals(returned) + + " key2.equals(returned)=" + key2.equals(returned) + + " returned=" + returned + + " ok=" + ok; assertTrue(msg, ok); // clear the cache @@ -533,25 +543,20 @@ public class ModifiedSelectorTest { } - - // ============== testcases for the comparator implementations ============== - @Test public void testEqualComparator() { EqualComparator comp = new EqualComparator(); doTest(comp); } - @Test public void testRuleComparator() { - RuleBasedCollator comp = (RuleBasedCollator)RuleBasedCollator.getInstance(); + RuleBasedCollator comp = (RuleBasedCollator) RuleBasedCollator.getInstance(); doTest(comp); } - @Test public void testEqualComparatorViaSelector() { ModifiedSelector s = new ModifiedSelector(); @@ -565,7 +570,6 @@ public class ModifiedSelectorTest { } } - @Test @Ignore("not yet supported see note in selector") public void testRuleComparatorViaSelector() { @@ -580,14 +584,12 @@ public class ModifiedSelectorTest { } } - @Test @Ignore("same logic as on algorithm, no testcases created") public void testCustomComparator() { // same logic as on algorithm, no testcases created } - @Test public void testResourceSelectorSimple() { BFT bft = new BFT(); @@ -637,20 +639,18 @@ public class ModifiedSelectorTest { assertTrue("Comparator gave wrong value.", comp.compare(o2, o3) == 0); } - // ===================== scenario tests ===================== - /** * Tests whether the seldirs attribute is used. */ @Test public void testSeldirs() { ModifiedSelector s = new ModifiedSelector(); - StringBuffer sbTrue = new StringBuffer(); - StringBuffer sbFalse = new StringBuffer(); - for (int i=0; i - *
  • try fist time --> should select all
  • - *
  • try second time --> should select no files (only directories)
  • - *
  • modify timestamp of one file and content of a nother one
  • - *
  • try third time --> should select only the file with modified - * content
  • + * and update=true). + *
    1. try fist time --> should select all
    2. + *
    3. try second time --> should select no files (only directories)
    4. + *
    5. modify timestamp of one file and content of another one
    6. + *
    7. try third time --> should select only the file with modified + * content
    */ @Test public void testScenario1() { @@ -718,9 +717,9 @@ public class ModifiedSelectorTest { // AccessObject to the test-Ant-environment bft = new BFT(); // give some values (via property file) to that environment - bft.writeProperties("f2name="+f2name); - bft.writeProperties("f3name="+f3name); - bft.writeProperties("f4name="+f4name); + bft.writeProperties("f2name=" + f2name); + bft.writeProperties("f3name=" + f3name); + bft.writeProperties("f4name=" + f4name); // call the target for making the files dirty bft.doTarget("modifiedselectortest-makeDirty"); @@ -737,13 +736,19 @@ public class ModifiedSelectorTest { // Mark all files which should be selected as (T)rue and all others // as (F)alse. Directories are always selected so they always are // (T)rue. - StringBuffer expected = new StringBuffer(); - for (int i=0; i selector. Used values are:
      - *
    • Cache: Propertyfile, - * cachefile={java.io.tmpdir}/mycache.txt
    • - *
    • Algorithm: Digest - * algorithm=SHA, Provider=null
    • - *
    • Comparator: java.text.RuleBasedCollator - *
    • Update: true
    • + * default value and its based on <custom> selector. Used values are: + *
      • Cache: Propertyfile, + * cachefile={java.io.tmpdir}/mycache.txt
      • + *
      • Algorithm: Digest + * algorithm=SHA, Provider=null
      • + *
      • Comparator: java.text.RuleBasedCollator
      • + *
      • Update: true
      */ @Test @Ignore("RuleBasedCollator not yet supported - see Selector:375 note") public void testScenario2() { ExtendSelector s = new ExtendSelector(); BFT bft = new BFT(); - String cachefile = System.getProperty("java.io.tmpdir")+"/mycache.txt"; + String cachefile = System.getProperty("java.io.tmpdir") + "/mycache.txt"; try { - s.setClassname("org.apache.tools.ant.types.selectors.modifiedselector.ModifiedSelector"); s.addParam(createParam("cache.cachefile", cachefile)); @@ -797,29 +803,34 @@ public class ModifiedSelectorTest { String f2name = "tar/bz2/asf-logo-huge.tar.bz2"; String f3name = "asf-logo.gif.md5"; String f4name = "copy.filterset.filtered"; - bft.writeProperties("f2name="+f2name); - bft.writeProperties("f3name="+f3name); - bft.writeProperties("f4name="+f4name); + bft.writeProperties("f2name=" + f2name); + bft.writeProperties("f3name=" + f3name); + bft.writeProperties("f4name=" + f4name); bft.doTarget("modifiedselectortest-makeDirty"); // third run String results = selectorRule.selectionString(s); - StringBuffer expected = new StringBuffer(); - for (int i=0; i5); - assertTrue("Too much files copied on second time.", to2.list().length==0); - assertTrue("Too much files copied on third time.", to3.list().length==2); + assertTrue("Not enough files copied on first time.", to1.list().length > 5); + assertTrue("Too much files copied on second time.", to2.list().length == 0); + assertTrue("Too much files copied on third time.", to3.list().length == 2); // don't catch the JUnit exceptions } finally { bft.doTarget("modifiedselectortest-scenario-clean"); @@ -934,10 +945,9 @@ public class ModifiedSelectorTest { File dir = getProject().getBaseDir(); File file = new File(dir, propfile); try { - java.io.FileWriter out = - new java.io.FileWriter(file.getAbsolutePath(), true); + FileWriter out = new FileWriter(file.getAbsolutePath(), true); out.write(line); - out.write(System.getProperty("line.separator")); + out.write(System.lineSeparator()); out.flush(); out.close(); } catch (Exception e) { @@ -946,7 +956,9 @@ public class ModifiedSelectorTest { } public void deletePropertiesfile() { - if (!isConfigured) setUp(); + if (!isConfigured) { + setUp(); + } new File(getProject().getBaseDir(), propfile).delete(); } @@ -956,8 +968,7 @@ public class ModifiedSelectorTest { cacheFile.delete(); } - }//class-BFT - + } /** * MockProject wrappes a very small ant project (one target, one task) @@ -968,7 +979,7 @@ public class ModifiedSelectorTest { private Target target; public MockProject() { - task = new Task(){ + task = new Task() { public void execute() { } }; @@ -983,22 +994,25 @@ public class ModifiedSelectorTest { public void fireBuildFinished() { super.fireBuildFinished(null); } + @SuppressWarnings("unused") public void fireSubBuildFinished() { super.fireSubBuildFinished(null); } + @SuppressWarnings("unused") public void fireTargetStarted() { super.fireTargetStarted(target); } public void fireTargetFinished() { super.fireTargetFinished(target, null); } + @SuppressWarnings("unused") public void fireTaskStarted() { super.fireTaskStarted(task); } public void fireTaskFinished() { super.fireTaskFinished(task, null); } - }//class-MockProject + } /** @@ -1026,13 +1040,9 @@ public class ModifiedSelectorTest { int length1 = expected.length(); int length2 = result.length(); int min = (length1 > length2) ? length2 : length1; - StringBuffer sb = new StringBuffer(); - for (int i=0; i filelist.length()) - ? filelist.length() - : selectorRule.getFilenames().length; - for (int i=0; i" + StringUtils.LINE_SEP, sw.toString()); diff --git a/src/tests/junit/org/apache/tools/ant/util/DateUtilsTest.java b/src/tests/junit/org/apache/tools/ant/util/DateUtilsTest.java index 4f5aa844d..e7edf2300 100644 --- a/src/tests/junit/org/apache/tools/ant/util/DateUtilsTest.java +++ b/src/tests/junit/org/apache/tools/ant/util/DateUtilsTest.java @@ -32,20 +32,20 @@ public class DateUtilsTest { @Test - public void testElapsedTime(){ - String text = DateUtils.formatElapsedTime(50*1000); + public void testElapsedTime() { + String text = DateUtils.formatElapsedTime(50 * 1000); assertEquals("50 seconds", text); - text = DateUtils.formatElapsedTime(65*1000); + text = DateUtils.formatElapsedTime(65 * 1000); assertEquals("1 minute 5 seconds", text); - text = DateUtils.formatElapsedTime(120*1000); + text = DateUtils.formatElapsedTime(120 * 1000); assertEquals("2 minutes 0 seconds", text); - text = DateUtils.formatElapsedTime(121*1000); + text = DateUtils.formatElapsedTime(121 * 1000); assertEquals("2 minutes 1 second", text); } // https://issues.apache.org/bugzilla/show_bug.cgi?id=44659 @Test - public void testLongElapsedTime(){ + public void testLongElapsedTime() { assertEquals("2926 minutes 13 seconds", DateUtils.formatElapsedTime(1000 * 175573)); assertEquals("153722867280912 minutes 55 seconds", @@ -53,7 +53,7 @@ public class DateUtilsTest { } @Test - public void testDateTimeISO(){ + public void testDateTimeISO() { TimeZone timeZone = TimeZone.getTimeZone("GMT+1"); Calendar cal = Calendar.getInstance(timeZone); cal.set(2002,1,23,10,11,12); @@ -63,7 +63,7 @@ public class DateUtilsTest { } @Test - public void testDateISO(){ + public void testDateISO() { TimeZone timeZone = TimeZone.getTimeZone("GMT"); Calendar cal = Calendar.getInstance(timeZone); cal.set(2002,1,23); @@ -73,7 +73,7 @@ public class DateUtilsTest { } @Test - public void testTimeISODate(){ + public void testTimeISODate() { // make sure that elapsed time in set via date works TimeZone timeZone = TimeZone.getTimeZone("GMT+1"); Calendar cal = Calendar.getInstance(timeZone); @@ -84,9 +84,9 @@ public class DateUtilsTest { } @Test - public void testTimeISO(){ + public void testTimeISO() { // make sure that elapsed time in ms works - long ms = (20*3600 + 11*60 + 12)*1000; + long ms = (20 * 3600 + 11 * 60 + 12) * 1000; String text = DateUtils.format(ms, DateUtils.ISO8601_TIME_PATTERN); assertEquals("20:11:12", text); diff --git a/src/tests/junit/org/apache/tools/ant/util/DeweyDecimalTest.java b/src/tests/junit/org/apache/tools/ant/util/DeweyDecimalTest.java index bcda609bd..ad1f8e0fc 100644 --- a/src/tests/junit/org/apache/tools/ant/util/DeweyDecimalTest.java +++ b/src/tests/junit/org/apache/tools/ant/util/DeweyDecimalTest.java @@ -21,41 +21,47 @@ package org.apache.tools.ant.util; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; + import org.junit.Test; -@SuppressWarnings("ResultOfObjectAllocationIgnored") public class DeweyDecimalTest { @Test public void parse() { assertEquals("1.2.3", new DeweyDecimal("1.2.3").toString()); } - @Test(expected=NumberFormatException.class) public void misparseEmpty() { + @Test(expected = NumberFormatException.class) + public void misparseEmpty() { new DeweyDecimal("1..2"); } - @Test(expected=NumberFormatException.class) public void misparseNonNumeric() { + @Test(expected = NumberFormatException.class) + public void misparseNonNumeric() { new DeweyDecimal("1.2.3-beta-5"); } - @Test(expected=NumberFormatException.class) public void misparseFinalDot() { + @Test(expected = NumberFormatException.class) + public void misparseFinalDot() { new DeweyDecimal("1.2."); } // TODO initial dots, empty string, null, negative numbers, ... - @Test public void testHashCode() { + @Test + public void testHashCode() { assertEquals(new DeweyDecimal("1.2.3").hashCode(), new DeweyDecimal("1.2.3").hashCode()); } - @Test public void testEquals() { + @Test + public void testEquals() { assertTrue(new DeweyDecimal("1.2.3").equals(new DeweyDecimal("1.2.3"))); assertFalse(new DeweyDecimal("1.2.3").equals(new DeweyDecimal("1.2.4"))); assertTrue(new DeweyDecimal("1.2.0").equals(new DeweyDecimal("1.2"))); assertTrue(new DeweyDecimal("1.2").equals(new DeweyDecimal("1.2.0"))); } - @Test public void compareTo() { + @Test + public void compareTo() { assertTrue(new DeweyDecimal("1.2.3").compareTo(new DeweyDecimal("1.2")) > 0); assertTrue(new DeweyDecimal("1.2").compareTo(new DeweyDecimal("1.2.3")) < 0); assertTrue(new DeweyDecimal("1.2.3").compareTo(new DeweyDecimal("1.2.3")) == 0); diff --git a/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java b/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java index e01665738..c52015654 100644 --- a/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java +++ b/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java @@ -44,7 +44,6 @@ public class FileUtilsTest { private File removeThis; private String root; - @Before public void setUp() { // Windows adds the drive letter in uppercase, unless you run Cygwin @@ -54,8 +53,7 @@ public class FileUtilsTest { @After public void tearDown() { if (removeThis != null && removeThis.exists()) { - if (!removeThis.delete()) - { + if (!removeThis.delete()) { removeThis.deleteOnExit(); } } @@ -69,7 +67,7 @@ public class FileUtilsTest { * behaviour and will help catch any regression in Java itself, * so is worth retaining. * @see FileUtils#setFileLastModified(java.io.File, long) - * @throws IOException + * @throws IOException if something goes wrong */ @Test public void testSetLastModified() throws IOException { @@ -87,7 +85,7 @@ public class FileUtilsTest { assertTrue(secondModTime > modTime); // number of milliseconds in a day - final int millisperday=24 * 3600 * 1000; + final int millisperday = 24 * 3600 * 1000; // in a previous version, the date of the file was set to 123456 // milliseconds since 01.01.1970 // it did not work on a computer running JDK 1.4.1_02 + Windows 2000 @@ -342,8 +340,7 @@ public class FileUtilsTest { * Test createTempFile */ @Test - public void testCreateTempFile() - { + public void testCreateTempFile() { // null parent dir File tmp1 = FILE_UTILS.createTempFile("pre", ".suf", null, false, true); String tmploc = System.getProperty("java.io.tmpdir"); @@ -476,9 +473,7 @@ public class FileUtilsTest { if (Os.isFamily("dos") || Os.isFamily("netware")) { dosRoot = System.getProperty("user.dir") .substring(0, 3).replace(File.separatorChar, '/'); - } - else - { + } else { dosRoot = ""; } if (Os.isFamily("dos")) { @@ -554,13 +549,13 @@ public class FileUtilsTest { public void testModificationTests() { //get a time - long firstTime=System.currentTimeMillis(); + long firstTime = System.currentTimeMillis(); //add some time. We assume no OS has a granularity this bad - long secondTime=firstTime+60000; -/* + long secondTime = firstTime + 60000; + /* assertTrue("same timestamp is up to date", fu.isUpToDate(firstTime, firstTime)); - */ + */ //check that older is up to date with a newer dest assertTrue("older source files are up to date", diff --git a/src/tests/junit/org/apache/tools/ant/util/JAXPUtilsTest.java b/src/tests/junit/org/apache/tools/ant/util/JAXPUtilsTest.java index 105c33d1d..7950771c9 100644 --- a/src/tests/junit/org/apache/tools/ant/util/JAXPUtilsTest.java +++ b/src/tests/junit/org/apache/tools/ant/util/JAXPUtilsTest.java @@ -29,9 +29,9 @@ import static org.junit.Assert.assertTrue; public class JAXPUtilsTest { @Test - public void testGetSystemId(){ + public void testGetSystemId() { File file = null; - if ( File.separatorChar == '\\' ){ + if (File.separatorChar == '\\') { file = new File("d:\\jdk"); } else { file = new File("/user/local/bin"); diff --git a/src/tests/junit/org/apache/tools/ant/util/JavaEnvUtilsTest.java b/src/tests/junit/org/apache/tools/ant/util/JavaEnvUtilsTest.java index a07daf2ea..28e1386cb 100644 --- a/src/tests/junit/org/apache/tools/ant/util/JavaEnvUtilsTest.java +++ b/src/tests/junit/org/apache/tools/ant/util/JavaEnvUtilsTest.java @@ -57,9 +57,9 @@ public class JavaEnvUtilsTest { String j = JavaEnvUtils.getJreExecutable("java"); assertTrue(j.endsWith(".exe")); - assertTrue(j+" is absolute", (new File(j)).isAbsolute()); + assertTrue(j + " is absolute", (new File(j)).isAbsolute()); try { - assertTrue(j+" is normalized and in the JRE dir", + assertTrue(j + " is normalized and in the JRE dir", j.startsWith(javaHome)); } catch (AssertionFailedError e) { // java.home is bogus @@ -69,12 +69,12 @@ public class JavaEnvUtilsTest { j = JavaEnvUtils.getJdkExecutable("javac"); assertTrue(j.endsWith(".exe")); try { - assertTrue(j+" is absolute", (new File(j)).isAbsolute()); + assertTrue(j + " is absolute", (new File(j)).isAbsolute()); String javaHomeParent = - FILE_UTILS.normalize(javaHome+"/..").getAbsolutePath(); - assertTrue(j+" is normalized and in the JDK dir", + FILE_UTILS.normalize(javaHome + "/..").getAbsolutePath(); + assertTrue(j + " is normalized and in the JDK dir", j.startsWith(javaHomeParent)); - assertTrue(j+" is normalized and not in the JRE dir", + assertTrue(j + " is normalized and not in the JRE dir", !j.startsWith(javaHome)); } catch (AssertionFailedError e) { @@ -101,19 +101,19 @@ public class JavaEnvUtilsTest { if (!extension.equals("")) { assertTrue(j.endsWith(extension)); } - assertTrue(j+" is absolute", (new File(j)).isAbsolute()); - assertTrue(j+" is normalized and in the JRE dir", + assertTrue(j + " is absolute", (new File(j)).isAbsolute()); + assertTrue(j + " is normalized and in the JRE dir", j.startsWith(javaHome)); j = JavaEnvUtils.getJdkExecutable("javac"); if (!extension.equals("")) { assertTrue(j.endsWith(extension)); } - assertTrue(j+" is absolute", (new File(j)).isAbsolute()); + assertTrue(j + " is absolute", (new File(j)).isAbsolute()); String javaHomeParent = - FILE_UTILS.normalize(javaHome+"/..").getAbsolutePath(); - assertTrue(j+" is normalized and in the JDK dir", + FILE_UTILS.normalize(javaHome + "/..").getAbsolutePath(); + assertTrue(j + " is normalized and in the JDK dir", j.startsWith(javaHomeParent)); if (JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_9)) { @@ -124,15 +124,14 @@ public class JavaEnvUtilsTest { !j.startsWith(javaHome)); } - assertEquals("foo"+extension, + assertEquals("foo" + extension, JavaEnvUtils.getJreExecutable("foo")); - assertEquals("foo"+extension, + assertEquals("foo" + extension, JavaEnvUtils.getJdkExecutable("foo")); } @Test - public void testIsAtLeastJavaVersion() - { + public void testIsAtLeastJavaVersion() { assertTrue( "Current java version is not at least the current java version...", JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.getJavaVersion())); diff --git a/src/tests/junit/org/apache/tools/ant/util/LayoutPreservingPropertiesTest.java b/src/tests/junit/org/apache/tools/ant/util/LayoutPreservingPropertiesTest.java index 89cd3daaa..48c52b3f9 100644 --- a/src/tests/junit/org/apache/tools/ant/util/LayoutPreservingPropertiesTest.java +++ b/src/tests/junit/org/apache/tools/ant/util/LayoutPreservingPropertiesTest.java @@ -74,7 +74,7 @@ public class LayoutPreservingPropertiesTest { lpf.setProperty(" prop one ", " leading and trailing spaces "); lpf.setProperty("prop\ttwo", "contains\ttab"); lpf.setProperty("prop\nthree", "contains\nnewline"); - lpf.setProperty("prop\rfour", "contains\rcarraige return"); + lpf.setProperty("prop\rfour", "contains\rcarriage return"); lpf.setProperty("prop\ffive", "contains\fform feed"); lpf.setProperty("prop\\six", "contains\\backslash"); lpf.setProperty("prop:seven", "contains:colon"); @@ -93,7 +93,7 @@ public class LayoutPreservingPropertiesTest { + " spaces ") > -1); assertTrue(s.indexOf("prop\\ttwo=contains\\ttab") > -1); assertTrue(s.indexOf("prop\\nthree=contains\\nnewline") > -1); - assertTrue(s.indexOf("prop\\rfour=contains\\rcarraige return") > -1); + assertTrue(s.indexOf("prop\\rfour=contains\\rcarriage return") > -1); assertTrue(s.indexOf("prop\\\\six=contains\\\\backslash") > -1); assertTrue(s.indexOf("prop\\:seven=contains\\:colon") > -1); assertTrue(s.indexOf("prop\\=eight=contains\\=equals") > -1); diff --git a/src/tests/junit/org/apache/tools/ant/util/LineOrientedOutputStreamTest.java b/src/tests/junit/org/apache/tools/ant/util/LineOrientedOutputStreamTest.java index 1fa23e849..d4b417df9 100644 --- a/src/tests/junit/org/apache/tools/ant/util/LineOrientedOutputStreamTest.java +++ b/src/tests/junit/org/apache/tools/ant/util/LineOrientedOutputStreamTest.java @@ -27,7 +27,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; - public class LineOrientedOutputStreamTest { private static String LINE = "This is a line"; @@ -61,21 +60,21 @@ public class LineOrientedOutputStreamTest { } @Test - public void testLineWithCariagereturnArray() throws IOException { + public void testLineWithCarriageReturnArray() throws IOException { writeByteArray(); writeAsArray('\r'); stream.assertInvoked(); } @Test - public void testLineWithCariagereturnSingleBytes() throws IOException { + public void testLineWithCarriageReturnSingleBytes() throws IOException { writeSingleBytes(); stream.write('\r'); stream.assertInvoked(); } @Test - public void testLineWithCariagereturnLinefeedArray() throws IOException { + public void testLineWithCarriageReturnLineFeedArray() throws IOException { writeByteArray(); writeAsArray('\r'); writeAsArray('\n'); @@ -83,7 +82,7 @@ public class LineOrientedOutputStreamTest { } @Test - public void testLineWithCariagereturnLinefeedSingleBytes() throws IOException { + public void testLineWithCarriageReturnLineFeedSingleBytes() throws IOException { writeSingleBytes(); stream.write('\r'); stream.write('\n'); @@ -125,9 +124,8 @@ public class LineOrientedOutputStreamTest { } private void writeSingleBytes() throws IOException { - byte[] b = LINE.getBytes(); - for (int i = 0; i < b.length; i++) { - stream.write(b[i]); + for (byte b : LINE.getBytes()) { + stream.write(b); } } @@ -150,4 +148,4 @@ public class LineOrientedOutputStreamTest { assertTrue("No output", !invoked); } } -}// LineOrientedOutputStreamTest +} diff --git a/src/tests/junit/org/apache/tools/ant/util/ReaderInputStreamTest.java b/src/tests/junit/org/apache/tools/ant/util/ReaderInputStreamTest.java index b31af33f1..0e4f0096a 100644 --- a/src/tests/junit/org/apache/tools/ant/util/ReaderInputStreamTest.java +++ b/src/tests/junit/org/apache/tools/ant/util/ReaderInputStreamTest.java @@ -43,6 +43,7 @@ public class ReaderInputStreamTest { compareBytes("a", "utf-16"); } + @SuppressWarnings("resource") @Test public void testSimpleAbc16() throws Exception { // THIS WILL FAIL. @@ -51,7 +52,7 @@ public class ReaderInputStreamTest { int pos = 0; ReaderInputStream r = new ReaderInputStream( new StringReader("abc"), "utf-16"); - for (int i = 0; true; ++i) { + while (true) { int res = r.read(); if (res == -1) { break; @@ -63,6 +64,7 @@ public class ReaderInputStreamTest { new String(bytes, 0, bytes.length, "utf-16"); } + @SuppressWarnings("resource") @Test public void testReadZero() throws Exception { ReaderInputStream r = new ReaderInputStream( @@ -88,7 +90,8 @@ public class ReaderInputStreamTest { ReaderInputStream r = null; FileInputStream utf8 = null; try { - fin = new InputStreamReader(new FileInputStream(new File(System.getProperty("root"), "src/tests/antunit/taskdefs/exec/input/iso8859-1")), + fin = new InputStreamReader(new FileInputStream(new File(System.getProperty("root"), + "src/tests/antunit/taskdefs/exec/input/iso8859-1")), "ISO8859_1"); r = new ReaderInputStream(fin, "UTF8"); @@ -99,7 +102,8 @@ public class ReaderInputStreamTest { b = r.read(); } - utf8 = new FileInputStream(new File(System.getProperty("root"), "src/tests/antunit/taskdefs/exec/expected/utf-8")); + utf8 = new FileInputStream(new File(System.getProperty("root"), + "src/tests/antunit/taskdefs/exec/expected/utf-8")); ByteArrayOutputStream expectedOS = new ByteArrayOutputStream(); b = utf8.read(); while (b > -1) { @@ -120,11 +124,10 @@ public class ReaderInputStreamTest { } } + @SuppressWarnings("resource") private void compareBytes(String s, String encoding) throws Exception { byte[] expected = s.getBytes(encoding); - - ReaderInputStream r = new ReaderInputStream( - new StringReader(s), encoding); + ReaderInputStream r = new ReaderInputStream(new StringReader(s), encoding); for (int i = 0; i < expected.length; ++i) { int expect = expected[i] & 0xFF; int read = r.read(); diff --git a/src/tests/junit/org/apache/tools/ant/util/ResourceUtilsTest.java b/src/tests/junit/org/apache/tools/ant/util/ResourceUtilsTest.java index 96cc9cbfc..50247b1ba 100644 --- a/src/tests/junit/org/apache/tools/ant/util/ResourceUtilsTest.java +++ b/src/tests/junit/org/apache/tools/ant/util/ResourceUtilsTest.java @@ -55,8 +55,12 @@ public class ResourceUtilsTest implements ResourceFactory, FileNameMapper { } /* ============ FileNameMapper interface ======================= */ - public void setFrom(String s) {} - public void setTo(String s) {} + public void setFrom(String s) { + } + + public void setTo(String s) { + } + public String[] mapFileName(String s) { return new String[] {"fred colon", "carrot ironfoundersson"}; } diff --git a/src/tests/junit/org/apache/tools/ant/util/StringUtilsTest.java b/src/tests/junit/org/apache/tools/ant/util/StringUtilsTest.java index cf7d9b76a..4c3220a8c 100644 --- a/src/tests/junit/org/apache/tools/ant/util/StringUtilsTest.java +++ b/src/tests/junit/org/apache/tools/ant/util/StringUtilsTest.java @@ -17,21 +17,24 @@ */ package org.apache.tools.ant.util; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + import java.util.Arrays; import java.util.Collection; import java.util.Vector; import org.junit.Test; -import static org.junit.Assert.*; - /** * Test for StringUtils */ public class StringUtilsTest { @Test - public void testSplit(){ + public void testSplit() { final String data = "a,b,,"; Vector res = StringUtils.split(data, ','); assertEquals(4, res.size()); @@ -42,7 +45,7 @@ public class StringUtilsTest { } @Test - public void testSplitLines(){ + public void testSplitLines() { final String data = "a\r\nb\nc\nd\ne"; Vector res = StringUtils.lineSplit(data); assertEquals(5, res.size()); @@ -63,42 +66,42 @@ public class StringUtilsTest { @Test public void testEndsWithBothEmpty() { - assertTrue( StringUtils.endsWith( new StringBuffer(), "") ); + assertTrue(StringUtils.endsWith(new StringBuffer(), "")); } @Test public void testEndsWithEmptyString() { - assertTrue( StringUtils.endsWith( new StringBuffer("12234545"), "") ); + assertTrue(StringUtils.endsWith(new StringBuffer("12234545"), "")); } @Test public void testEndsWithShorterString() { - assertTrue( StringUtils.endsWith( new StringBuffer("12345678"), "78")); + assertTrue(StringUtils.endsWith(new StringBuffer("12345678"), "78")); } @Test public void testEndsWithSameString() { - assertTrue( StringUtils.endsWith( new StringBuffer("123"), "123")); + assertTrue(StringUtils.endsWith(new StringBuffer("123"), "123")); } @Test public void testEndsWithLongerString() { - assertFalse( StringUtils.endsWith( new StringBuffer("12"), "1245")); + assertFalse(StringUtils.endsWith(new StringBuffer("12"), "1245")); } @Test public void testEndsWithNoMatch() { - assertFalse( StringUtils.endsWith( new StringBuffer("12345678"), "789")); + assertFalse(StringUtils.endsWith(new StringBuffer("12345678"), "789")); } @Test public void testEndsWithEmptyBuffer() { - assertFalse( StringUtils.endsWith( new StringBuffer(""), "12345667") ); + assertFalse(StringUtils.endsWith(new StringBuffer(""), "12345667")); } @Test public void testEndsWithJDKPerf() { - StringBuffer buf = getFilledBuffer(1024*300, 'a'); + StringBuffer buf = getFilledBuffer(1024 * 300, 'a'); for (int i = 0; i < 1000; i++) { assertTrue(buf.toString().endsWith("aa")); } @@ -106,7 +109,7 @@ public class StringUtilsTest { @Test public void testEndsWithPerf() { - StringBuffer buf = getFilledBuffer(1024*300, 'a'); + StringBuffer buf = getFilledBuffer(1024 * 300, 'a'); for (int i = 0; i < 1000; i++) { assertTrue(StringUtils.endsWith(buf, "aa")); } @@ -114,7 +117,9 @@ public class StringUtilsTest { private StringBuffer getFilledBuffer(int size, char ch) { StringBuffer buf = new StringBuffer(size); - for (int i = 0; i < size; i++) { buf.append(ch); }; + for (int i = 0; i < size; i++) { + buf.append(ch); + } return buf; } @@ -140,15 +145,13 @@ public class StringUtilsTest { String suffix = "Suffix"; String input = prefix + name + suffix; assertEquals( - "Does not remove the suffix right.", - prefix + name, - StringUtils.removeSuffix(input, suffix) - ); + "Does not remove the suffix right.", + prefix + name, + StringUtils.removeSuffix(input, suffix)); assertEquals( - "Should leave the string unattended.", - prefix + name + suffix, - StringUtils.removeSuffix(input, "bla") - ); + "Should leave the string unattended.", + prefix + name + suffix, + StringUtils.removeSuffix(input, "bla")); } @Test @@ -157,36 +160,32 @@ public class StringUtilsTest { String name = "Name"; String suffix = "Suffix"; String input = prefix + name + suffix; - assertEquals( - "Does not remove the prefix right.", - name + suffix, - StringUtils.removePrefix(input, prefix) - ); - assertEquals( - "Should leave the string unattended.", - prefix + name + suffix, - StringUtils.removePrefix(input, "bla") - ); + assertEquals("Does not remove the prefix right.", + name + suffix, + StringUtils.removePrefix(input, prefix)); + assertEquals("Should leave the string unattended.", + prefix + name + suffix, + StringUtils.removePrefix(input, "bla")); } - + @Test public void testJoin() { assertEquals("a, b, c", StringUtils.join(Arrays.asList("a", "b", "c"), ", ")); } - + @Test public void testJoinEmptyArray() { - assertEquals("", StringUtils.join(new String[]{}, ", ")); + assertEquals("", StringUtils.join(new String[] {}, ", ")); } - + @Test public void testJoinNullCollection() { - assertEquals("", StringUtils.join((Collection)null, ", ")); + assertEquals("", StringUtils.join((Collection) null, ", ")); } @Test public void testJoinNullArray() { - assertEquals("", StringUtils.join((String[])null, ", ")); + assertEquals("", StringUtils.join((String[]) null, ", ")); } @Test @@ -195,22 +194,22 @@ public class StringUtilsTest { } @Test - public void testTrimToNullWithNullInput(){ + public void testTrimToNullWithNullInput() { assertNull(StringUtils.trimToNull(null)); } @Test - public void testTrimToNullWithEmptyInput(){ + public void testTrimToNullWithEmptyInput() { assertNull(StringUtils.trimToNull("")); } @Test - public void testTrimToNullWithBlankSpaceInput(){ + public void testTrimToNullWithBlankSpaceInput() { assertNull(StringUtils.trimToNull(" ")); } @Test - public void testTrimToNullWithInputPaddedWithSpace(){ - assertEquals("aaBcDeF",StringUtils.trimToNull(" aaBcDeF ")); + public void testTrimToNullWithInputPaddedWithSpace() { + assertEquals("aaBcDeF", StringUtils.trimToNull(" aaBcDeF ")); } } diff --git a/src/tests/junit/org/apache/tools/ant/util/UnPackageNameMapperTest.java b/src/tests/junit/org/apache/tools/ant/util/UnPackageNameMapperTest.java index 7586950d5..c59154d52 100644 --- a/src/tests/junit/org/apache/tools/ant/util/UnPackageNameMapperTest.java +++ b/src/tests/junit/org/apache/tools/ant/util/UnPackageNameMapperTest.java @@ -29,7 +29,7 @@ public class UnPackageNameMapperTest { UnPackageNameMapper mapper = new UnPackageNameMapper(); mapper.setFrom("TEST-*.xml"); mapper.setTo("*.java"); - String file ="TEST-org.apache.tools.ant.util.UnPackageNameMapperTest.xml"; + String file = "TEST-org.apache.tools.ant.util.UnPackageNameMapperTest.xml"; String result = mapper.mapFileName(file)[0]; String expected = fixupPath("org/apache/tools/ant/util/UnPackageNameMapperTest.java"); diff --git a/src/tests/junit/org/apache/tools/ant/util/regexp/JakartaRegexpMatcherTest.java b/src/tests/junit/org/apache/tools/ant/util/regexp/JakartaRegexpMatcherTest.java index 3340b59cf..b93beb3a7 100644 --- a/src/tests/junit/org/apache/tools/ant/util/regexp/JakartaRegexpMatcherTest.java +++ b/src/tests/junit/org/apache/tools/ant/util/regexp/JakartaRegexpMatcherTest.java @@ -59,5 +59,6 @@ public class JakartaRegexpMatcherTest extends RegexpMatcherTest { /** * Fails for "default" mode. */ - protected void doEndTest2(String text) {} + protected void doEndTest2(String text) { + } } diff --git a/src/tests/junit/org/apache/tools/ant/util/regexp/JakartaRegexpRegexpTest.java b/src/tests/junit/org/apache/tools/ant/util/regexp/JakartaRegexpRegexpTest.java index 078fbb1bd..8edc13c87 100644 --- a/src/tests/junit/org/apache/tools/ant/util/regexp/JakartaRegexpRegexpTest.java +++ b/src/tests/junit/org/apache/tools/ant/util/regexp/JakartaRegexpRegexpTest.java @@ -40,7 +40,7 @@ public class JakartaRegexpRegexpTest extends RegexpTest { try { super.testWindowsLineSeparator2(); fail("Should trigger when this bug is fixed. {@since 1.2}"); - } catch (AssertionFailedError e){ + } catch (AssertionFailedError e) { } } @@ -51,12 +51,13 @@ public class JakartaRegexpRegexpTest extends RegexpTest { try { super.testUnixLineSeparator(); fail("Should trigger once this bug is fixed. {@since 1.2}"); - } catch (AssertionFailedError e){ + } catch (AssertionFailedError e) { } } /** * Fails for "default" mode. */ - protected void doEndTest2(String text) {} + protected void doEndTest2(String text) { + } } diff --git a/src/tests/junit/org/apache/tools/ant/util/regexp/Jdk14RegexpMatcherTest.java b/src/tests/junit/org/apache/tools/ant/util/regexp/Jdk14RegexpMatcherTest.java index c042e7157..40f6dcaf5 100644 --- a/src/tests/junit/org/apache/tools/ant/util/regexp/Jdk14RegexpMatcherTest.java +++ b/src/tests/junit/org/apache/tools/ant/util/regexp/Jdk14RegexpMatcherTest.java @@ -40,7 +40,7 @@ public class Jdk14RegexpMatcherTest extends RegexpMatcherTest { try { super.testParagraphCharacter(); fail("Should trigger once fixed. {@since JDK 1.4RC1}"); - } catch (AssertionFailedError e){ + } catch (AssertionFailedError e) { } } @@ -48,7 +48,7 @@ public class Jdk14RegexpMatcherTest extends RegexpMatcherTest { try { super.testLineSeparatorCharacter(); fail("Should trigger once fixed. {@since JDK 1.4RC1}"); - } catch (AssertionFailedError e){ + } catch (AssertionFailedError e) { } } @@ -56,7 +56,7 @@ public class Jdk14RegexpMatcherTest extends RegexpMatcherTest { try { super.testStandaloneCR(); fail("Should trigger once fixed. {@since JDK 1.4RC1}"); - } catch (AssertionFailedError e){ + } catch (AssertionFailedError e) { } } @@ -64,7 +64,7 @@ public class Jdk14RegexpMatcherTest extends RegexpMatcherTest { try { super.testWindowsLineSeparator(); fail("Should trigger once fixed. {@since JDK 1.4RC1}"); - } catch (AssertionFailedError e){ + } catch (AssertionFailedError e) { } } } diff --git a/src/tests/junit/org/apache/tools/ant/util/regexp/Jdk14RegexpRegexpTest.java b/src/tests/junit/org/apache/tools/ant/util/regexp/Jdk14RegexpRegexpTest.java index 2b60406a3..5f5342ea8 100644 --- a/src/tests/junit/org/apache/tools/ant/util/regexp/Jdk14RegexpRegexpTest.java +++ b/src/tests/junit/org/apache/tools/ant/util/regexp/Jdk14RegexpRegexpTest.java @@ -40,7 +40,7 @@ public class Jdk14RegexpRegexpTest extends RegexpTest { try { super.testParagraphCharacter(); fail("Should trigger once fixed. {@since JDK 1.4RC1}"); - } catch (AssertionFailedError e){ + } catch (AssertionFailedError e) { } } @@ -48,7 +48,7 @@ public class Jdk14RegexpRegexpTest extends RegexpTest { try { super.testLineSeparatorCharacter(); fail("Should trigger once fixed. {@since JDK 1.4RC1}"); - } catch (AssertionFailedError e){ + } catch (AssertionFailedError e) { } } @@ -56,7 +56,7 @@ public class Jdk14RegexpRegexpTest extends RegexpTest { try { super.testStandaloneCR(); fail("Should trigger once fixed. {@since JDK 1.4RC1}"); - } catch (AssertionFailedError e){ + } catch (AssertionFailedError e) { } } @@ -64,7 +64,7 @@ public class Jdk14RegexpRegexpTest extends RegexpTest { try { super.testWindowsLineSeparator(); fail("Should trigger once fixed. {@since JDK 1.4RC1}"); - } catch (AssertionFailedError e){ + } catch (AssertionFailedError e) { } } diff --git a/src/tests/junit/org/apache/tools/ant/util/regexp/RegexpMatcherTest.java b/src/tests/junit/org/apache/tools/ant/util/regexp/RegexpMatcherTest.java index 095082740..3129e68e3 100644 --- a/src/tests/junit/org/apache/tools/ant/util/regexp/RegexpMatcherTest.java +++ b/src/tests/junit/org/apache/tools/ant/util/regexp/RegexpMatcherTest.java @@ -35,7 +35,9 @@ public abstract class RegexpMatcherTest extends TestCase { public abstract RegexpMatcher getImplementation(); - protected final RegexpMatcher getReg() {return reg;} + protected final RegexpMatcher getReg() { + return reg; + } public RegexpMatcherTest(String name) { super(name); @@ -152,7 +154,7 @@ public abstract class RegexpMatcherTest extends TestCase { public void testMultiVersusSingleLine() throws IOException { - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); buf.append("Line1").append(UNIX_LINE); buf.append("starttest Line2").append(UNIX_LINE); buf.append("Line3 endtest").append(UNIX_LINE); diff --git a/src/tests/junit/org/apache/tools/bzip2/CBZip2StreamTest.java b/src/tests/junit/org/apache/tools/bzip2/CBZip2StreamTest.java index 50e0e576b..88b500a86 100644 --- a/src/tests/junit/org/apache/tools/bzip2/CBZip2StreamTest.java +++ b/src/tests/junit/org/apache/tools/bzip2/CBZip2StreamTest.java @@ -27,6 +27,7 @@ import static org.junit.Assert.fail; public class CBZip2StreamTest { + @SuppressWarnings("resource") @Test public void testNullPointer() throws IOException { try { diff --git a/src/tests/junit/org/apache/tools/mail/MailMessageTest.java b/src/tests/junit/org/apache/tools/mail/MailMessageTest.java index 435729e47..3d7582640 100644 --- a/src/tests/junit/org/apache/tools/mail/MailMessageTest.java +++ b/src/tests/junit/org/apache/tools/mail/MailMessageTest.java @@ -65,7 +65,7 @@ public class MailMessageTest { * If this testcase takes >90s to complete, it is very likely that * the two threads are blocked waiting for each other and Thread.join() * timed out. - * @throws InterruptedException + * @throws InterruptedException if something goes wrong */ @Test public void testAPIExample() throws InterruptedException { @@ -82,8 +82,8 @@ public class MailMessageTest { testMailClient.cc("cc2@you.com"); testMailClient.bcc("bcc@you.com"); testMailClient.setSubject("Test subject"); - testMailClient.setMessage( "test line 1\n" + - "test line 2" ); + testMailClient.setMessage("test line 1\n" + + "test line 2"); Thread client = new Thread(testMailClient); client.start(); @@ -144,7 +144,7 @@ public class MailMessageTest { /** * Test a MailMessage with no cc or bcc lines - * @throws InterruptedException + * @throws InterruptedException if something goes wrong */ @Test public void testToOnly() throws InterruptedException { @@ -157,8 +157,8 @@ public class MailMessageTest { testMailClient.from("Mail Message "); testMailClient.to("to@you.com"); testMailClient.setSubject("Test subject"); - testMailClient.setMessage( "test line 1\n" + - "test line 2" ); + testMailClient.setMessage("test line 1\n" + + "test line 2"); Thread client = new Thread(testMailClient); client.start(); @@ -196,7 +196,7 @@ public class MailMessageTest { /** * Test a MailMessage with no to or bcc lines - * @throws InterruptedException + * @throws InterruptedException if something goes wrong */ @Test public void testCcOnly() throws InterruptedException { @@ -209,8 +209,8 @@ public class MailMessageTest { testMailClient.from("Mail Message "); testMailClient.cc("cc@you.com"); testMailClient.setSubject("Test subject"); - testMailClient.setMessage( "test line 1\n" + - "test line 2" ); + testMailClient.setMessage("test line 1\n" + + "test line 2"); Thread client = new Thread(testMailClient); client.start(); @@ -248,7 +248,7 @@ public class MailMessageTest { /** * Test a MailMessage with no to or cc lines - * @throws InterruptedException + * @throws InterruptedException if something goes wrong */ @Test public void testBccOnly() throws InterruptedException { @@ -261,8 +261,8 @@ public class MailMessageTest { testMailClient.from("Mail Message "); testMailClient.bcc("bcc@you.com"); testMailClient.setSubject("Test subject"); - testMailClient.setMessage( "test line 1\n" + - "test line 2" ); + testMailClient.setMessage("test line 1\n" + + "test line 2"); Thread client = new Thread(testMailClient); client.start(); @@ -291,8 +291,8 @@ public class MailMessageTest { "250\r\n" + "QUIT\r\n" + "221\r\n"; - assertEquals( expectedResult.length(), result.length() ); - assertEquals( expectedResult, result ); + assertEquals(expectedResult.length(), result.length()); + assertEquals(expectedResult, result); assertFalse(testMailClient.getFailMessage(), testMailClient.isFailed()); } @@ -300,7 +300,7 @@ public class MailMessageTest { /** * Test a MailMessage with no subject line * Subject is an optional field (RFC 822 s4.1) - * @throws InterruptedException + * @throws InterruptedException if something goes wrong */ @Test public void testNoSubject() throws InterruptedException { @@ -312,8 +312,8 @@ public class MailMessageTest { testMailClient.from("Mail Message "); testMailClient.to("to@you.com"); - testMailClient.setMessage( "test line 1\n" + - "test line 2" ); + testMailClient.setMessage("test line 1\n" + + "test line 2"); Thread client = new Thread(testMailClient); client.start(); @@ -342,15 +342,15 @@ public class MailMessageTest { "250\r\n" + "QUIT\r\n" + "221\r\n"; - assertEquals( expectedResult.length(), result.length() ); - assertEquals( expectedResult, result ); + assertEquals(expectedResult.length(), result.length()); + assertEquals(expectedResult, result); assertFalse(testMailClient.getFailMessage(), testMailClient.isFailed()); } /** * Test a MailMessage with empty body message - * @throws InterruptedException + * @throws InterruptedException if something goes wrong */ @Test public void testEmptyBody() throws InterruptedException { @@ -402,7 +402,7 @@ public class MailMessageTest { * Test a MailMessage with US-ASCII character set * The next four testcase can be kinda hard to debug as Ant will often * print the junit failure in US-ASCII. - * @throws InterruptedException + * @throws InterruptedException if something goes wrong */ @Test public void testAsciiCharset() throws InterruptedException { @@ -453,22 +453,20 @@ public class MailMessageTest { bos1.print(expectedResult); bos2.print(result); - assertEquals( "expected message length != actual message length " - + "in testAsciiCharset()", expectedResult.length(), result.length() ); - assertEquals( "baos1 and baos2 should be the same in testAsciiCharset()", - baos1.toString(), baos2.toString() ); // order of headers cannot be guaranteed + assertEquals("expected message length != actual message length " + + "in testAsciiCharset()", expectedResult.length(), result.length()); + assertEquals("baos1 and baos2 should be the same in testAsciiCharset()", + baos1.toString(), baos2.toString()); // order of headers cannot be guaranteed assertFalse(testMailClient.getFailMessage(), testMailClient.isFailed()); } - - /** * A private test class that pretends to be a mail transfer agent */ private class ServerThread implements Runnable { - private StringBuffer sb = null; + private StringBuilder sb = null; private boolean loop = false; ServerSocket ssock = null; Socket sock = null; @@ -481,45 +479,45 @@ public class MailMessageTest { try { ssock = new ServerSocket(TEST_PORT); sock = ssock.accept(); // wait for connection - in = new BufferedReader( new InputStreamReader( - sock.getInputStream()) ); - out = new BufferedWriter( new OutputStreamWriter( - sock.getOutputStream() ) ); - sb = new StringBuffer(); - send( "220 test SMTP EmailTaskTest\r\n" ); + in = new BufferedReader(new InputStreamReader( + sock.getInputStream())); + out = new BufferedWriter(new OutputStreamWriter( + sock.getOutputStream())); + sb = new StringBuilder(); + send("220 test SMTP EmailTaskTest\r\n"); loop = true; - while ( loop ) { + while (loop) { String response = in.readLine(); - if ( response == null ) { + if (response == null) { loop = false; break; } - sb.append( response + "\r\n" ); - - if ( !data && response.startsWith( "HELO" ) ) { - send( "250 " + local + " Hello " + local + " " + - "[127.0.0.1], pleased to meet you\r\n" ); - } else if ( !data && response.startsWith("MAIL") ) { - send( "250\r\n" ); - } else if ( !data && response.startsWith("RCPT")) { - send( "250\r\n" ); + sb.append(response).append("\r\n"); + + if (!data && response.startsWith("HELO")) { + send("250 " + local + " Hello " + local + " " + + "[127.0.0.1], pleased to meet you\r\n"); + } else if (!data && response.startsWith("MAIL")) { + send("250\r\n"); + } else if (!data && response.startsWith("RCPT")) { + send("250\r\n"); } else if (!data && response.startsWith("DATA")) { - send( "354\r\n" ); + send("354\r\n"); data = true; - } else if (data && response.equals(".") ) { - send( "250\r\n" ); + } else if (data && response.equals(".")) { + send("250\r\n"); data = false; } else if (!data && response.startsWith("QUIT")) { - send( "221\r\n" ); + send("221\r\n"); loop = false; } else if (!data) { //throw new IllegalStateException("Command unrecognized: " // + response); - send( "500 5.5.1 Command unrecognized: \"" + - response + "\"\r\n" ); + send("500 5.5.1 Command unrecognized: \"" + + response + "\"\r\n"); loop = false; } else { - // sb.append( response + "\r\n" ); + // sb.append(response + "\r\n"); } } // while @@ -531,9 +529,9 @@ public class MailMessageTest { } private void send(String retmsg) throws IOException { - out.write( retmsg ); + out.write(retmsg); out.flush(); - sb.append( retmsg ); + sb.append(retmsg); } private void disconnect() { @@ -653,9 +651,9 @@ public class MailMessageTest { msg.setSubject(subject); } - if (message != null ) { + if (message != null) { PrintStream out = msg.getPrintStream(); - out.println( message ); + out.println(message); } msg.sendAndClose(); @@ -674,6 +672,7 @@ public class MailMessageTest { return failMessage; } + @SuppressWarnings("unused") public void replyTo(String replyTo) { replyToList.add(replyTo); } diff --git a/src/tests/junit/org/apache/tools/tar/TarEntryTest.java b/src/tests/junit/org/apache/tools/tar/TarEntryTest.java index e942cdb3a..f5c20208f 100644 --- a/src/tests/junit/org/apache/tools/tar/TarEntryTest.java +++ b/src/tests/junit/org/apache/tools/tar/TarEntryTest.java @@ -18,6 +18,8 @@ package org.apache.tools.tar; +import java.io.File; + import org.junit.Test; /** @@ -30,6 +32,6 @@ public class TarEntryTest { */ @Test public void testFileConstructor() { - new TarEntry(new java.io.File("/foo")); + new TarEntry(new File("/foo")); } } diff --git a/src/tests/junit/org/apache/tools/zip/AsiExtraFieldTest.java b/src/tests/junit/org/apache/tools/zip/AsiExtraFieldTest.java index 873b3f50d..c62e3e18a 100644 --- a/src/tests/junit/org/apache/tools/zip/AsiExtraFieldTest.java +++ b/src/tests/junit/org/apache/tools/zip/AsiExtraFieldTest.java @@ -62,8 +62,8 @@ public class AsiExtraFieldTest implements UnixStat { 0, 0, 0, 0, // link length 5, 0, 6, 0}; // uid, gid assertEquals("no link", expect.length, b.length); - for (int i=0; i