Home | History | Annotate | Download | only in framework
      1 package junit.framework;
      2 
      3 /**
      4  * Thrown when an assert equals for Strings failed.
      5  *
      6  * Inspired by a patch from Alex Chaffee mailto:alex (at) purpletech.com
      7  */
      8 public class ComparisonFailure extends AssertionFailedError {
      9 	private static final int MAX_CONTEXT_LENGTH= 20;
     10 	private static final long serialVersionUID= 1L;
     11 
     12 	private String fExpected;
     13 	private String fActual;
     14 
     15 	/**
     16 	 * Constructs a comparison failure.
     17 	 * @param message the identifying message or null
     18 	 * @param expected the expected string value
     19 	 * @param actual the actual string value
     20 	 */
     21 	public ComparisonFailure (String message, String expected, String actual) {
     22 		super (message);
     23 		fExpected= expected;
     24 		fActual= actual;
     25 	}
     26 
     27 	/**
     28 	 * Returns "..." in place of common prefix and "..." in
     29 	 * place of common suffix between expected and actual.
     30 	 *
     31 	 * @see java.lang.Throwable#getMessage()
     32 	 */
     33 	public String getMessage() {
     34 		return new ComparisonCompactor(MAX_CONTEXT_LENGTH, fExpected, fActual).compact(super.getMessage());
     35 	}
     36 
     37 	/**
     38 	 * Gets the actual string value
     39 	 * @return the actual string value
     40 	 */
     41 	public String getActual() {
     42 		return fActual;
     43 	}
     44 	/**
     45 	 * Gets the expected string value
     46 	 * @return the expected string value
     47 	 */
     48 	public String getExpected() {
     49 		return fExpected;
     50 	}
     51 }