Browse Source

use StringUtils and FileUtils where possible

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@375172 13f79535-47bb-0310-9956-ffa450edef68
master
Kevin Jackson 19 years ago
parent
commit
789c3b0316
2 changed files with 26 additions and 31 deletions
  1. +13
    -16
      src/main/org/apache/tools/ant/taskdefs/optional/junit/BriefJUnitResultFormatter.java
  2. +13
    -15
      src/main/org/apache/tools/ant/taskdefs/optional/junit/PlainJUnitResultFormatter.java

+ 13
- 16
src/main/org/apache/tools/ant/taskdefs/optional/junit/BriefJUnitResultFormatter.java View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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; package org.apache.tools.ant.taskdefs.optional.junit;


import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
import java.text.NumberFormat; import java.text.NumberFormat;

import junit.framework.AssertionFailedError; import junit.framework.AssertionFailedError;
import junit.framework.Test; 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. * Prints plain text output of the test to a specified Writer.
* Inspired by the PlainJUnitResultFormatter. * Inspired by the PlainJUnitResultFormatter.
@@ -109,10 +112,9 @@ public class BriefJUnitResultFormatter implements JUnitResultFormatter {
if (output == null) { if (output == null) {
return; // Quick return - no output do nothing. return; // Quick return - no output do nothing.
} }
String newLine = System.getProperty("line.separator");
StringBuffer sb = new StringBuffer("Testsuite: "); StringBuffer sb = new StringBuffer("Testsuite: ");
sb.append(suite.getName()); sb.append(suite.getName());
sb.append(newLine);
sb.append(StringUtils.LINE_SEP);
output.write(sb.toString()); output.write(sb.toString());
output.flush(); output.flush();
} }
@@ -122,7 +124,6 @@ public class BriefJUnitResultFormatter implements JUnitResultFormatter {
* @param suite the test suite * @param suite the test suite
*/ */
public void endTestSuite(JUnitTest suite) { public void endTestSuite(JUnitTest suite) {
String newLine = System.getProperty("line.separator");
StringBuffer sb = new StringBuffer("Tests run: "); StringBuffer sb = new StringBuffer("Tests run: ");
sb.append(suite.runCount()); sb.append(suite.runCount());
sb.append(", Failures: "); sb.append(", Failures: ");
@@ -132,24 +133,24 @@ public class BriefJUnitResultFormatter implements JUnitResultFormatter {
sb.append(", Time elapsed: "); sb.append(", Time elapsed: ");
sb.append(numberFormat.format(suite.getRunTime() / 1000.0)); sb.append(numberFormat.format(suite.getRunTime() / 1000.0));
sb.append(" sec"); 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 // append the err and output streams to the log
if (systemOutput != null && systemOutput.length() > 0) { if (systemOutput != null && systemOutput.length() > 0) {
sb.append("------------- Standard Output ---------------") sb.append("------------- Standard Output ---------------")
.append(newLine)
.append(StringUtils.LINE_SEP)
.append(systemOutput) .append(systemOutput)
.append("------------- ---------------- ---------------") .append("------------- ---------------- ---------------")
.append(newLine);
.append(StringUtils.LINE_SEP);
} }


if (systemError != null && systemError.length() > 0) { if (systemError != null && systemError.length() > 0) {
sb.append("------------- Standard Error -----------------") sb.append("------------- Standard Error -----------------")
.append(newLine)
.append(StringUtils.LINE_SEP)
.append(systemError) .append(systemError)
.append("------------- ---------------- ---------------") .append("------------- ---------------- ---------------")
.append(newLine);
.append(StringUtils.LINE_SEP);
} }


if (output != null) { if (output != null) {
@@ -160,11 +161,7 @@ public class BriefJUnitResultFormatter implements JUnitResultFormatter {
output.flush(); output.flush();
} finally { } finally {
if (out != System.out && out != System.err) { if (out != System.out && out != System.err) {
try {
out.close();
} catch (IOException e) {
// ignore
}
FileUtils.close(out);
} }
} }
} }


+ 13
- 15
src/main/org/apache/tools/ant/taskdefs/optional/junit/PlainJUnitResultFormatter.java View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.io.StringWriter;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.util.Hashtable; import java.util.Hashtable;

import junit.framework.AssertionFailedError; import junit.framework.AssertionFailedError;
import junit.framework.Test; import junit.framework.Test;

import org.apache.tools.ant.BuildException; 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) { if (out == null) {
return; // Quick return - no output do nothing. return; // Quick return - no output do nothing.
} }
String newLine = System.getProperty("line.separator");
StringBuffer sb = new StringBuffer("Testsuite: "); StringBuffer sb = new StringBuffer("Testsuite: ");
sb.append(suite.getName()); sb.append(suite.getName());
sb.append(newLine);
sb.append(StringUtils.LINE_SEP);
try { try {
out.write(sb.toString().getBytes()); out.write(sb.toString().getBytes());
out.flush(); out.flush();
@@ -107,7 +110,6 @@ public class PlainJUnitResultFormatter implements JUnitResultFormatter {
* @throws BuildException if unable to write the output * @throws BuildException if unable to write the output
*/ */
public void endTestSuite(JUnitTest suite) throws BuildException { public void endTestSuite(JUnitTest suite) throws BuildException {
String newLine = System.getProperty("line.separator");
StringBuffer sb = new StringBuffer("Tests run: "); StringBuffer sb = new StringBuffer("Tests run: ");
sb.append(suite.runCount()); sb.append(suite.runCount());
sb.append(", Failures: "); sb.append(", Failures: ");
@@ -117,26 +119,26 @@ public class PlainJUnitResultFormatter implements JUnitResultFormatter {
sb.append(", Time elapsed: "); sb.append(", Time elapsed: ");
sb.append(nf.format(suite.getRunTime() / 1000.0)); sb.append(nf.format(suite.getRunTime() / 1000.0));
sb.append(" sec"); sb.append(" sec");
sb.append(newLine);
sb.append(StringUtils.LINE_SEP);


// append the err and output streams to the log // append the err and output streams to the log
if (systemOutput != null && systemOutput.length() > 0) { if (systemOutput != null && systemOutput.length() > 0) {
sb.append("------------- Standard Output ---------------") sb.append("------------- Standard Output ---------------")
.append(newLine)
.append(StringUtils.LINE_SEP)
.append(systemOutput) .append(systemOutput)
.append("------------- ---------------- ---------------") .append("------------- ---------------- ---------------")
.append(newLine);
.append(StringUtils.LINE_SEP);
} }


if (systemError != null && systemError.length() > 0) { if (systemError != null && systemError.length() > 0) {
sb.append("------------- Standard Error -----------------") sb.append("------------- Standard Error -----------------")
.append(newLine)
.append(StringUtils.LINE_SEP)
.append(systemError) .append(systemError)
.append("------------- ---------------- ---------------") .append("------------- ---------------- ---------------")
.append(newLine);
.append(StringUtils.LINE_SEP);
} }


sb.append(newLine);
sb.append(StringUtils.LINE_SEP);


if (out != null) { if (out != null) {
try { try {
@@ -148,11 +150,7 @@ public class PlainJUnitResultFormatter implements JUnitResultFormatter {
throw new BuildException("Unable to write output", ioex); throw new BuildException("Unable to write output", ioex);
} finally { } finally {
if (out != System.out && out != System.err) { if (out != System.out && out != System.err) {
try {
out.close();
} catch (IOException e) {
// ignore
}
FileUtils.close(out);
} }
} }
} }


Loading…
Cancel
Save