0349bc07c5cdcb3df3b6e90e92dd10d9febaba6f
1 package be
.nikiroo
.utils
.test
;
4 * A {@link TestCase} that can be run with {@link TestLauncher}.
8 abstract public class TestCase
{
10 * The type of {@link Exception} used to signal a failed assertion or a
15 class AssertException
extends Exception
{
16 private static final long serialVersionUID
= 1L;
18 public AssertException(String reason
) {
26 * Create a new {@link TestCase}.
31 public TestCase(String name
) {
36 * Setup the test (called before the test is run).
41 public void setUp() throws Exception
{
45 * Tear-down the test (called when the test has been ran).
50 public void tearDown() throws Exception
{
58 public String
getName() {
63 * Actually do the test.
68 abstract public void test() throws Exception
;
73 * @throws AssertException
76 public void fail() throws AssertException
{
85 * @throws AssertException
88 public void fail(String reason
) throws AssertException
{
89 throw new AssertException("Failed!" + //
90 reason
!= null ?
"\n" + reason
: "");
94 * Check that 2 {@link Object}s are equals.
101 * @throws AssertException
102 * in case they differ
104 public void assertEquals(Object expected
, Object actual
)
105 throws AssertException
{
106 assertEquals(null, expected
, actual
);
110 * Check that 2 {@link Object}s are equals.
113 * error message to display if they differ
119 * @throws AssertException
120 * in case they differ
122 public void assertEquals(String errorMessage
, Object expected
, Object actual
)
123 throws AssertException
{
125 if (errorMessage
== null) {
126 errorMessage
= String
.format("" //
127 + "Assertion failed!\n" //
128 + "Expected value: [%s]\n" //
129 + "Actual value: [%s]", expected
, actual
);
132 if ((expected
== null && actual
!= null)
133 || (expected
!= null && !expected
.equals(actual
))) {
134 throw new AssertException(errorMessage
);
139 * Check that 2 {@link Object}s are equals.
146 * @throws AssertException
147 * in case they differ
149 public void assertEquals(long expected
, long actual
) throws AssertException
{
150 assertEquals(new Long(expected
), new Long(actual
));
154 * Check that 2 {@link Object}s are equals.
157 * error message to display if they differ
163 * @throws AssertException
164 * in case they differ
166 public void assertEquals(String errorMessage
, long expected
, long actual
)
167 throws AssertException
{
168 assertEquals(errorMessage
, new Long(expected
), new Long(actual
));
172 * Check that 2 {@link Object}s are equals.
179 * @throws AssertException
180 * in case they differ
182 public void assertEquals(boolean expected
, boolean actual
)
183 throws AssertException
{
184 assertEquals(new Boolean(expected
), new Boolean(actual
));
188 * Check that 2 {@link Object}s are equals.
191 * error message to display if they differ
197 * @throws AssertException
198 * in case they differ
200 public void assertEquals(String errorMessage
, boolean expected
,
201 boolean actual
) throws AssertException
{
202 assertEquals(errorMessage
, new Boolean(expected
), new Boolean(actual
));
206 * Check that 2 {@link Object}s are equals.
213 * @throws AssertException
214 * in case they differ
216 public void assertEquals(double expected
, double actual
)
217 throws AssertException
{
218 assertEquals(new Double(expected
), new Double(actual
));
222 * Check that 2 {@link Object}s are equals.
225 * error message to display if they differ
231 * @throws AssertException
232 * in case they differ
234 public void assertEquals(String errorMessage
, double expected
, double actual
)
235 throws AssertException
{
236 assertEquals(errorMessage
, new Double(expected
), new Double(actual
));