Interface IterableOfProtosUsingCorrespondence<M extends Message>

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void contains​(@Nullable M expected)
      Checks that the subject contains at least one element that corresponds to the given expected element.
      void containsAnyIn​(Iterable<? extends M> expected)
      Checks that the subject contains at least one element that corresponds to at least one of the expected elements.
      void containsAnyIn​(M[] expected)
      Checks that the subject contains at least one element that corresponds to at least one of the expected elements.
      void containsAnyOf​(@Nullable M first, @Nullable M second, @Nullable M... rest)
      Checks that the subject contains at least one element that corresponds to at least one of the expected elements.
      Ordered containsAtLeast​(@Nullable M first, @Nullable M second, @Nullable M... rest)
      Checks that the subject contains elements that corresponds to all of the expected elements, i.e.
      Ordered containsAtLeastElementsIn​(Iterable<? extends M> expected)
      Checks that the subject contains elements that corresponds to all of the expected elements, i.e.
      Ordered containsAtLeastElementsIn​(M[] expected)
      Checks that the subject contains elements that corresponds to all of the expected elements, i.e.
      Ordered containsExactly​(@Nullable M... expected)
      Checks that subject contains exactly elements that correspond to the expected elements, i.e.
      Ordered containsExactlyElementsIn​(Iterable<? extends M> expected)
      Checks that subject contains exactly elements that correspond to the expected elements, i.e.
      Ordered containsExactlyElementsIn​(M[] expected)
      Checks that subject contains exactly elements that correspond to the expected elements, i.e.
      void containsNoneIn​(Iterable<? extends M> excluded)
      Checks that the subject contains no elements that correspond to any of the given elements.
      void containsNoneIn​(M[] excluded)
      Checks that the subject contains no elements that correspond to any of the given elements.
      void containsNoneOf​(@Nullable M firstExcluded, @Nullable M secondExcluded, @Nullable M... restOfExcluded)
      Checks that the subject contains no elements that correspond to any of the given elements.
      IterableOfProtosUsingCorrespondence<M> displayingDiffsPairedBy​(Function<? super M,​?> keyFunction)
      Specifies a way to pair up unexpected and missing elements in the message when an assertion fails.
      void doesNotContain​(@Nullable M excluded)
      Checks that none of the actual elements correspond to the given element.
    • Method Detail

      • displayingDiffsPairedBy

        IterableOfProtosUsingCorrespondence<M> displayingDiffsPairedBy​(Function<? super M,​?> keyFunction)
        Specifies a way to pair up unexpected and missing elements in the message when an assertion fails. For example:
        
         assertThat(actualFoos)
             .ignoringRepeatedFieldOrder()
             .ignoringFields(Foo.BAR_FIELD_NUMBER)
             .displayingDiffsPairedBy(Foo::getId)
             .containsExactlyElementsIn(expectedFoos);
         

        On assertions where it makes sense to do so, the elements are paired as follows: they are keyed by keyFunction, and if an unexpected element and a missing element have the same non-null key then the they are paired up. (Elements with null keys are not paired.) The failure message will show paired elements together, and a diff will be shown.

        The expected elements given in the assertion should be uniquely keyed by keyFunction. If multiple missing elements have the same key then the pairing will be skipped.

        Useful key functions will have the property that key equality is less strict than the already specified equality rules; i.e. given actual and expected values with keys actualKey and expectedKey, if actual and expected compare equal given the rest of the directives such as ignoringRepeatedFieldOrder and ignoringFields, then it is guaranteed that actualKey is equal to expectedKey, but there are cases where actualKey is equal to expectedKey but the direct comparison fails.

        Note that calling this method makes no difference to whether a test passes or fails, it just improves the message if it fails.

      • contains

        void contains​(@Nullable M expected)
        Checks that the subject contains at least one element that corresponds to the given expected element.
      • doesNotContain

        void doesNotContain​(@Nullable M excluded)
        Checks that none of the actual elements correspond to the given element.
      • containsExactly

        @CanIgnoreReturnValue
        Ordered containsExactly​(@Nullable M... expected)
        Checks that subject contains exactly elements that correspond to the expected elements, i.e. that there is a 1:1 mapping between the actual elements and the expected elements where each pair of elements correspond.

        To also test that the contents appear in the given order, make a call to inOrder() on the object returned by this method.

        To test that the iterable contains the same elements as an array, prefer containsExactlyElementsIn(Message[]). It makes clear that the given array is a list of elements, not an element itself.

      • containsExactlyElementsIn

        @CanIgnoreReturnValue
        Ordered containsExactlyElementsIn​(Iterable<? extends M> expected)
        Checks that subject contains exactly elements that correspond to the expected elements, i.e. that there is a 1:1 mapping between the actual elements and the expected elements where each pair of elements correspond.

        To also test that the contents appear in the given order, make a call to inOrder() on the object returned by this method.

      • containsExactlyElementsIn

        @CanIgnoreReturnValue
        Ordered containsExactlyElementsIn​(M[] expected)
        Checks that subject contains exactly elements that correspond to the expected elements, i.e. that there is a 1:1 mapping between the actual elements and the expected elements where each pair of elements correspond.

        To also test that the contents appear in the given order, make a call to inOrder() on the object returned by this method.

      • containsAtLeast

        @CanIgnoreReturnValue
        Ordered containsAtLeast​(@Nullable M first,
                                @Nullable M second,
                                @Nullable M... rest)
        Checks that the subject contains elements that corresponds to all of the expected elements, i.e. that there is a 1:1 mapping between any subset of the actual elements and the expected elements where each pair of elements correspond.

        To also test that the contents appear in the given order, make a call to inOrder() on the object returned by this method. The elements must appear in the given order within the subject, but they are not required to be consecutive.

      • containsAtLeastElementsIn

        @CanIgnoreReturnValue
        Ordered containsAtLeastElementsIn​(Iterable<? extends M> expected)
        Checks that the subject contains elements that corresponds to all of the expected elements, i.e. that there is a 1:1 mapping between any subset of the actual elements and the expected elements where each pair of elements correspond.

        To also test that the contents appear in the given order, make a call to inOrder() on the object returned by this method. The elements must appear in the given order within the subject, but they are not required to be consecutive.

      • containsAtLeastElementsIn

        @CanIgnoreReturnValue
        Ordered containsAtLeastElementsIn​(M[] expected)
        Checks that the subject contains elements that corresponds to all of the expected elements, i.e. that there is a 1:1 mapping between any subset of the actual elements and the expected elements where each pair of elements correspond.

        To also test that the contents appear in the given order, make a call to inOrder() on the object returned by this method. The elements must appear in the given order within the subject, but they are not required to be consecutive.

      • containsAnyOf

        void containsAnyOf​(@Nullable M first,
                           @Nullable M second,
                           @Nullable M... rest)
        Checks that the subject contains at least one element that corresponds to at least one of the expected elements.
      • containsAnyIn

        void containsAnyIn​(Iterable<? extends M> expected)
        Checks that the subject contains at least one element that corresponds to at least one of the expected elements.
      • containsAnyIn

        void containsAnyIn​(M[] expected)
        Checks that the subject contains at least one element that corresponds to at least one of the expected elements.
      • containsNoneOf

        void containsNoneOf​(@Nullable M firstExcluded,
                            @Nullable M secondExcluded,
                            @Nullable M... restOfExcluded)
        Checks that the subject contains no elements that correspond to any of the given elements. (Duplicates are irrelevant to this test, which fails if any of the subject elements correspond to any of the given elements.)
      • containsNoneIn

        void containsNoneIn​(Iterable<? extends M> excluded)
        Checks that the subject contains no elements that correspond to any of the given elements. (Duplicates are irrelevant to this test, which fails if any of the subject elements correspond to any of the given elements.)
      • containsNoneIn

        void containsNoneIn​(M[] excluded)
        Checks that the subject contains no elements that correspond to any of the given elements. (Duplicates are irrelevant to this test, which fails if any of the subject elements correspond to any of the given elements.)