Package com.google.common.truth
Class SubjectUtils
- java.lang.Object
-
- com.google.common.truth.SubjectUtils
-
final class SubjectUtils extends java.lang.Object
Utility methods used inSubject
implementors.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
SubjectUtils.DuplicateGroupedAndTyped
Missing or unexpected values from a collection assertion, with equal objects grouped together and, in some cases, type information added.private static class
SubjectUtils.NonHashingMultiset<E>
-
Field Summary
Fields Modifier and Type Field Description (package private) static java.lang.String
HUMAN_UNDERSTANDABLE_EMPTY_STRING
-
Constructor Summary
Constructors Modifier Constructor Description private
SubjectUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static <T> java.util.List<T>
accumulate(T first, T second, T... rest)
private static java.util.List<java.lang.String>
addTypeInfoToEveryItem(java.lang.Iterable<?> items)
(package private) static <T> java.lang.Iterable<T>
annotateEmptyStrings(java.lang.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>
concat(java.lang.Iterable<? extends E>... inputs)
(package private) static java.lang.String
countDuplicates(java.lang.Iterable<?> items)
(package private) static java.lang.String
countDuplicatesAndAddTypeInfo(java.lang.Iterable<?> itemsIterable)
Makes a String representation ofitems
with collapsed duplicates and additional class info.(package private) static SubjectUtils.DuplicateGroupedAndTyped
countDuplicatesAndMaybeAddTypeInfoReturnObject(java.lang.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(java.lang.Iterable<T> items)
(package private) static <T> int
countOf(T t, java.lang.Iterable<T> items)
(package private) static java.lang.String
entryString(com.google.common.collect.Multiset.Entry<?> entry)
private static com.google.common.base.Optional<java.lang.String>
getHomogeneousTypeName(java.lang.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(java.lang.Iterable<?> items1, java.lang.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> java.util.Collection<T>
iterableToCollection(java.lang.Iterable<T> iterable)
(package private) static <T> java.util.List<T>
iterableToList(java.lang.Iterable<T> iterable)
(package private) static java.lang.String
iterableToStringWithTypeInfo(java.lang.Iterable<?> itemsIterable)
Makes a String representation ofitems
with additional class info.(package private) static java.lang.String
objectToTypeName(java.lang.Object item)
(package private) static java.util.List<java.lang.Object>
retainMatchingToString(java.lang.Iterable<?> items, java.lang.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 Detail
-
HUMAN_UNDERSTANDABLE_EMPTY_STRING
static final java.lang.String HUMAN_UNDERSTANDABLE_EMPTY_STRING
- See Also:
- Constant Field Values
-
-
Method Detail
-
accumulate
static <T> java.util.List<T> accumulate(T first, T second, T... rest)
-
countOf
static <T> int countOf(T t, java.lang.Iterable<T> items)
-
countDuplicates
static java.lang.String countDuplicates(java.lang.Iterable<?> items)
-
entryString
static java.lang.String entryString(com.google.common.collect.Multiset.Entry<?> entry)
-
countDuplicatesToMultiset
private static <T> SubjectUtils.NonHashingMultiset<T> countDuplicatesToMultiset(java.lang.Iterable<T> items)
-
countDuplicatesAndAddTypeInfo
static java.lang.String countDuplicatesAndAddTypeInfo(java.lang.Iterable<?> itemsIterable)
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(java.lang.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
static java.lang.String iterableToStringWithTypeInfo(java.lang.Iterable<?> itemsIterable)
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
static java.util.List<java.lang.Object> retainMatchingToString(java.lang.Iterable<?> items, java.lang.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.Example:
retainMatchingToString([1L, 2L, 2L], [2, 3]) == [2L, 2L]
-
hasMatchingToStringPair
static boolean hasMatchingToStringPair(java.lang.Iterable<?> items1, java.lang.Iterable<?> items2)
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
static java.lang.String objectToTypeName(java.lang.Object item)
-
getHomogeneousTypeName
private static com.google.common.base.Optional<java.lang.String> getHomogeneousTypeName(java.lang.Iterable<?> items)
Returns the name of the single type of all given items orOptional.absent()
if no such type exists.
-
addTypeInfoToEveryItem
private static java.util.List<java.lang.String> addTypeInfoToEveryItem(java.lang.Iterable<?> items)
-
iterableToCollection
static <T> java.util.Collection<T> iterableToCollection(java.lang.Iterable<T> iterable)
-
iterableToList
static <T> java.util.List<T> iterableToList(java.lang.Iterable<T> iterable)
-
annotateEmptyStrings
static <T> java.lang.Iterable<T> annotateEmptyStrings(java.lang.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(java.lang.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)
-
-