Class MultimapSubject

    • Constructor Detail

      • MultimapSubject

        protected MultimapSubject​(FailureMetadata metadata,
                                  @Nullable Multimap<?,​?> actual)
        The constructor is for use by subclasses only. If you want to create an instance of this class itself, call check(...).that(actual).
    • Method Detail

      • isEmpty

        public final void isEmpty()
        Checks that the actual multimap is empty.
      • isNotEmpty

        public final void isNotEmpty()
        Checks that the actual multimap is not empty.
      • hasSize

        public final void hasSize​(int size)
        Checks that the actual multimap has the given size.
      • containsKey

        public final void containsKey​(@Nullable Object key)
        Checks that the actual multimap contains the given key.
      • doesNotContainKey

        public final void doesNotContainKey​(@Nullable Object key)
        Checks that the actual multimap does not contain the given key.
      • containsEntry

        public final void containsEntry​(@Nullable Object key,
                                        @Nullable Object value)
        Checks that the actual multimap contains the given entry.
      • doesNotContainEntry

        public final void doesNotContainEntry​(@Nullable Object key,
                                              @Nullable Object value)
        Checks that the actual multimap does not contain the given entry.
      • valuesForKey

        public IterableSubject valuesForKey​(@Nullable Object key)
        Returns a Subject for making assertions about the values for the given key within the Multimap.

        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. (There is one small exception: This method does check whether the actual value is null, failing if so.)

      • isEqualTo

        public final void isEqualTo​(@Nullable Object expected)
        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:

        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 an equals 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 as equals is implemented according to the contract for its type.

        Overrides:
        isEqualTo in class Subject
      • containsExactlyEntriesIn

        @CanIgnoreReturnValue
        public final Ordered containsExactlyEntriesIn​(@Nullable Multimap<?,​?> expected)
        Checks that the actual multimap contains precisely the same entries as the argument Multimap.

        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​(@Nullable Multimap<?,​?> expected)
        Checks that the actual multimap contains at least the entries in the argument Multimap.

        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​(@Nullable Object k0,
                                             @Nullable Object v0,
                                             @Nullable Object... rest)
        Checks that the actual multimap contains 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)
        Checks that the actual multimap contains 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 ObjectMultimapSubject.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 the Multimap under test) are compared to expected values using the given Correspondence. The actual values must be of type A, and the expected values must be of type E. The check is actually executed by continuing the method chain. For example:
        
         assertThat(actualMultimap)
             .comparingValuesUsing(correspondence)
             .containsEntry(expectedKey, expectedValue);
         
        where actualMultimap is a Multimap<?, A> (or, more generally, a Multimap<?, ? extends A>), correspondence is a Correspondence<A, E>, and expectedValue is an E.

        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 multimap that is not of type A.