1 18 19 package org.apache.tools.ant.taskdefs.optional.junit; 20 21 import java.io.OutputStream ; 22 import junit.framework.AssertionFailedError; 23 import junit.framework.TestCase; 24 import junit.framework.TestResult; 25 import org.apache.tools.ant.AntClassLoader; 26 27 34 public final class JUnitTaskMirrorImpl implements JUnitTaskMirror { 35 36 private final JUnitTask task; 37 38 42 public JUnitTaskMirrorImpl(JUnitTask task) { 43 this.task = task; 44 } 45 46 47 public void addVmExit(JUnitTest test, JUnitTaskMirror.JUnitResultFormatterMirror aFormatter, 48 OutputStream out, String message, String testCase) { 49 JUnitResultFormatter formatter = (JUnitResultFormatter) aFormatter; 50 formatter.setOutput(out); 51 formatter.startTestSuite(test); 52 TestCase t = new VmExitErrorTest(message, test, testCase); 56 formatter.startTest(t); 57 formatter.addError(t, new AssertionFailedError(message)); 58 formatter.endTestSuite(test); 59 } 60 61 62 public JUnitTaskMirror.JUnitTestRunnerMirror newJUnitTestRunner(JUnitTest test, 63 boolean haltOnError, boolean filterTrace, boolean haltOnFailure, 64 boolean showOutput, boolean logTestListenerEvents, AntClassLoader classLoader) { 65 return new JUnitTestRunner(test, haltOnError, filterTrace, haltOnFailure, 66 showOutput, logTestListenerEvents, classLoader); 67 } 68 69 70 public JUnitTaskMirror.SummaryJUnitResultFormatterMirror newSummaryJUnitResultFormatter() { 71 return new SummaryJUnitResultFormatter(); 72 } 73 74 static class VmExitErrorTest extends TestCase { 75 76 private String message; 77 private JUnitTest test; 78 private String testCase; 79 80 VmExitErrorTest(String aMessage, JUnitTest anOriginalTest, String aTestCase) { 81 message = aMessage; 82 test = anOriginalTest; 83 testCase = aTestCase; 84 } 85 86 public int countTestCases() { 87 return 1; 88 } 89 90 public void run(TestResult r) { 91 throw new AssertionFailedError(message); 92 } 93 94 public String getName() { 95 return testCase; 96 } 97 98 String getClassName() { 99 return test.getName(); 100 } 101 102 public String toString() { 103 return test.getName() + ":" + testCase; 104 } 105 } 106 } 107 | Popular Tags |