Class MapSubject
Map
subjects.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
private class
private static class
final class
A partially specified check in which the actual values (i.e.private static class
private static interface
Nested classes/interfaces inherited from class com.google.common.truth.Subject
Subject.EqualityCheck, Subject.Factory<SubjectT extends Subject,
ActualT> -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Map<?,
?> private static final Ordered
Ordered implementation that does nothing because an earlier check already caused a failure.private static final MapSubject.ValueTester<Object,
Object> private static final Ordered
Ordered implementation that does nothing because it's already known to be true.private static final com.google.common.base.Function<MapSubject.ValueDifference<Object,
Object>, String> A formatting function for value differences when compared for equality. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
MapSubject
(FailureMetadata metadata, Map<?, ?> map) Constructor for use by subclasses. -
Method Summary
Modifier and TypeMethodDescriptionaccumulateMap
(String functionName, Object k0, Object v0, Object... rest) addKeyTypes
(Map<?, ?> in) final <A,
E> MapSubject.UsingCorrespondence<A, E> comparingValuesUsing
(Correspondence<? super A, ? super E> correspondence) Starts a method chain for a check in which the actual values (i.e.final Ordered
containsAtLeast
(Object k0, Object v0, Object... rest) final Ordered
containsAtLeastEntriesIn
(Map<?, ?> expectedMap) Fails if the map does not contain at least the given set of entries in the given map.private boolean
containsEntriesInAnyOrder
(Map<?, ?> expectedMap, String failVerb, boolean allowUnexpected) final void
containsEntry
(Object key, Object value) Fails if the map does not contain the given entry.final Ordered
Fails if the map is not empty.final Ordered
containsExactly
(Object k0, Object v0, Object... rest) Fails if the map does not contain exactly the given set of key/value pairs.final Ordered
containsExactlyEntriesIn
(Map<?, ?> expectedMap) Fails if the map does not contain exactly the given set of entries in the given map.final void
containsKey
(Object key) Fails if the map does not contain the given key.final void
doesNotContainEntry
(Object key, Object value) Fails if the map contains the given entry.final void
doesNotContainKey
(Object key) Fails if the map contains the given key.final void
hasSize
(int expectedSize) Fails if the map does not have the given size.final void
isEmpty()
Fails if the map is not empty.final void
Fails if the subject is not equal to the given object.final void
Fails if the map is empty.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 Details
-
actual
-
EQUALITY
-
VALUE_DIFFERENCE_FORMAT
private static final com.google.common.base.Function<MapSubject.ValueDifference<Object,Object>, VALUE_DIFFERENCE_FORMATString> A formatting function for value differences when compared for equality. -
IN_ORDER
Ordered implementation that does nothing because it's already known to be true. -
ALREADY_FAILED
Ordered implementation that does nothing because an earlier check already caused a failure.
-
-
Constructor Details
-
MapSubject
Constructor for use by subclasses. If you want to create an instance of this class itself, callcheck(...)
.that(actual)
.
-
-
Method Details
-
isEqualTo
Description copied from class:Subject
Fails 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 (
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
-
isEmpty
public final void isEmpty()Fails if the map is not empty. -
isNotEmpty
public final void isNotEmpty()Fails if the map is empty. -
hasSize
public final void hasSize(int expectedSize) Fails if the map does not have the given size. -
containsKey
Fails if the map does not contain the given key. -
doesNotContainKey
Fails if the map contains the given key. -
containsEntry
Fails if the map does not contain the given entry. -
doesNotContainEntry
Fails if the map contains the given entry. -
containsExactly
Fails if the map is not empty. -
containsExactly
Fails if the map 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!
The arguments must not contain duplicate keys.
-
containsAtLeast
-
accumulateMap
-
containsExactlyEntriesIn
Fails if the map does not contain exactly the given set of entries in the given map. -
containsAtLeastEntriesIn
Fails if the map does not contain at least the given set of entries in the given map. -
containsEntriesInAnyOrder
-
addKeyTypes
-
comparingValuesUsing
public final <A,E> MapSubject.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 theMap
under test) are compared to expected values using the givenCorrespondence
. The actual values must be of typeA
, the expected values must be of typeE
. The check is actually executed by continuing the method chain. For example:
whereassertThat(actualMap) .comparingValuesUsing(correspondence) .containsEntry(expectedKey, expectedValue);
actualMap
is aMap<?, A>
(or, more generally, aMap<?, ? 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
or an expected value that is not of typeE
.
-