1 package org.junit.runner.notification; 2 3 import java.io.PrintWriter ; 4 import java.io.StringWriter ; 5 6 import org.junit.runner.Description; 7 8 15 public class Failure { 16 private final Description fDescription; 17 private Throwable fThrownException; 18 19 24 public Failure(Description description, Throwable thrownException) { 25 fThrownException = thrownException; 26 fDescription= description; 27 } 28 29 32 public String getTestHeader() { 33 return fDescription.getDisplayName(); 34 } 35 36 39 public Description getDescription() { 40 return fDescription; 41 } 42 43 46 47 public Throwable getException() { 48 return fThrownException; 49 } 50 51 @Override 52 public String toString() { 53 StringBuffer buffer= new StringBuffer (); 54 buffer.append(getTestHeader() + ": "+fThrownException.getMessage()); 55 return buffer.toString(); 56 } 57 58 62 public String getTrace() { 63 StringWriter stringWriter= new StringWriter (); 64 PrintWriter writer= new PrintWriter (stringWriter); 65 getException().printStackTrace(writer); 66 StringBuffer buffer= stringWriter.getBuffer(); 67 return buffer.toString(); 68 } 69 70 74 public String getMessage() { 75 return getException().getMessage(); 76 } 77 } 78 | Popular Tags |