diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/BriefJUnitResultFormatter.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/BriefJUnitResultFormatter.java index a75bfd1e1..5f3ae2204 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/BriefJUnitResultFormatter.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/BriefJUnitResultFormatter.java @@ -1,5 +1,5 @@ /* - * Copyright 2001-2002,2004-2005 The Apache Software Foundation + * Copyright 2001-2002,2004-2006 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,14 +17,17 @@ package org.apache.tools.ant.taskdefs.optional.junit; -import java.io.IOException; import java.io.OutputStream; import java.io.PrintWriter; import java.io.StringWriter; import java.text.NumberFormat; + import junit.framework.AssertionFailedError; import junit.framework.Test; +import org.apache.tools.ant.util.FileUtils; +import org.apache.tools.ant.util.StringUtils; + /** * Prints plain text output of the test to a specified Writer. * Inspired by the PlainJUnitResultFormatter. @@ -109,10 +112,9 @@ public class BriefJUnitResultFormatter implements JUnitResultFormatter { if (output == null) { return; // Quick return - no output do nothing. } - String newLine = System.getProperty("line.separator"); StringBuffer sb = new StringBuffer("Testsuite: "); sb.append(suite.getName()); - sb.append(newLine); + sb.append(StringUtils.LINE_SEP); output.write(sb.toString()); output.flush(); } @@ -122,7 +124,6 @@ public class BriefJUnitResultFormatter implements JUnitResultFormatter { * @param suite the test suite */ public void endTestSuite(JUnitTest suite) { - String newLine = System.getProperty("line.separator"); StringBuffer sb = new StringBuffer("Tests run: "); sb.append(suite.runCount()); sb.append(", Failures: "); @@ -132,24 +133,24 @@ public class BriefJUnitResultFormatter implements JUnitResultFormatter { sb.append(", Time elapsed: "); sb.append(numberFormat.format(suite.getRunTime() / 1000.0)); sb.append(" sec"); - sb.append(newLine); - sb.append(newLine); + sb.append(StringUtils.LINE_SEP); + sb.append(StringUtils.LINE_SEP); // append the err and output streams to the log if (systemOutput != null && systemOutput.length() > 0) { sb.append("------------- Standard Output ---------------") - .append(newLine) + .append(StringUtils.LINE_SEP) .append(systemOutput) .append("------------- ---------------- ---------------") - .append(newLine); + .append(StringUtils.LINE_SEP); } if (systemError != null && systemError.length() > 0) { sb.append("------------- Standard Error -----------------") - .append(newLine) + .append(StringUtils.LINE_SEP) .append(systemError) .append("------------- ---------------- ---------------") - .append(newLine); + .append(StringUtils.LINE_SEP); } if (output != null) { @@ -160,11 +161,7 @@ public class BriefJUnitResultFormatter implements JUnitResultFormatter { output.flush(); } finally { if (out != System.out && out != System.err) { - try { - out.close(); - } catch (IOException e) { - // ignore - } + FileUtils.close(out); } } } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/PlainJUnitResultFormatter.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/PlainJUnitResultFormatter.java index ffcc8aab2..8a1a05d0b 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/PlainJUnitResultFormatter.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/PlainJUnitResultFormatter.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2004 The Apache Software Foundation + * Copyright 2000-2006 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,9 +23,13 @@ import java.io.PrintWriter; import java.io.StringWriter; import java.text.NumberFormat; import java.util.Hashtable; + import junit.framework.AssertionFailedError; import junit.framework.Test; + import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.util.FileUtils; +import org.apache.tools.ant.util.StringUtils; /** @@ -89,10 +93,9 @@ public class PlainJUnitResultFormatter implements JUnitResultFormatter { if (out == null) { return; // Quick return - no output do nothing. } - String newLine = System.getProperty("line.separator"); StringBuffer sb = new StringBuffer("Testsuite: "); sb.append(suite.getName()); - sb.append(newLine); + sb.append(StringUtils.LINE_SEP); try { out.write(sb.toString().getBytes()); out.flush(); @@ -107,7 +110,6 @@ public class PlainJUnitResultFormatter implements JUnitResultFormatter { * @throws BuildException if unable to write the output */ public void endTestSuite(JUnitTest suite) throws BuildException { - String newLine = System.getProperty("line.separator"); StringBuffer sb = new StringBuffer("Tests run: "); sb.append(suite.runCount()); sb.append(", Failures: "); @@ -117,26 +119,26 @@ public class PlainJUnitResultFormatter implements JUnitResultFormatter { sb.append(", Time elapsed: "); sb.append(nf.format(suite.getRunTime() / 1000.0)); sb.append(" sec"); - sb.append(newLine); + sb.append(StringUtils.LINE_SEP); // append the err and output streams to the log if (systemOutput != null && systemOutput.length() > 0) { sb.append("------------- Standard Output ---------------") - .append(newLine) + .append(StringUtils.LINE_SEP) .append(systemOutput) .append("------------- ---------------- ---------------") - .append(newLine); + .append(StringUtils.LINE_SEP); } if (systemError != null && systemError.length() > 0) { sb.append("------------- Standard Error -----------------") - .append(newLine) + .append(StringUtils.LINE_SEP) .append(systemError) .append("------------- ---------------- ---------------") - .append(newLine); + .append(StringUtils.LINE_SEP); } - sb.append(newLine); + sb.append(StringUtils.LINE_SEP); if (out != null) { try { @@ -148,11 +150,7 @@ public class PlainJUnitResultFormatter implements JUnitResultFormatter { throw new BuildException("Unable to write output", ioex); } finally { if (out != System.out && out != System.err) { - try { - out.close(); - } catch (IOException e) { - // ignore - } + FileUtils.close(out); } } }