1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
//Copyright (c) Corporation for National Research Initiatives
package javatests;
import java.lang.reflect.Field;
import java.lang.NoSuchFieldException;
/**
* @author updikca1
*/
public class TestSupport {
public static class AssertionError extends RuntimeException {
public AssertionError() {
super();
}
public AssertionError(String message) {
super(message);
}
public AssertionError(String message, Throwable cause) {
super(message, cause);
}
public AssertionError(Throwable cause) {
super(cause);
}
}
public static void assertThat(boolean test, String message) {
if (!test) {
throw new AssertionError(message);
}
}
public static void fail(String message) {
throw new AssertionError(message);
}
public static void assertEquals(Object a, Object b, String message) {
assertThat(a.equals(b), message + "[a.equals(b) failed]");
assertThat(b.equals(a), message + "[b.equals(a) failed]");
}
public static void assertNotEquals(Object a, Object b, String message) {
assertThat( !a.equals(b), message + "[not a.equals(b) failed]");
assertThat( !b.equals(a), message + "[not b.equals(a) failed]");
}
public static Field getField(Class cls, String name) {
try {
Field f = cls.getDeclaredField(name);
f.setAccessible(true);
return f;
} catch (NoSuchFieldException ex) {
throw new RuntimeException(ex);
}
}
}
|