Class Helpers

java.lang.Object
com.google.common.collect.testing.Helpers

@GwtCompatible(emulated=true) @NullMarked public class Helpers extends Object
  • Constructor Details

    • Helpers

      public Helpers()
  • Method Details

    • copyToList

      public static <E extends @Nullable Object> List<E> copyToList(Iterable<? extends E> elements)
    • copyToList

      public static <E extends @Nullable Object> List<E> copyToList(E[] elements)
    • copyToSet

      public static <E extends @Nullable Object> Set<E> copyToSet(Iterable<? extends E> elements)
    • copyToSet

      public static <E extends @Nullable Object> Set<E> copyToSet(E[] elements)
    • mapEntry

      public static <K extends @Nullable Object, V extends @Nullable Object> Map.Entry<K,V> mapEntry(K key, V value)
    • assertEmpty

      public static void assertEmpty(Iterable<?> iterable)
    • assertEmpty

      public static void assertEmpty(Map<?,?> map)
    • assertEqualInOrder

      public static void assertEqualInOrder(Iterable<?> expected, Iterable<?> actual)
    • assertContentsInOrder

      public static void assertContentsInOrder(Iterable<?> actual, Object... expected)
    • assertEqualIgnoringOrder

      public static void assertEqualIgnoringOrder(Iterable<?> expected, Iterable<?> actual)
    • assertContentsAnyOrder

      public static void assertContentsAnyOrder(Iterable<?> actual, Object... expected)
    • assertContains

      public static void assertContains(Iterable<?> actual, Object expected)
    • assertContainsAllOf

      public static void assertContainsAllOf(Iterable<?> actual, Object... expected)
    • addAll

      @CanIgnoreReturnValue public static <E extends @Nullable Object> boolean addAll(Collection<E> addTo, Iterable<? extends E> elementsToAdd)
    • entryComparator

      public static <K extends @Nullable Object, V extends @Nullable Object> Comparator<Map.Entry<K,V>> entryComparator(@Nullable Comparator<? super K> keyComparator)
    • testComparator

      public static <T extends @Nullable Object> void testComparator(Comparator<? super T> comparator, T... valuesInExpectedOrder)
      Asserts that all pairs of T values within valuesInExpectedOrder are ordered consistently between their order within valuesInExpectedOrder and the order implied by the given comparator.
      See Also:
    • testComparator

      public static <T extends @Nullable Object> void testComparator(Comparator<? super T> comparator, List<T> valuesInExpectedOrder)
      Asserts that all pairs of T values within valuesInExpectedOrder are ordered consistently between their order within valuesInExpectedOrder and the order implied by the given comparator.

      In detail, this method asserts

      • reflexivity: comparator.compare(t, t) = 0 for all t in valuesInExpectedOrder; and
      • consistency: comparator.compare(ti, tj) < 0 and comparator.compare(tj, ti) > 0 for i < j, where ti = valuesInExpectedOrder.get(i) and tj = valuesInExpectedOrder.get(j).
    • testCompareToAndEquals

      public static <T extends Comparable<? super T>> void testCompareToAndEquals(List<T> valuesInExpectedOrder)
    • misleadingSizeCollection

      public static <T extends @Nullable Object> 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 extends @Nullable Object, V extends @Nullable Object> 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.
    • orderEntriesByKey

      public static <K extends Comparable, V extends @Nullable Object> Iterable<Map.Entry<K,V>> orderEntriesByKey(List<Map.Entry<K,V>> insertionOrder)
    • getMethod

      @GwtIncompatible public static Method getMethod(Class<?> clazz, String name)