KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > junit > framework > ComparisonFailure


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@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 JavaDoc fExpected;
13     private String JavaDoc 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 JavaDoc message, String JavaDoc expected, String JavaDoc 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 Throwable#getMessage()
32      */

33     @Override JavaDoc
34     public String JavaDoc getMessage() {
35         return new ComparisonCompactor(MAX_CONTEXT_LENGTH, fExpected, fActual).compact(super.getMessage());
36     }
37     
38     /**
39      * Gets the actual string value
40      * @return the actual string value
41      */

42     public String JavaDoc getActual() {
43         return fActual;
44     }
45     /**
46      * Gets the expected string value
47      * @return the expected string value
48      */

49     public String JavaDoc getExpected() {
50         return fExpected;
51     }
52 }
Popular Tags