1 package junit.framework;
2
3 import java.io.PrintWriter;
4 import java.io.StringWriter;
5
6
7
8
9
10
11
12
13 public class TestFailure {
14 protected Test fFailedTest;
15 protected Throwable fThrownException;
16
17
18
19
20 public TestFailure(Test failedTest, Throwable thrownException) {
21 fFailedTest = failedTest;
22 fThrownException = thrownException;
23 }
24
25
26
27
28 public Test failedTest() {
29 return fFailedTest;
30 }
31
32
33
34
35 public Throwable thrownException() {
36 return fThrownException;
37 }
38
39
40
41
42 @Override
43 public String toString() {
44 return fFailedTest + ": " + fThrownException.getMessage();
45 }
46
47
48
49
50
51 public String trace() {
52 StringWriter stringWriter = new StringWriter();
53 PrintWriter writer = new PrintWriter(stringWriter);
54 thrownException().printStackTrace(writer);
55 return stringWriter.toString();
56 }
57
58
59
60
61 public String exceptionMessage() {
62 return thrownException().getMessage();
63 }
64
65
66
67
68
69
70 public boolean isFailure() {
71 return thrownException() instanceof AssertionFailedError;
72 }
73 }