Class MultimapSubject
- java.lang.Object
-
- com.google.common.truth.Subject
-
- com.google.common.truth.MultimapSubject
-
- Direct Known Subclasses:
MultimapWithProtoValuesSubject
public class MultimapSubject extends Subject
Propositions forMultimap
subjects.- Author:
- Daniel Ploch, Kurt Alfred Kluever
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
MultimapSubject.UsingCorrespondence<A extends @Nullable Object,E extends @Nullable Object>
A partially specified check in which the actual values (i.e. the values of theMultimap
under test) are compared to expected values using aCorrespondence
.-
Nested classes/interfaces inherited from class com.google.common.truth.Subject
Subject.Factory<SubjectT extends Subject,ActualT>
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
MultimapSubject(FailureMetadata metadata, @Nullable Multimap<?,?> multimap)
Constructor for use by subclasses.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <A extends @Nullable Object,E extends @Nullable Object>
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 theMultimap
under test) are compared to expected values using the givenCorrespondence
.Ordered
containsAtLeast(@Nullable Object k0, @Nullable Object v0, @Nullable Object... rest)
Fails if the multimap does not contain at least the given key/value pairs.Ordered
containsAtLeastEntriesIn(Multimap<?,?> expectedMultimap)
void
containsEntry(@Nullable Object key, @Nullable Object value)
Fails if the multimap does not contain the given entry.Ordered
containsExactly()
Fails if the multimap is not empty.Ordered
containsExactly(@Nullable Object k0, @Nullable Object v0, @Nullable Object... rest)
Fails if the multimap does not contain exactly the given set of key/value pairs.Ordered
containsExactlyEntriesIn(Multimap<?,?> expectedMultimap)
void
containsKey(@Nullable Object key)
Fails if the multimap does not contain the given key.void
doesNotContainEntry(@Nullable Object key, @Nullable Object value)
Fails if the multimap contains the given entry.void
doesNotContainKey(@Nullable Object key)
Fails if the multimap contains the given key.void
hasSize(int expectedSize)
Fails if the multimap does not have the given size.void
isEmpty()
Fails if the multimap is not empty.void
isEqualTo(@Nullable Object other)
Checks that the value under test is equal to the given object.void
isNotEmpty()
Fails if the multimap is empty.IterableSubject
valuesForKey(@Nullable Object key)
-
Methods inherited from class com.google.common.truth.Subject
actualCustomStringRepresentation, check, equals, failWithActual, failWithActual, failWithoutActual, hashCode, ignoreCheck, isAnyOf, isIn, isInstanceOf, isNoneOf, isNotEqualTo, isNotIn, isNotInstanceOf, isNotNull, isNotSameInstanceAs, isNull, isSameInstanceAs, toString
-
-
-
-
Constructor Detail
-
MultimapSubject
protected MultimapSubject(FailureMetadata metadata, @Nullable Multimap<?,?> multimap)
Constructor for use by subclasses. If you want to create an instance of this class itself, callcheck(...)
.that(actual)
.
-
-
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(@Nullable Object key)
Fails if the multimap does not contain the given key.
-
doesNotContainKey
public final void doesNotContainKey(@Nullable Object key)
Fails if the multimap contains the given key.
-
containsEntry
public final void containsEntry(@Nullable Object key, @Nullable Object value)
Fails if the multimap does not contain the given entry.
-
doesNotContainEntry
public final void doesNotContainEntry(@Nullable Object key, @Nullable Object value)
Fails if the multimap contains the given entry.
-
valuesForKey
public IterableSubject valuesForKey(@Nullable Object key)
-
isEqualTo
public final void isEqualTo(@Nullable Object other)
Description copied from class:Subject
Checks that the value under test is 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 (
Double
orFloat
), 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 anequals
implementation 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 asequals
is implemented according to the contract for its type. - they are equal according to
-
containsExactlyEntriesIn
@CanIgnoreReturnValue public final Ordered containsExactlyEntriesIn(Multimap<?,?> expectedMultimap)
Fails if theMultimap
does 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
@CanIgnoreReturnValue public final Ordered containsAtLeastEntriesIn(Multimap<?,?> expectedMultimap)
Fails if theMultimap
does 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
@CanIgnoreReturnValue public final Ordered containsExactly()
Fails if the multimap is not empty.
-
containsExactly
@CanIgnoreReturnValue public final Ordered containsExactly(@Nullable Object k0, @Nullable Object v0, @Nullable 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
@CanIgnoreReturnValue public final Ordered containsAtLeast(@Nullable Object k0, @Nullable Object v0, @Nullable 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!
-
comparingValuesUsing
public <A extends @Nullable Object,E extends @Nullable Object> 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 theMultimap
under 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);
actualMultimap
is aMultimap<?, A>
(or, more generally, aMultimap<?, ? extends A>
),correspondence
is aCorrespondence<A, E>
, andexpectedValue
is 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
ClassCastException
if they encounter an actual value that is not of typeA
.
-
-