forked from Qortal/qortal
CHANGED: simplified AssertExtensions
This commit is contained in:
parent
730b5033d1
commit
af84cc8575
@ -6,16 +6,12 @@ import java.io.ByteArrayInputStream;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Set;
|
|
||||||
import javax.xml.stream.XMLStreamException;
|
import javax.xml.stream.XMLStreamException;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
|
||||||
import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
import static test.utils.AssertExtensions.*;
|
import static test.utils.AssertExtensions.*;
|
||||||
@ -74,7 +70,7 @@ public class GlobalizationTests {
|
|||||||
" </context>\n" +
|
" </context>\n" +
|
||||||
"</localization>\n";
|
"</localization>\n";
|
||||||
|
|
||||||
List<TranslationEntry> expected = new ArrayList<TranslationEntry>();
|
List<TranslationEntry> expected = new ArrayList<>();
|
||||||
expected.add(new TranslationEntry(Locale.forLanguageTag("en-GB"), "/path1/key1", "1"));
|
expected.add(new TranslationEntry(Locale.forLanguageTag("en-GB"), "/path1/key1", "1"));
|
||||||
expected.add(new TranslationEntry(Locale.forLanguageTag("en-GB"), "/path1/path2/path3/key2", "2"));
|
expected.add(new TranslationEntry(Locale.forLanguageTag("en-GB"), "/path1/path2/path3/key2", "2"));
|
||||||
expected.add(new TranslationEntry(Locale.forLanguageTag("en-GB"), "/path1/path4/key3", "3"));
|
expected.add(new TranslationEntry(Locale.forLanguageTag("en-GB"), "/path1/path4/key3", "3"));
|
||||||
|
@ -4,6 +4,7 @@ import com.google.common.collect.Iterables;
|
|||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.Array;
|
||||||
import java.lang.Class;
|
import java.lang.Class;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -13,11 +14,11 @@ import static org.hamcrest.MatcherAssert.assertThat;
|
|||||||
|
|
||||||
public class AssertExtensions {
|
public class AssertExtensions {
|
||||||
|
|
||||||
public static <T> void assertItemsEqual(Iterable<T> expected, Iterable<T> actual, EqualityComparer<T> comparer) {
|
public static <T> void assertItemsEqual(Collection<T> expected, Iterable<T> actual, EqualityComparer<T> comparer) {
|
||||||
assertItemsEqual(expected, actual, comparer, (String)null);
|
assertItemsEqual(expected, actual, comparer, (String)null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> void assertItemsEqual(Iterable<T> expected, Iterable<T> actual, EqualityComparer<T> comparer, String message) {
|
public static <T> void assertItemsEqual(Collection<T> expected, Iterable<T> actual, EqualityComparer<T> comparer, String message) {
|
||||||
List<EquatableWrapper<T>> expectedSet = new ArrayList<EquatableWrapper<T>>();
|
List<EquatableWrapper<T>> expectedSet = new ArrayList<EquatableWrapper<T>>();
|
||||||
for(T item: expected)
|
for(T item: expected)
|
||||||
expectedSet.add(new EquatableWrapper<T>(item, comparer));
|
expectedSet.add(new EquatableWrapper<T>(item, comparer));
|
||||||
@ -29,26 +30,13 @@ public class AssertExtensions {
|
|||||||
assertItemsEqual(expectedSet, actualSet, message);
|
assertItemsEqual(expectedSet, actualSet, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> void assertItemsEqual(Iterable<T> expected, Iterable<T> actual) {
|
public static <T> void assertItemsEqual(Collection<T> expected, Iterable<T> actual) {
|
||||||
assertItemsEqual(expected, actual, (String)null);
|
assertItemsEqual(expected, actual, (String)null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> void assertItemsEqual(Iterable<T> expected, Iterable<T> actual, String message) {
|
public static <T> void assertItemsEqual(Collection<T> expected, Iterable<T> actual, String message) {
|
||||||
List<T> list = new ArrayList<T>();
|
List<T> list = new ArrayList<T>();
|
||||||
T[] expectedArray = getArray(expected);
|
T[] expectedArray = (T[])expected.toArray();
|
||||||
assertThat(message, actual, containsInAnyOrder(expectedArray));
|
assertThat(message, actual, containsInAnyOrder(expectedArray));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T> T[] getArray(Iterable<T> iterable) {
|
|
||||||
// XXX: What a horrific way to create an array from an iterable.
|
|
||||||
// Isn't there a better solution?
|
|
||||||
List<T> list = new ArrayList<T>();
|
|
||||||
for(T item : iterable)
|
|
||||||
list.add(item);
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
T[] result = (T[])new Object[list.size()];
|
|
||||||
for(int i = 0; i < list.size(); i++)
|
|
||||||
result[i] = list.get(i);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user