Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: junit/framework/TestFailure.java


1   package junit.framework;
2   
3   import java.io.PrintWriter;
4   import java.io.StringWriter;
5   
6   
7   /**
8    * A <code>TestFailure</code> collects a failed test together with
9    * the caught exception.
10   * @see TestResult
11   */
12  public class TestFailure extends Object {
13    protected Test fFailedTest;
14    protected Throwable fThrownException;
15    
16  
17    /**
18     * Constructs a TestFailure with the given test and exception.
19     */
20    public TestFailure(Test failedTest, Throwable thrownException) {
21      fFailedTest= failedTest;
22      fThrownException= thrownException;
23    }
24    /**
25     * Gets the failed test.
26     */
27    public Test failedTest() {
28        return fFailedTest;
29    }
30    /**
31     * Gets the thrown exception.
32     */
33    public Throwable thrownException() {
34        return fThrownException;
35    }
36    /**
37     * Returns a short description of the failure.
38     */
39    public String toString() {
40        StringBuffer buffer= new StringBuffer();
41        buffer.append(fFailedTest+": "+fThrownException.getMessage());
42        return buffer.toString();
43    }
44    public String trace() {
45      StringWriter stringWriter= new StringWriter();
46      PrintWriter writer= new PrintWriter(stringWriter);
47      thrownException().printStackTrace(writer);
48      StringBuffer buffer= stringWriter.getBuffer();
49      return buffer.toString();
50    }
51    public String exceptionMessage() {
52      return thrownException().getMessage();
53    }
54    public boolean isFailure() {
55      return thrownException() instanceof AssertionFailedError;
56    }
57  }