Browse Source

make huge method in a number of methods

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@566726 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 18 years ago
parent
commit
1266e53bd1
1 changed files with 43 additions and 44 deletions
  1. +43
    -44
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java

+ 43
- 44
src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java View File

@@ -262,42 +262,32 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
} }


private PrintStream savedOut = null; private PrintStream savedOut = null;
private PrintStream savedErr = null;


/**
* Run the test.
*/
public void run() {
res = new TestResult();
res.addListener(wrapListener(this));
for (int i = 0; i < formatters.size(); i++) {
res.addListener(wrapListener((TestListener) formatters.elementAt(i)));
}

ByteArrayOutputStream errStrm = new ByteArrayOutputStream();
systemError = new PrintStream(errStrm);
private PrintStream createEmptyStream() {
return new PrintStream(
new OutputStream() {
public void write(int b) {
}
});
}


ByteArrayOutputStream outStrm = new ByteArrayOutputStream();
systemOut = new PrintStream(outStrm);
private PrintStream createTeePrint(PrintStream ps1, PrintStream ps2) {
return new PrintStream(new TeeOutputStream(ps1, ps2));
}


PrintStream savedErr = null;
private void setupIOStreams(ByteArrayOutputStream o,
ByteArrayOutputStream e) {
systemOut = new PrintStream(o);
systemError = new PrintStream(e);


if (forked) { if (forked) {
if (!outputToFormatters) { if (!outputToFormatters) {
if (!showOutput) { if (!showOutput) {
savedOut = System.out; savedOut = System.out;
savedErr = System.err; savedErr = System.err;
System.setOut(
new PrintStream(
new OutputStream() {
public void write(int b) {
}
}));
System.setErr(
new PrintStream(
new OutputStream() {
public void write(int b) {
}
}));
System.setOut(createEmptyStream());
System.setErr(createEmptyStream());
} }
} else { } else {
savedOut = System.out; savedOut = System.out;
@@ -306,15 +296,8 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
System.setOut(systemOut); System.setOut(systemOut);
System.setErr(systemError); System.setErr(systemError);
} else { } else {
System.setOut(new PrintStream(
new TeeOutputStream(savedOut, systemOut)
)
);
System.setErr(new PrintStream(
new TeeOutputStream(savedErr,
systemError)
)
);
System.setOut(createTeePrint(savedOut, systemOut));
System.setErr(createTeePrint(savedErr, systemError));
} }
perm = null; perm = null;
} }
@@ -323,6 +306,22 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
perm.setSecurityManager(); perm.setSecurityManager();
} }
} }
}

/**
* Run the test.
*/
public void run() {
res = new TestResult();
res.addListener(wrapListener(this));
for (int i = 0; i < formatters.size(); i++) {
res.addListener(wrapListener((TestListener) formatters.elementAt(i)));
}

ByteArrayOutputStream errStrm = new ByteArrayOutputStream();
ByteArrayOutputStream outStrm = new ByteArrayOutputStream();

setupIOStreams(outStrm, errStrm);


Test suite = null; Test suite = null;
Throwable exception = null; Throwable exception = null;
@@ -740,9 +739,10 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
JUnitTest t = new JUnitTest(testCaseName); JUnitTest t = new JUnitTest(testCaseName);
t.setTodir(new File(st.nextToken())); t.setTodir(new File(st.nextToken()));
t.setOutfile(st.nextToken()); t.setOutfile(st.nextToken());
t.setProperties(props);
code = launch(t, haltError, stackfilter, haltFail, code = launch(t, haltError, stackfilter, haltFail,
showOut, outputToFormat, showOut, outputToFormat,
logTestListenerEvents, props);
logTestListenerEvents);
errorOccurred = (code == ERRORS); errorOccurred = (code == ERRORS);
failureOccurred = (code != SUCCESS); failureOccurred = (code != SUCCESS);
if (errorOccurred || failureOccurred) { if (errorOccurred || failureOccurred) {
@@ -763,10 +763,11 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
e.printStackTrace(); e.printStackTrace();
} }
} else { } else {
returnCode = launch(new JUnitTest(args[0]), haltError,
stackfilter, haltFail,
showOut, outputToFormat,
logTestListenerEvents, props);
JUnitTest t = new JUnitTest(args[0]);
t.setProperties(props);
returnCode = launch(
t, haltError, stackfilter, haltFail,
showOut, outputToFormat, logTestListenerEvents);
} }


registerNonCrash(); registerNonCrash();
@@ -899,9 +900,7 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
private static int launch(JUnitTest t, boolean haltError, private static int launch(JUnitTest t, boolean haltError,
boolean stackfilter, boolean haltFail, boolean stackfilter, boolean haltFail,
boolean showOut, boolean outputToFormat, boolean showOut, boolean outputToFormat,
boolean logTestListenerEvents,
Properties props) {
t.setProperties(props);
boolean logTestListenerEvents) {
JUnitTestRunner runner = JUnitTestRunner runner =
new JUnitTestRunner(t, haltError, stackfilter, haltFail, showOut, new JUnitTestRunner(t, haltError, stackfilter, haltFail, showOut,
logTestListenerEvents, null); logTestListenerEvents, null);


Loading…
Cancel
Save