package org.wamblee.test;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.Set;
private AssertionUtils() {
// Empty
}
+
+ /**
+ * Asserts that two collections are equal including equality of the elements.
+ * @param aExpected
+ * @param aActual
+ */
+ public static void assertEquals(List aExpected, List aActual) {
+ assertEquals(aExpected.toArray(), aActual.toArray());
+ }
+
+ /**
+ * Asserts that two collections are equal including equality of the elements.
+ * @param aMsg
+ * @param aExpected
+ * @param aActual
+ */
+ public static void assertEquals(String aMsg, List aExpected, List aActual) {
+ assertEquals(aMsg, aExpected.toArray(), aActual.toArray());
+ }
/**
* Asserts that two object arrays are equal.
aExpectedMap.get(key), aActual.get(key));
}
}
+
+ public static interface ErroneousCode {
+ void run() throws Exception;
+ }
+
+ /**
+ * Asserts that an exception occurs.
+ * @param aRunnable Test cases should create a subclass of this which contains the
+ * code that should throw an exception.
+ * @param aType Type of exception that is expected.
+ */
+ public static void assertException(ErroneousCode aObject, Class aType) {
+ try {
+ aObject.run();
+ } catch (Throwable t) {
+ if ( aType.isInstance(t)) {
+ return; // ok
+ }
+ else {
+ throw new RuntimeException(t);
+ }
+ }
+ }
}