/** * Assert two float values are equal * * @param one the expected value * @param two the actual value */ protected void assertEquals(float one, float two) { assertEquals(one, two, 0f); }
/** * Serialize/deserialize * * @param <T> the expected type * @param value the value * @param expected the expected type * @return the result * @throws Exception for any problem */ protected <T> T serializeDeserialize(Serializable value, Class<T> expected) throws Exception { byte[] bytes = serialize(value); Object result = deserialize(bytes); return assertInstanceOf(result, expected); }
public URL getResource(final String name) { return findResource(getClass(), name); }
/** * Asserts a collection is empty * * @param context the context * @param c the collection */ protected void assertEmpty(String context, Collection c) { assertNotNull(c); if (c.isEmpty() == false) throw new AssertionFailedError(context); }
/** * Check we have the expected deep exception * * @param expected the excepted class of the exception * @param throwable the real exception */ public static void checkDeepThrowable(Class<? extends Throwable> expected, Throwable throwable) { assertNotNull(expected); assertNotNull(throwable); while (throwable.getCause() != null) throwable = throwable.getCause(); if (throwable instanceof AssertionFailedError || throwable instanceof AssertionError) throw (Error) throwable; if (expected.equals(throwable.getClass()) == false) { staticLog.error("Unexpected throwable", throwable); fail("Unexpected throwable: " + throwable); } else { staticLog.debug("Got expected " + expected.getName() + "(" + throwable + ")"); } }
public void doJoinExpectError(Class<? extends Throwable> expected) throws InterruptedException { super.join(); if (t == null) throw new AssertionFailedError("No error from thread " + this); AbstractTestCase.checkThrowable(expected, t); }
/** * Check we have the expected exception * * @param expected the excepted class of the exception * @param throwable the real exception */ public static void checkThrowable(Class<? extends Throwable> expected, Throwable throwable) { if (expected == null) fail("Must provide an expected class"); if (throwable == null) fail("Must provide a throwable for comparison"); if (throwable instanceof AssertionFailedError || throwable instanceof AssertionError) throw (Error) throwable; if (expected.equals(throwable.getClass()) == false) { staticLog.error("Unexpected throwable", throwable); fail("Unexpected throwable: " + throwable); } else { staticLog.debug("Got expected " + expected.getName() + "(" + throwable + ")"); } }
protected void setUp() throws Exception { log("Starting"); startTime = System.currentTimeMillis(); }
/** * Check we have the expected type * * @param <T> the expected type * @param o the object * @param expectedType the excepted class of the exception * @return the expected type */ protected <T> T assertInstanceOf(Object o, Class<T> expectedType) { return assertInstanceOf(o, expectedType, true); }
/** * Raise an assertion failed error for an error * * @param reason the reason * @param cause the cause */ protected void failure(String reason, Throwable cause) { getLog().error(reason, cause); if (cause instanceof AssertionFailedError) throw (AssertionFailedError) cause; Error error = new AssertionFailedError(reason); error.initCause(cause); throw error; }
/** * Asserts a collection is empty * * @param context the context * @param c the collection */ protected void assertEmpty(String context, Collection c) { assertNotNull(c); if (c.isEmpty() == false) throw new AssertionFailedError(context); }
/** * Check we have the expected deep exception * * @param expected the excepted class of the exception * @param throwable the real exception */ public static void checkDeepThrowable(Class<? extends Throwable> expected, Throwable throwable) { assertNotNull(expected); assertNotNull(throwable); while (throwable.getCause() != null) throwable = throwable.getCause(); if (throwable instanceof AssertionFailedError || throwable instanceof AssertionError) throw (Error) throwable; if (expected.equals(throwable.getClass()) == false) { staticLog.error("Unexpected throwable", throwable); fail("Unexpected throwable: " + throwable); } else { staticLog.debug("Got expected " + expected.getName() + "(" + throwable + ")"); } }
public void doJoinExpectError(long millis, Class<? extends Throwable> expected) throws InterruptedException { super.join(millis); if (t == null) throw new AssertionFailedError("No error from thread " + this); AbstractTestCase.checkThrowable(expected, t); } }
/** * Check we have the expected exception * * @param expected the excepted class of the exception * @param throwable the real exception */ public static void checkThrowable(Class<? extends Throwable> expected, Throwable throwable) { if (expected == null) fail("Must provide an expected class"); if (throwable == null) fail("Must provide a throwable for comparison"); if (throwable instanceof AssertionFailedError || throwable instanceof AssertionError) throw (Error) throwable; if (expected.equals(throwable.getClass()) == false) { staticLog.error("Unexpected throwable", throwable); fail("Unexpected throwable: " + throwable); } else { staticLog.debug("Got expected " + expected.getName() + "(" + throwable + ")"); } }
protected void setUp() throws Exception { log("Starting"); startTime = System.currentTimeMillis(); }
/** * Check we have the expected type * * @param <T> the expected type * @param o the object * @param expectedType the excepted class of the exception * @return the expected type */ protected <T> T assertInstanceOf(Object o, Class<T> expectedType) { return assertInstanceOf(o, expectedType, true); }