Class Helpers
- java.lang.Object
-
- com.google.common.collect.testing.Helpers
-
@GwtCompatible(emulated=true) public class Helpers extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static interfaceHelpers.GwtTransientPrivate replacement forcom.google.gwt.user.client.rpc.GwtTransientto work around build-system quirks.static classHelpers.NullsBeforeCompares strings in natural order except that null comes immediately before a given value.static classHelpers.NullsBeforeBstatic classHelpers.NullsBeforeTwo
-
Field Summary
Fields Modifier and Type Field Description private static java.util.Comparator<java.lang.Comparable>NATURAL_ORDER
-
Constructor Summary
Constructors Constructor Description Helpers()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <E> booleanaddAll(java.util.Collection<E> addTo, java.lang.Iterable<? extends E> elementsToAdd)static voidassertContains(java.lang.Iterable<?> actual, java.lang.Object expected)static voidassertContainsAllOf(java.lang.Iterable<?> actual, java.lang.Object... expected)static voidassertContentsAnyOrder(java.lang.Iterable<?> actual, java.lang.Object... expected)static voidassertContentsInOrder(java.lang.Iterable<?> actual, java.lang.Object... expected)static voidassertEmpty(java.lang.Iterable<?> iterable)static voidassertEmpty(java.util.Map<?,?> map)static voidassertEqualIgnoringOrder(java.lang.Iterable<?> expected, java.lang.Iterable<?> actual)static voidassertEqualInOrder(java.lang.Iterable<?> expected, java.lang.Iterable<?> actual)(package private) static <E> java.util.List<E>castOrCopyToList(java.lang.Iterable<E> iterable)static <E> java.util.List<E>copyToList(E[] elements)static <E> java.util.List<E>copyToList(java.lang.Iterable<? extends E> elements)static <E> java.util.Set<E>copyToSet(E[] elements)static <E> java.util.Set<E>copyToSet(java.lang.Iterable<? extends E> elements)(package private) static <T> java.util.Iterator<T>cycle(java.lang.Iterable<T> iterable)static <K,V>
java.util.Comparator<java.util.Map.Entry<K,V>>entryComparator(java.util.Comparator<? super K> keyComparator)(package private) static booleanequal(java.lang.Object a, java.lang.Object b)(package private) static voidfail(java.lang.Throwable cause, java.lang.Object message)(package private) static <T> Tget(java.util.Iterator<T> iterator, int position)static java.lang.reflect.MethodgetMethod(java.lang.Class<?> clazz, java.lang.String name)private static booleanisEmpty(java.lang.Iterable<?> iterable)static <K,V>
java.util.Map.Entry<K,V>mapEntry(K key, V value)static <T> java.util.Collection<T>misleadingSizeCollection(int delta)Returns a collection that simulates concurrent modification by having its size method return incorrect values.static <K,V>
java.util.Map.Entry<K,V>nefariousMapEntry(K key, V value)Returns a "nefarious" map entry with the specified key and value, meaning an entry that is suitable for testing that map entries cannot be modified via a nefarious implementation of equals.static <K extends java.lang.Comparable,V>
java.lang.Iterable<java.util.Map.Entry<K,V>>orderEntriesByKey(java.util.List<java.util.Map.Entry<K,V>> insertionOrder)(package private) static <T> java.lang.Iterable<T>reverse(java.util.List<T> list)static <T> voidtestComparator(java.util.Comparator<? super T> comparator, java.util.List<T> valuesInExpectedOrder)Asserts that all pairs ofTvalues withinvaluesInExpectedOrderare ordered consistently between their order withinvaluesInExpectedOrderand the order implied by the givencomparator.static <T> voidtestComparator(java.util.Comparator<? super T> comparator, T... valuesInExpectedOrder)Asserts that all pairs ofTvalues withinvaluesInExpectedOrderare ordered consistently between their order withinvaluesInExpectedOrderand the order implied by the givencomparator.static <T extends java.lang.Comparable<? super T>>
voidtestCompareToAndEquals(java.util.List<T> valuesInExpectedOrder)
-
-
-
Method Detail
-
equal
static boolean equal(java.lang.Object a, java.lang.Object b)
-
copyToList
public static <E> java.util.List<E> copyToList(java.lang.Iterable<? extends E> elements)
-
copyToList
public static <E> java.util.List<E> copyToList(E[] elements)
-
copyToSet
public static <E> java.util.Set<E> copyToSet(java.lang.Iterable<? extends E> elements)
-
copyToSet
public static <E> java.util.Set<E> copyToSet(E[] elements)
-
mapEntry
public static <K,V> java.util.Map.Entry<K,V> mapEntry(K key, V value)
-
isEmpty
private static boolean isEmpty(java.lang.Iterable<?> iterable)
-
assertEmpty
public static void assertEmpty(java.lang.Iterable<?> iterable)
-
assertEmpty
public static void assertEmpty(java.util.Map<?,?> map)
-
assertEqualInOrder
public static void assertEqualInOrder(java.lang.Iterable<?> expected, java.lang.Iterable<?> actual)
-
assertContentsInOrder
public static void assertContentsInOrder(java.lang.Iterable<?> actual, java.lang.Object... expected)
-
assertEqualIgnoringOrder
public static void assertEqualIgnoringOrder(java.lang.Iterable<?> expected, java.lang.Iterable<?> actual)
-
assertContentsAnyOrder
public static void assertContentsAnyOrder(java.lang.Iterable<?> actual, java.lang.Object... expected)
-
assertContains
public static void assertContains(java.lang.Iterable<?> actual, java.lang.Object expected)
-
assertContainsAllOf
public static void assertContainsAllOf(java.lang.Iterable<?> actual, java.lang.Object... expected)
-
addAll
public static <E> boolean addAll(java.util.Collection<E> addTo, java.lang.Iterable<? extends E> elementsToAdd)
-
reverse
static <T> java.lang.Iterable<T> reverse(java.util.List<T> list)
-
cycle
static <T> java.util.Iterator<T> cycle(java.lang.Iterable<T> iterable)
-
get
static <T> T get(java.util.Iterator<T> iterator, int position)
-
fail
static void fail(java.lang.Throwable cause, java.lang.Object message)
-
entryComparator
public static <K,V> java.util.Comparator<java.util.Map.Entry<K,V>> entryComparator(java.util.Comparator<? super K> keyComparator)
-
testComparator
public static <T> void testComparator(java.util.Comparator<? super T> comparator, T... valuesInExpectedOrder)Asserts that all pairs ofTvalues withinvaluesInExpectedOrderare ordered consistently between their order withinvaluesInExpectedOrderand the order implied by the givencomparator.- See Also:
testComparator(Comparator, List)
-
testComparator
public static <T> void testComparator(java.util.Comparator<? super T> comparator, java.util.List<T> valuesInExpectedOrder)Asserts that all pairs ofTvalues withinvaluesInExpectedOrderare ordered consistently between their order withinvaluesInExpectedOrderand the order implied by the givencomparator.In detail, this method asserts
- reflexivity:
comparator.compare(t, t) = 0for alltinvaluesInExpectedOrder; and - consistency:
comparator.compare(ti, tj) < 0andcomparator.compare(tj, ti) > 0fori < j, whereti = valuesInExpectedOrder.get(i)andtj = valuesInExpectedOrder.get(j).
- reflexivity:
-
testCompareToAndEquals
public static <T extends java.lang.Comparable<? super T>> void testCompareToAndEquals(java.util.List<T> valuesInExpectedOrder)
-
misleadingSizeCollection
public static <T> java.util.Collection<T> misleadingSizeCollection(int delta)
Returns a collection that simulates concurrent modification by having its size method return incorrect values. This is useful for testing methods that must treat the return value from size() as a hint only.- Parameters:
delta- the difference between the true size of the collection and the values returned by the size method
-
nefariousMapEntry
public static <K,V> java.util.Map.Entry<K,V> nefariousMapEntry(K key, V value)Returns a "nefarious" map entry with the specified key and value, meaning an entry that is suitable for testing that map entries cannot be modified via a nefarious implementation of equals. This is used for testing unmodifiable collections of map entries; for example, it should not be possible to access the raw (modifiable) map entry via a nefarious equals method.
-
castOrCopyToList
static <E> java.util.List<E> castOrCopyToList(java.lang.Iterable<E> iterable)
-
orderEntriesByKey
public static <K extends java.lang.Comparable,V> java.lang.Iterable<java.util.Map.Entry<K,V>> orderEntriesByKey(java.util.List<java.util.Map.Entry<K,V>> insertionOrder)
-
getMethod
@GwtIncompatible public static java.lang.reflect.Method getMethod(java.lang.Class<?> clazz, java.lang.String name)
-
-