01: /*
02: * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
03: * Copyright (C) 2007 - Javolution (http://javolution.org/)
04: * All rights reserved.
05: *
06: * Permission to use, copy, modify, and distribute this software is
07: * freely granted, provided that this notice is preserved.
08: */
09: package javolution.testing;
10:
11: /**
12: * This class represents an exception which might be raised when
13: * a testing assertion fails (see {@link TestContext#REGRESSION}).
14: *
15: * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
16: * @version 5.2, August 5, 2007
17: */
18: public class AssertionException extends RuntimeException {
19:
20: /**
21: * Holds the associated message if any.
22: */
23: private String _message;
24:
25: /**
26: * Holds the expected value.
27: */
28: private Object _expected;
29:
30: /**
31: * Holds the actual value.
32: */
33: private Object _actual;
34:
35: /**
36: * Creates an exception with the specified parameters.
37: *
38: * @param message the associated message or <code>null</code>
39: * @param expected the expected value
40: * @param actual the actual value
41: */
42: public AssertionException(String message, Object expected,
43: Object actual) {
44: _message = message;
45: _expected = expected;
46: _actual = actual;
47: }
48:
49: /**
50: * Returns the assertion message if any.
51: *
52: * @return the assertion message or <code>null</code>
53: */
54: public String getMessage() {
55: return _message;
56: }
57:
58: /**
59: * Returns the expected value.
60: *
61: * @return the assertion expected value.
62: */
63: public Object getExpected() {
64: return _expected;
65: }
66:
67: /**
68: * Returns the actual value.
69: *
70: * @return the assertion actual value.
71: */
72: public Object getActual() {
73: return _actual;
74: }
75:
76: /**
77: * Returns the textual representation of this exception.
78: *
79: * @return the string representation of the exception.
80: */
81: public String toString() {
82: return _message != null ? _message + ": " + _expected
83: + " expected but found " + _actual : _expected
84: + " expected but found " + _actual;
85: }
86:
87: private static final long serialVersionUID = 1L;
88: }
|