Package com.google.common.truth
Class SubjectUtils
java.lang.Object
com.google.common.truth.SubjectUtils
Utility methods used in
Subject
implementors.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final class
Missing or unexpected values from a collection assertion, with equal objects grouped together and, in some cases, type information added.private static final class
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static <T> List<T>
accumulate
(T first, T second, T... rest) addTypeInfoToEveryItem
(Iterable<?> items) (package private) 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.(package private) static <E> com.google.common.collect.ImmutableList<E>
append
(com.google.common.collect.ImmutableList<? extends E> list, E object) (package private) static <E> com.google.common.collect.ImmutableList<E>
append
(E[] array, E object) (package private) static <E> com.google.common.collect.ImmutableList<E>
(package private) static String
countDuplicates
(Iterable<?> items) (package private) static String
countDuplicatesAndAddTypeInfo
(Iterable<?> itemsIterable) Makes a String representation ofitems
with collapsed duplicates and additional class info.(package private) static SubjectUtils.DuplicateGroupedAndTyped
countDuplicatesAndMaybeAddTypeInfoReturnObject
(Iterable<?> itemsIterable, boolean addTypeInfo) Similar tocountDuplicatesAndAddTypeInfo(java.lang.Iterable<?>)
andcountDuplicates(java.lang.Iterable<?>)
but (a) only adds type info if requested and (b) returns a richer object containing the data.private static <T> SubjectUtils.NonHashingMultiset<T>
countDuplicatesToMultiset
(Iterable<T> items) (package private) static <T> int
(package private) static String
entryString
(com.google.common.collect.Multiset.Entry<?> entry) private static com.google.common.base.Optional<String>
getHomogeneousTypeName
(Iterable<?> items) Returns the name of the single type of all given items orOptional.absent()
if no such type exists.(package private) static boolean
hasMatchingToStringPair
(Iterable<?> items1, Iterable<?> items2) Returns true if there is a pair of an item fromitems1
and one initems2
that has the sametoString()
value without being equal.(package private) static <T> Collection<T>
iterableToCollection
(Iterable<T> iterable) (package private) static <T> List<T>
iterableToList
(Iterable<T> iterable) (package private) static String
iterableToStringWithTypeInfo
(Iterable<?> itemsIterable) Makes a String representation ofitems
with additional class info.(package private) static String
objectToTypeName
(Object item) retainMatchingToString
(Iterable<?> items, Iterable<?> itemsToCheck) Returns a new collection containing all elements initems
for which there exists at least one element initemsToCheck
that has the sametoString()
value without being equal.(package private) static <E> com.google.common.collect.ImmutableList<E>
sandwich
(E first, E[] array, E last)
-
Field Details
-
HUMAN_UNDERSTANDABLE_EMPTY_STRING
- See Also:
-
-
Constructor Details
-
SubjectUtils
private SubjectUtils()
-
-
Method Details
-
accumulate
-
countOf
-
countDuplicates
-
entryString
-
countDuplicatesToMultiset
-
countDuplicatesAndAddTypeInfo
Makes a String representation ofitems
with collapsed duplicates and additional class info.Example:
countDuplicatesAndAddTypeInfo([1, 2, 2, 3]) == "[1, 2 [3 copies]] (java.lang.Integer)"
andcountDuplicatesAndAddTypeInfo([1, 2L]) == "[1 (java.lang.Integer), 2 (java.lang.Long)]"
. -
countDuplicatesAndMaybeAddTypeInfoReturnObject
static SubjectUtils.DuplicateGroupedAndTyped countDuplicatesAndMaybeAddTypeInfoReturnObject(Iterable<?> itemsIterable, boolean addTypeInfo) Similar tocountDuplicatesAndAddTypeInfo(java.lang.Iterable<?>)
andcountDuplicates(java.lang.Iterable<?>)
but (a) only adds type info if requested and (b) returns a richer object containing the data. -
iterableToStringWithTypeInfo
Makes a String representation ofitems
with additional class info.Example:
iterableToStringWithTypeInfo([1, 2]) == "[1, 2] (java.lang.Integer)"
anditerableToStringWithTypeInfo([1, 2L]) == "[1 (java.lang.Integer), 2 (java.lang.Long)]"
. -
retainMatchingToString
Returns a new collection containing all elements initems
for which there exists at least one element initemsToCheck
that has the sametoString()
value without being equal.Example:
retainMatchingToString([1L, 2L, 2L], [2, 3]) == [2L, 2L]
-
hasMatchingToStringPair
Returns true if there is a pair of an item fromitems1
and one initems2
that has the sametoString()
value without being equal.Example:
hasMatchingToStringPair([1L, 2L], [1]) == true
-
objectToTypeName
-
getHomogeneousTypeName
Returns the name of the single type of all given items orOptional.absent()
if no such type exists. -
addTypeInfoToEveryItem
-
iterableToCollection
-
iterableToList
-
annotateEmptyStrings
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)
-