1 package junit.framework; 2 3 import java.io.PrintWriter ; 4 import java.io.StringWriter ; 5 6 7 12 public class TestFailure extends Object { 13 protected Test fFailedTest; 14 protected Throwable fThrownException; 15 16 17 20 public TestFailure(Test failedTest, Throwable thrownException) { 21 fFailedTest= failedTest; 22 fThrownException= thrownException; 23 } 24 27 public Test failedTest() { 28 return fFailedTest; 29 } 30 33 public Throwable thrownException() { 34 return fThrownException; 35 } 36 39 @Override 40 public String toString() { 41 StringBuffer buffer= new StringBuffer (); 42 buffer.append(fFailedTest+": "+fThrownException.getMessage()); 43 return buffer.toString(); 44 } 45 public String trace() { 46 StringWriter stringWriter= new StringWriter (); 47 PrintWriter writer= new PrintWriter (stringWriter); 48 thrownException().printStackTrace(writer); 49 StringBuffer buffer= stringWriter.getBuffer(); 50 return buffer.toString(); 51 } 52 public String exceptionMessage() { 53 return thrownException().getMessage(); 54 } 55 public boolean isFailure() { 56 return thrownException() instanceof AssertionFailedError; 57 } 58 } | Popular Tags |