Class Helpers


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

    • Method Detail

      • copyToList

        public static <E> List<E> copyToList​(E[] elements)
      • copyToSet

        public static <E> Set<E> copyToSet​(E[] elements)
      • testComparator

        public static <T> 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(Comparator, List)
      • testComparator

        public static <T> 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).
      • misleadingSizeCollection

        public static <T> 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> 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.