Class SubjectUtils

java.lang.Object
com.google.common.truth.SubjectUtils

final class SubjectUtils extends Object
Utility methods used in Subject implementors.
  • Field Details

  • Constructor Details

    • SubjectUtils

      private SubjectUtils()
  • Method Details

    • accumulate

      static <T> List<T> accumulate(T first, T second, T... rest)
    • countOf

      static <T> int countOf(T t, Iterable<T> items)
    • countDuplicates

      static String countDuplicates(Iterable<?> items)
    • entryString

      static String entryString(com.google.common.collect.Multiset.Entry<?> entry)
    • countDuplicatesToMultiset

      private static <T> SubjectUtils.NonHashingMultiset<T> countDuplicatesToMultiset(Iterable<T> items)
    • countDuplicatesAndAddTypeInfo

      static String countDuplicatesAndAddTypeInfo(Iterable<?> itemsIterable)
      Makes a String representation of items with collapsed duplicates and additional class info.

      Example: countDuplicatesAndAddTypeInfo([1, 2, 2, 3]) == "[1, 2 [3 copies]] (java.lang.Integer)" and countDuplicatesAndAddTypeInfo([1, 2L]) == "[1 (java.lang.Integer), 2 (java.lang.Long)]".

    • countDuplicatesAndMaybeAddTypeInfoReturnObject

      static SubjectUtils.DuplicateGroupedAndTyped countDuplicatesAndMaybeAddTypeInfoReturnObject(Iterable<?> itemsIterable, boolean addTypeInfo)
      Similar to countDuplicatesAndAddTypeInfo(java.lang.Iterable<?>) and countDuplicates(java.lang.Iterable<?>) but (a) only adds type info if requested and (b) returns a richer object containing the data.
    • iterableToStringWithTypeInfo

      static String iterableToStringWithTypeInfo(Iterable<?> itemsIterable)
      Makes a String representation of items with additional class info.

      Example: iterableToStringWithTypeInfo([1, 2]) == "[1, 2] (java.lang.Integer)" and iterableToStringWithTypeInfo([1, 2L]) == "[1 (java.lang.Integer), 2 (java.lang.Long)]".

    • retainMatchingToString

      static List<Object> retainMatchingToString(Iterable<?> items, Iterable<?> itemsToCheck)
      Returns a new collection containing all elements in items for which there exists at least one element in itemsToCheck that has the same toString() value without being equal.

      Example: retainMatchingToString([1L, 2L, 2L], [2, 3]) == [2L, 2L]

    • hasMatchingToStringPair

      static boolean hasMatchingToStringPair(Iterable<?> items1, Iterable<?> items2)
      Returns true if there is a pair of an item from items1 and one in items2 that has the same toString() value without being equal.

      Example: hasMatchingToStringPair([1L, 2L], [1]) == true

    • objectToTypeName

      static String objectToTypeName(Object item)
    • getHomogeneousTypeName

      private static com.google.common.base.Optional<String> getHomogeneousTypeName(Iterable<?> items)
      Returns the name of the single type of all given items or Optional.absent() if no such type exists.
    • addTypeInfoToEveryItem

      private static List<String> addTypeInfoToEveryItem(Iterable<?> items)
    • iterableToCollection

      static <T> Collection<T> iterableToCollection(Iterable<T> iterable)
    • iterableToList

      static <T> List<T> iterableToList(Iterable<T> iterable)
    • annotateEmptyStrings

      static <T> Iterable<T> annotateEmptyStrings(Iterable<T> items)
      Returns an iterable with all empty strings replaced by a non-empty human understandable indicator for an empty string.

      Returns the given iterable if it contains no empty strings.

    • concat

      @SafeVarargs static <E> com.google.common.collect.ImmutableList<E> concat(Iterable<? extends E>... inputs)
    • append

      static <E> com.google.common.collect.ImmutableList<E> append(E[] array, E object)
    • append

      static <E> com.google.common.collect.ImmutableList<E> append(com.google.common.collect.ImmutableList<? extends E> list, E object)
    • sandwich

      static <E> com.google.common.collect.ImmutableList<E> sandwich(E first, E[] array, E last)