Browse Source

- Enforce coding guidelines.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270672 13f79535-47bb-0310-9956-ffa450edef68
master
Stephane Bailliez 23 years ago
parent
commit
33db84490c
1 changed files with 57 additions and 54 deletions
  1. +57
    -54
      src/main/org/apache/tools/ant/taskdefs/optional/junit/BriefJUnitResultFormatter.java

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

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
* Copyright (c) 2001 The Apache Software Foundation. All rights
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -54,10 +54,16 @@


package org.apache.tools.ant.taskdefs.optional.junit; package org.apache.tools.ant.taskdefs.optional.junit;


import org.apache.tools.ant.BuildException;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.text.NumberFormat;


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

import org.apache.tools.ant.BuildException;


/** /**
* Prints plain text output of the test to a specified Writer. * Prints plain text output of the test to a specified Writer.
@@ -69,32 +75,32 @@ import junit.framework.AssertionFailedError;
* @see PlainJUnitResultFormatter * @see PlainJUnitResultFormatter
*/ */
public class BriefJUnitResultFormatter implements JUnitResultFormatter { public class BriefJUnitResultFormatter implements JUnitResultFormatter {
/** /**
* Where to write the log to. * Where to write the log to.
*/ */
private java.io.OutputStream m_out;
private OutputStream out;


/** /**
* Used for writing the results. * Used for writing the results.
*/ */
private java.io.PrintWriter m_output;
private PrintWriter output;
/** /**
* Used as part of formatting the results. * Used as part of formatting the results.
*/ */
private java.io.StringWriter m_results;
private StringWriter results;


/** /**
* Used for writing formatted results to. * Used for writing formatted results to.
*/ */
private java.io.PrintWriter m_resultWriter;
private PrintWriter resultWriter;
/** /**
* Formatter for timings. * Formatter for timings.
*/ */
private java.text.NumberFormat m_numberFormat = java.text.NumberFormat.getInstance();
private NumberFormat numberFormat = NumberFormat.getInstance();
/** /**
* Output suite has written to System.out * Output suite has written to System.out
*/ */
@@ -106,18 +112,18 @@ public class BriefJUnitResultFormatter implements JUnitResultFormatter {
private String systemError = null; private String systemError = null;


public BriefJUnitResultFormatter() { public BriefJUnitResultFormatter() {
m_results = new java.io.StringWriter();
m_resultWriter = new java.io.PrintWriter(m_results);
results = new StringWriter();
resultWriter = new PrintWriter(results);
} }
/** /**
* Sets the stream the formatter is supposed to write its results to. * Sets the stream the formatter is supposed to write its results to.
*/ */
public void setOutput(java.io.OutputStream out) {
m_out = out;
m_output = new java.io.PrintWriter(out);
public void setOutput(OutputStream out) {
this.out = out;
output = new PrintWriter(out);
} }
public void setSystemOutput(String out) { public void setSystemOutput(String out) {
systemOutput = out; systemOutput = out;
} }
@@ -126,10 +132,7 @@ public class BriefJUnitResultFormatter implements JUnitResultFormatter {
systemError = err; systemError = err;
} }


protected java.io.PrintWriter output() { return m_output; }
protected java.io.PrintWriter resultWriter() { return m_resultWriter; }

/** /**
* The whole testsuite started. * The whole testsuite started.
*/ */
@@ -151,51 +154,52 @@ public class BriefJUnitResultFormatter implements JUnitResultFormatter {
sb.append(", Errors: "); sb.append(", Errors: ");
sb.append(suite.errorCount()); sb.append(suite.errorCount());
sb.append(", Time elapsed: "); sb.append(", Time elapsed: ");
sb.append(m_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(newLine); sb.append(newLine);


// 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 ---------------" )
.append(newLine)
.append(systemOutput)
.append("------------- ---------------- ---------------" )
.append(newLine);
sb.append("------------- Standard Output ---------------")
.append(newLine)
.append(systemOutput)
.append("------------- ---------------- ---------------")
.append(newLine);
} }
if (systemError != null && systemError.length() > 0) { if (systemError != null && systemError.length() > 0) {
sb.append("------------- Standard Error -----------------" )
.append(newLine)
.append(systemError)
.append("------------- ---------------- ---------------" )
.append(newLine);
sb.append("------------- Standard Error -----------------")
.append(newLine)
.append(systemError)
.append("------------- ---------------- ---------------")
.append(newLine);
} }


if ( output() != null) {
if (output != null) {
try { try {
output().write(sb.toString());
resultWriter().close();
output().write(m_results.toString());
output().flush();
output.write(sb.toString());
resultWriter.close();
output.write(results.toString());
output.flush();
} finally { } finally {
if (m_out != (Object)System.out &&
m_out != (Object)System.err) {
if (out != System.out &&
out != System.err) {
try { try {
m_out.close();
} catch (java.io.IOException e) {}
out.close();
} catch (IOException e) {
}
} }
} }
} }
} }
/** /**
* A test started. * A test started.
*/ */
public void startTest(Test test) { public void startTest(Test test) {
} }
/** /**
* A test ended. * A test ended.
*/ */
@@ -226,15 +230,14 @@ public class BriefJUnitResultFormatter implements JUnitResultFormatter {
public void addError(Test test, Throwable error) { public void addError(Test test, Throwable error) {
formatError("\tCaused an ERROR", test, error); formatError("\tCaused an ERROR", test, error);
} }
/** /**
* Format the test for printing.. * Format the test for printing..
*/ */
protected String formatTest(Test test) { protected String formatTest(Test test) {
if (test == null) { if (test == null) {
return "Null Test: "; return "Null Test: ";
}
else {
} else {
return "Testcase: " + test.toString() + ":"; return "Testcase: " + test.toString() + ":";
} }
} }
@@ -242,16 +245,16 @@ public class BriefJUnitResultFormatter implements JUnitResultFormatter {
/** /**
* Format an error and print it. * Format an error and print it.
*/ */
protected synchronized void formatError(String type, Test test,
protected synchronized void formatError(String type, Test test,
Throwable error) { Throwable error) {
if (test != null) { if (test != null) {
endTest(test); endTest(test);
} }


resultWriter().println(formatTest(test) + type);
resultWriter().println(error.getMessage());
resultWriter.println(formatTest(test) + type);
resultWriter.println(error.getMessage());
String strace = JUnitTestRunner.getFilteredTrace(error); String strace = JUnitTestRunner.getFilteredTrace(error);
resultWriter().println(strace);
resultWriter().println("");
resultWriter.println(strace);
resultWriter.println();
} }
} }

Loading…
Cancel
Save