01: package junit.framework;
02:
03: /**
04: * Thrown when an assert equals for Strings failed.
05: *
06: * Inspired by a patch from Alex Chaffee mailto:alex@purpletech.com
07: */
08: public class ComparisonFailure extends AssertionFailedError {
09: 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,
22: String actual) {
23: super (message);
24: fExpected = expected;
25: fActual = actual;
26: }
27:
28: /**
29: * Returns "..." in place of common prefix and "..." in
30: * place of common suffix between expected and actual.
31: *
32: * @see Throwable#getMessage()
33: */
34: @Override
35: public String getMessage() {
36: return new ComparisonCompactor(MAX_CONTEXT_LENGTH, fExpected,
37: fActual).compact(super .getMessage());
38: }
39:
40: /**
41: * Gets the actual string value
42: * @return the actual string value
43: */
44: public String getActual() {
45: return fActual;
46: }
47:
48: /**
49: * Gets the expected string value
50: * @return the expected string value
51: */
52: public String getExpected() {
53: return fExpected;
54: }
55: }
|