public class CollectionFilter {
+ /**
+ * Filters a collection by adding all elements in the from collection
+ * that satisfy a given condition to the to collection.
+ * @param <T> Type of contained element.
+ * @param aFrom From container to which the condition is applied.
+ * @param aTo To container to which matching elements are added.
+ * @param aCondition Condition by which elements are matched.
+ */
public static <T> void filter(Collection<T> aFrom, Collection<T> aTo, Condition<T> aCondition) {
for (T t: aFrom) {
if ( aCondition.matches(t)) {
*/
package org.wamblee.test;
+import java.util.Arrays;
+import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
* @param aActual
* Actual object array.
*/
- public static void assertEquals(Object[] aExpected, Object[] aActual) {
+ public static <T> void assertEquals(T[] aExpected, T[] aActual) {
assertEquals("", aExpected, aActual);
}
+
/**
* Asserts that two object arrays are equal.
* @param aActual
* Actual array.
*/
- public static void assertEquals(String aMsg, Object[] aExpected,
- Object[] aActual) {
+ public static <T> void assertEquals(String aMsg, T[] aExpected,
+ T[] aActual) {
TestCase.assertEquals(aMsg + ": Array lengths ", aExpected.length,
aActual.length);
aActual[i]);
}
}
+
/**
* Asserts that two objects are equal, and in case the object is an Object[]
* @param aActual
* Actual result.
*/
- public static void assertEquals(String aMsg, Object aExpected,
- Object aActual) {
+ public static <T> void assertEquals(String aMsg, T aExpected,
+ T aActual) {
if (aExpected instanceof Object[]) {
AssertionUtils.assertEquals(aMsg, (Object[]) aExpected,
(Object[]) aActual);
* @param aActual
* Actual result.
*/
- public static void assertEquals(String aMsg, Map aExpectedMap, Map aActual) {
+ public static <Key,Value> void assertEquals(String aMsg,
+ Map<Key,Value> aExpectedMap, Map<Key,Value> aActual) {
TestCase.assertEquals("Map sizes differ", aExpectedMap.size(), aActual
.size());
public static void assertException(ErroneousCode aObject, Class aType) {
try {
aObject.run();
+ throw new RuntimeException("No exception occurred");
} catch (Throwable t) {
if ( aType.isInstance(t)) {
return; // ok