Class MultimapSubject
- java.lang.Object
-
- com.google.common.truth.Subject
-
- com.google.common.truth.MultimapSubject
-
public class MultimapSubject extends Subject
Propositions forMultimapsubjects.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classMultimapSubject.EntryCorrespondence<K,A,E>private static classMultimapSubject.IterableEntriesprivate classMultimapSubject.MultimapInOrderclassMultimapSubject.UsingCorrespondence<A,E>A partially specified check in which the actual values (i.e.-
Nested classes/interfaces inherited from class com.google.common.truth.Subject
Subject.EqualityCheck, Subject.Factory<SubjectT extends Subject,ActualT>
-
-
Field Summary
Fields Modifier and Type Field Description private com.google.common.collect.Multimap<?,?>actualprivate static OrderedALREADY_FAILEDOrdered implementation that does nothing because an earlier check already caused a failure.
-
Constructor Summary
Constructors Modifier Constructor Description protectedMultimapSubject(FailureMetadata metadata, com.google.common.collect.Multimap<?,?> multimap)Constructor for use by subclasses.(package private)MultimapSubject(FailureMetadata metadata, com.google.common.collect.Multimap<?,?> multimap, java.lang.String typeDescription)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static com.google.common.collect.Multimap<java.lang.Object,java.lang.Object>accumulateMultimap(java.lang.Object k0, java.lang.Object v0, java.lang.Object... rest)private static booleanadvanceToFind(java.util.Iterator<?> iterator, java.lang.Object value)Advances the iterator until it either returns value, or has no more elements.private static com.google.common.collect.Multimap<?,?>annotateEmptyStringsMultimap(com.google.common.collect.Multimap<?,?> multimap)Returns a multimap with all empty strings (as keys or values) replaced by a non-empty human understandable indicator for an empty string.<A,E>
MultimapSubject.UsingCorrespondence<A,E>comparingValuesUsing(Correspondence<? super A,? super E> correspondence)Starts a method chain for a check in which the actual values (i.e.OrderedcontainsAtLeast(java.lang.Object k0, java.lang.Object v0, java.lang.Object... rest)Fails if the multimap does not contain at least the given key/value pairs.OrderedcontainsAtLeastEntriesIn(com.google.common.collect.Multimap<?,?> expectedMultimap)Fails if theMultimapdoes not contain at least the entries in the argumentMultimap.voidcontainsEntry(java.lang.Object key, java.lang.Object value)Fails if the multimap does not contain the given entry.OrderedcontainsExactly()Fails if the multimap is not empty.OrderedcontainsExactly(java.lang.Object k0, java.lang.Object v0, java.lang.Object... rest)Fails if the multimap does not contain exactly the given set of key/value pairs.OrderedcontainsExactlyEntriesIn(com.google.common.collect.Multimap<?,?> expectedMultimap)Fails if theMultimapdoes not contain precisely the same entries as the argumentMultimap.voidcontainsKey(java.lang.Object key)Fails if the multimap does not contain the given key.private static java.lang.StringcountDuplicatesMultimap(com.google.common.collect.Multimap<?,?> multimap)private static com.google.common.collect.ListMultimap<?,?>difference(com.google.common.collect.Multimap<?,?> minuend, com.google.common.collect.Multimap<?,?> subtrahend)private static java.util.List<?>difference(java.util.List<?> minuend, java.util.List<?> subtrahend)voiddoesNotContainEntry(java.lang.Object key, java.lang.Object value)Fails if the multimap contains the given entry.voiddoesNotContainKey(java.lang.Object key)Fails if the multimap contains the given key.private static <V> java.util.Collection<V>get(com.google.common.collect.Multimap<?,V> multimap, java.lang.Object key)voidhasSize(int expectedSize)Fails if the multimap does not have the given size.voidisEmpty()Fails if the multimap is not empty.voidisEqualTo(java.lang.Object other)Fails if the subject is not equal to the given object.voidisNotEmpty()Fails if the multimap is empty.private Subject.Factory<IterableSubject,java.lang.Iterable<?>>iterableEntries()IterableSubjectvaluesForKey(java.lang.Object key)Returns a context-awareSubjectfor making assertions about the values for the given key within theMultimap.-
Methods inherited from class com.google.common.truth.Subject
actual, actualCustomStringRepresentation, actualCustomStringRepresentationForPackageMembersToCall, butWas, check, check, checkNoNeedToDisplayBothValues, equals, fail, fail, fail, failEqualityCheckForEqualsWithoutDescription, failWithActual, failWithActual, failWithActual, failWithActual, failWithBadResults, failWithCustomSubject, failWithoutActual, failWithoutActual, failWithoutActual, failWithoutActual, failWithoutSubject, hashCode, ignoreCheck, isAnyOf, isIn, isInstanceOf, isNoneOf, isNotEqualTo, isNotIn, isNotInstanceOf, isNotNull, isNotSameInstanceAs, isNull, isSameInstanceAs, toString, typeDescription
-
-
-
-
Field Detail
-
ALREADY_FAILED
private static final Ordered ALREADY_FAILED
Ordered implementation that does nothing because an earlier check already caused a failure.
-
actual
private final com.google.common.collect.Multimap<?,?> actual
-
-
Constructor Detail
-
MultimapSubject
protected MultimapSubject(FailureMetadata metadata, com.google.common.collect.Multimap<?,?> multimap)
Constructor for use by subclasses. If you want to create an instance of this class itself, callcheck(...).that(actual).
-
MultimapSubject
MultimapSubject(FailureMetadata metadata, com.google.common.collect.Multimap<?,?> multimap, java.lang.String typeDescription)
-
-
Method Detail
-
isEmpty
public final void isEmpty()
Fails if the multimap is not empty.
-
isNotEmpty
public final void isNotEmpty()
Fails if the multimap is empty.
-
hasSize
public final void hasSize(int expectedSize)
Fails if the multimap does not have the given size.
-
containsKey
public final void containsKey(java.lang.Object key)
Fails if the multimap does not contain the given key.
-
doesNotContainKey
public final void doesNotContainKey(java.lang.Object key)
Fails if the multimap contains the given key.
-
containsEntry
public final void containsEntry(java.lang.Object key, java.lang.Object value)Fails if the multimap does not contain the given entry.
-
doesNotContainEntry
public final void doesNotContainEntry(java.lang.Object key, java.lang.Object value)Fails if the multimap contains the given entry.
-
valuesForKey
public IterableSubject valuesForKey(java.lang.Object key)
Returns a context-awareSubjectfor making assertions about the values for the given key within theMultimap.This method performs no checks on its own and cannot cause test failures. Subsequent assertions must be chained onto this method call to test properties of the
Multimap.
-
isEqualTo
public final void isEqualTo(java.lang.Object other)
Description copied from class:SubjectFails if the subject is not equal to the given object. For the purposes of this comparison, two objects are equal if any of the following is true:- they are equal according to
Objects.equal(java.lang.Object, java.lang.Object) - they are arrays and are considered equal by the appropriate
Arrays.equals(long[], long[])overload - they are boxed integer types (
Byte,Short,Character,Integer, orLong) and they are numerically equal when converted toLong. - the actual value is a boxed floating-point type (
DoubleorFloat), the expected value is anInteger, and the two are numerically equal when converted toDouble. (This allowsassertThat(someDouble).isEqualTo(0)to pass.)
Note: This method does not test the
Object.equals(java.lang.Object)implementation itself; it assumes that method is functioning correctly according to its contract. Testing anequalsimplementation requires a utility such as guava-testlib's EqualsTester.In some cases, this method might not even call
equals. It may instead perform other tests that will return the same result as long asequalsis implemented according to the contract for its type. - they are equal according to
-
containsExactlyEntriesIn
public final Ordered containsExactlyEntriesIn(com.google.common.collect.Multimap<?,?> expectedMultimap)
Fails if theMultimapdoes not contain precisely the same entries as the argumentMultimap.A subsequent call to
Ordered.inOrder()may be made if the caller wishes to verify that the two multimaps iterate fully in the same order. That is, their key sets iterate in the same order, and the value collections for each key iterate in the same order.
-
containsAtLeastEntriesIn
public final Ordered containsAtLeastEntriesIn(com.google.common.collect.Multimap<?,?> expectedMultimap)
Fails if theMultimapdoes not contain at least the entries in the argumentMultimap.A subsequent call to
Ordered.inOrder()may be made if the caller wishes to verify that the entries are present in the same order as given. That is, the keys are present in the given order in the key set, and the values for each key are present in the given order order in the value collections.
-
containsExactly
public final Ordered containsExactly()
Fails if the multimap is not empty.
-
containsExactly
public final Ordered containsExactly(java.lang.Object k0, java.lang.Object v0, java.lang.Object... rest)
Fails if the multimap does not contain exactly the given set of key/value pairs.Warning: the use of varargs means that we cannot guarantee an equal number of key/value pairs at compile time. Please make sure you provide varargs in key/value pairs!
-
containsAtLeast
public final Ordered containsAtLeast(java.lang.Object k0, java.lang.Object v0, java.lang.Object... rest)
Fails if the multimap does not contain at least the given key/value pairs.Warning: the use of varargs means that we cannot guarantee an equal number of key/value pairs at compile time. Please make sure you provide varargs in key/value pairs!
-
accumulateMultimap
private static com.google.common.collect.Multimap<java.lang.Object,java.lang.Object> accumulateMultimap(java.lang.Object k0, java.lang.Object v0, java.lang.Object... rest)
-
iterableEntries
private Subject.Factory<IterableSubject,java.lang.Iterable<?>> iterableEntries()
-
advanceToFind
private static boolean advanceToFind(java.util.Iterator<?> iterator, java.lang.Object value)Advances the iterator until it either returns value, or has no more elements.Returns true if the value was found, false if the end was reached before finding it.
This is basically the same as
Iterables.contains(java.lang.Iterable<? extends java.lang.Object>, java.lang.Object), but where the contract explicitly states that the iterator isn't advanced beyond the value if the value is found.
-
get
private static <V> java.util.Collection<V> get(com.google.common.collect.Multimap<?,V> multimap, java.lang.Object key)
-
difference
private static com.google.common.collect.ListMultimap<?,?> difference(com.google.common.collect.Multimap<?,?> minuend, com.google.common.collect.Multimap<?,?> subtrahend)
-
difference
private static java.util.List<?> difference(java.util.List<?> minuend, java.util.List<?> subtrahend)
-
countDuplicatesMultimap
private static java.lang.String countDuplicatesMultimap(com.google.common.collect.Multimap<?,?> multimap)
-
annotateEmptyStringsMultimap
private static com.google.common.collect.Multimap<?,?> annotateEmptyStringsMultimap(com.google.common.collect.Multimap<?,?> multimap)
Returns a multimap with all empty strings (as keys or values) replaced by a non-empty human understandable indicator for an empty string.Returns the given multimap if it contains no empty strings.
-
comparingValuesUsing
public <A,E> MultimapSubject.UsingCorrespondence<A,E> comparingValuesUsing(Correspondence<? super A,? super E> correspondence)
Starts a method chain for a check in which the actual values (i.e. the values of theMultimapunder test) are compared to expected values using the givenCorrespondence. The actual values must be of typeA, and the expected values must be of typeE. The check is actually executed by continuing the method chain. For example:
whereassertThat(actualMultimap) .comparingValuesUsing(correspondence) .containsEntry(expectedKey, expectedValue);actualMultimapis aMultimap<?, A>(or, more generally, aMultimap<?, ? extends A>),correspondenceis aCorrespondence<A, E>, andexpectedValueis anE.Note that keys will always be compared with regular object equality (
Object.equals(java.lang.Object)).Any of the methods on the returned object may throw
ClassCastExceptionif they encounter an actual value that is not of typeA.
-
-