From 1266e53bd199e68ea11ce1bcf38b58d8fc1ea0a1 Mon Sep 17 00:00:00 2001 From: Peter Reilly Date: Thu, 16 Aug 2007 14:21:50 +0000 Subject: [PATCH] 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 --- .../optional/junit/JUnitTestRunner.java | 87 +++++++++---------- 1 file changed, 43 insertions(+), 44 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java index a32eeb671..d59bb5292 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java @@ -262,42 +262,32 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR } 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 (!outputToFormatters) { if (!showOutput) { savedOut = System.out; 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 { savedOut = System.out; @@ -306,15 +296,8 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR System.setOut(systemOut); System.setErr(systemError); } 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; } @@ -323,6 +306,22 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR 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; Throwable exception = null; @@ -740,9 +739,10 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR JUnitTest t = new JUnitTest(testCaseName); t.setTodir(new File(st.nextToken())); t.setOutfile(st.nextToken()); + t.setProperties(props); code = launch(t, haltError, stackfilter, haltFail, showOut, outputToFormat, - logTestListenerEvents, props); + logTestListenerEvents); errorOccurred = (code == ERRORS); failureOccurred = (code != SUCCESS); if (errorOccurred || failureOccurred) { @@ -763,10 +763,11 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR e.printStackTrace(); } } 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(); @@ -899,9 +900,7 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR private static int launch(JUnitTest t, boolean haltError, boolean stackfilter, boolean haltFail, boolean showOut, boolean outputToFormat, - boolean logTestListenerEvents, - Properties props) { - t.setProperties(props); + boolean logTestListenerEvents) { JUnitTestRunner runner = new JUnitTestRunner(t, haltError, stackfilter, haltFail, showOut, logTestListenerEvents, null);