Newer
Older

Thiemo Belmega
committed
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
package de.unipotsdam.cs.toolup.util;
import org.apache.commons.lang3.builder.ToStringBuilder;
import java.util.Collection;
public class AssertionUtil {
public static <T> void assertContainsAll(Collection<T> expectedCollection, Collection<? extends T> actualCollection) {
if (expectedCollection == null && actualCollection == null) {
return;
}
if (expectedCollection == null ^ actualCollection == null) {
throw new AssertionError("Expected: " + expectedCollection + "\n but was: " + actualCollection);
}
if (!expectedCollection.containsAll(actualCollection)) {
String expected = ToStringBuilder.reflectionToString(expectedCollection);
String actual = ToStringBuilder.reflectionToString(actualCollection);
throw new AssertionError("Expected: " + expected + "\n but was: " + actual);
}
}
public static <T> void assertCollectionEquals(Collection<T> expectedCollection, Collection<T> actualCollection) {
if (expectedCollection == null && actualCollection == null) {
return;
}
if (expectedCollection == null ^ actualCollection == null) {
throw new AssertionError("Expected: " + expectedCollection + "\n but was: " + actualCollection);
}
if (expectedCollection.size() != actualCollection.size()) {
throw new AssertionError("Expected size " + expectedCollection.size() + "\n but was: " + actualCollection.size());
}
assertContainsAll(expectedCollection, actualCollection);
assertContainsAll(actualCollection, expectedCollection);
}
}