| 1 |
package org.astrogrid.samp.test; |
| 2 |
|
| 3 |
/** |
| 4 |
* No-frills test case superclass. |
| 5 |
* |
| 6 |
* @author Mark Taylor |
| 7 |
* @since 18 Jul 2008 |
| 8 |
*/ |
| 9 |
public class Tester { |
| 10 |
|
| 11 |
/** |
| 12 |
* Fails a test. |
| 13 |
* |
| 14 |
* @throws TextException always |
| 15 |
*/ |
| 16 |
public static void fail() throws TestException { |
| 17 |
throw new TestException( "Test failed" ); |
| 18 |
} |
| 19 |
|
| 20 |
/** |
| 21 |
* Tests an assertion. |
| 22 |
* |
| 23 |
* @param test asserted condition |
| 24 |
* @throws TestException if <code>test</code> is false |
| 25 |
*/ |
| 26 |
public static void assertTrue( boolean test ) throws TestException { |
| 27 |
if ( ! test ) { |
| 28 |
throw new TestException( "Test failed" ); |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Tests object equality. |
| 34 |
* |
| 35 |
* @param o1 object 1 |
| 36 |
* @param o2 object 2 |
| 37 |
* @throws TestException unless <code>o1</code> and <code>o2</code> |
| 38 |
* are both <code>null</code> or are equal in the sense of |
| 39 |
* {@link java.lang.Object#equals} |
| 40 |
*/ |
| 41 |
public static void assertEquals( Object o1, Object o2 ) |
| 42 |
throws TestException { |
| 43 |
if ( o1 == null && o2 == null ) { |
| 44 |
} |
| 45 |
else if ( o1 == null || ! o1.equals( o2 ) ) { |
| 46 |
throw new TestException( |
| 47 |
"Test failed: " + o1 + " != " + o2 ); |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Tests integer equality. |
| 53 |
* |
| 54 |
* @param i1 integer 1 |
| 55 |
* @param i2 integer 2 |
| 56 |
* @throws TestException iff <code>i1</code> != <code>i2</code> |
| 57 |
*/ |
| 58 |
public static void assertEquals( int i1, int i2 ) throws TestException { |
| 59 |
if ( i1 != i2 ) { |
| 60 |
throw new TestException( |
| 61 |
"Test failed: " + i1 + " != " + i2 ); |
| 62 |
} |
| 63 |
} |
| 64 |
} |