Class Iterables


  • public class Iterables
    extends java.lang.Object
    Reusable assertions for Iterables.
    • Constructor Detail

      • Iterables

        Iterables()
    • Method Detail

      • getComparator

        public java.util.Comparator<?> getComparator()
      • assertNullOrEmpty

        public void assertNullOrEmpty​(AssertionInfo info,
                                      java.lang.Iterable<?> actual)
        Asserts that the given Iterable is null or empty.
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        Throws:
        java.lang.AssertionError - if the given Iterable is not null *and* contains one or more elements.
      • assertEmpty

        public void assertEmpty​(AssertionInfo info,
                                java.lang.Iterable<?> actual)
        Asserts that the given Iterable is empty.
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        Throws:
        java.lang.AssertionError - if the given Iterable is null.
        java.lang.AssertionError - if the given Iterable is not empty.
      • assertNotEmpty

        public void assertNotEmpty​(AssertionInfo info,
                                   java.lang.Iterable<?> actual)
        Asserts that the given Iterable is not empty.
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        Throws:
        java.lang.AssertionError - if the given Iterable is null.
        java.lang.AssertionError - if the given Iterable is empty.
      • assertHasSize

        public void assertHasSize​(AssertionInfo info,
                                  java.lang.Iterable<?> actual,
                                  int expectedSize)
        Asserts that the number of elements in the given Iterable is equal to the expected one.
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        expectedSize - the expected size of actual.
        Throws:
        java.lang.AssertionError - if the given Iterable is null.
        java.lang.AssertionError - if the number of elements in the given Iterable is different from the expected one.
      • assertHasOnlyOneElementSatisfying

        public <T> void assertHasOnlyOneElementSatisfying​(AssertionInfo info,
                                                          java.lang.Iterable<? extends T> actual,
                                                          java.util.function.Consumer<? super T> consumer)
        Asserts that the unique element of the Iterable satisfies the given assertions expressed as a Consumer,
        Type Parameters:
        T - the type of elements in actual.
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        consumer - the given requirements.
        Throws:
        java.lang.AssertionError - if the Iterable does not have a unique element.
        java.lang.AssertionError - if the Iterable's unique element does not satisfies the given assertions.
      • assertHasSizeGreaterThan

        public void assertHasSizeGreaterThan​(AssertionInfo info,
                                             java.lang.Iterable<?> actual,
                                             int boundary)
        Asserts that the number of elements in the given Iterable is greater than the boundary.
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        boundary - the given value to compare the size of actual to.
        Throws:
        java.lang.AssertionError - if the given Iterable is null.
        java.lang.AssertionError - if the number of elements in the given Iterable is greater than the boundary.
      • assertHasSizeGreaterThanOrEqualTo

        public void assertHasSizeGreaterThanOrEqualTo​(AssertionInfo info,
                                                      java.lang.Iterable<?> actual,
                                                      int boundary)
        Asserts that the number of elements in the given Iterable is greater than or equal to the boundary.
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        boundary - the given value to compare the size of actual to.
        Throws:
        java.lang.AssertionError - if the given Iterable is null.
        java.lang.AssertionError - if the number of elements in the given Iterable is greater than or equal to the boundary.
      • assertHasSizeLessThan

        public void assertHasSizeLessThan​(AssertionInfo info,
                                          java.lang.Iterable<?> actual,
                                          int boundary)
        Asserts that the number of elements in the given Iterable is less than the boundary.
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        boundary - the given value to compare the size of actual to.
        Throws:
        java.lang.AssertionError - if the given Iterable is null.
        java.lang.AssertionError - if the number of elements in the given Iterable is less than the expected one.
      • assertHasSizeLessThanOrEqualTo

        public void assertHasSizeLessThanOrEqualTo​(AssertionInfo info,
                                                   java.lang.Iterable<?> actual,
                                                   int boundary)
        Asserts that the number of elements in the given Iterable is less than or equal to the boundary.
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        boundary - the given value to compare the size of actual to.
        Throws:
        java.lang.AssertionError - if the given Iterable is null.
        java.lang.AssertionError - if the number of elements in the given Iterable is less than or equal to the boundary.
      • assertHasSizeBetween

        public void assertHasSizeBetween​(AssertionInfo info,
                                         java.lang.Iterable<?> actual,
                                         int lowerBoundary,
                                         int higherBoundary)
        Asserts that the number of elements in the given Iterable is between the given lower and higher boundary (inclusive).
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        lowerBoundary - the lower boundary compared to which actual size should be greater than or equal to.
        higherBoundary - the higher boundary compared to which actual size should be less than or equal to.
        Throws:
        java.lang.AssertionError - if the given array is null.
        java.lang.AssertionError - if the number of elements in the given array is not between the boundaries.
      • assertHasSameSizeAs

        public void assertHasSameSizeAs​(AssertionInfo info,
                                        java.lang.Iterable<?> actual,
                                        java.lang.Object other)
        Assert that the actual Iterable has the same size as the other array.
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        other - the given array to compare.
        Throws:
        java.lang.AssertionError - if the actual group is null.
        java.lang.AssertionError - if the other group is null.
        java.lang.AssertionError - if actual Iterable and other array don't have the same size.
      • assertHasSameSizeAs

        public void assertHasSameSizeAs​(AssertionInfo info,
                                        java.lang.Iterable<?> actual,
                                        java.lang.Iterable<?> other)
        Assert that the actual Iterable has the same size as the other Iterable.
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        other - the given Iterable.
        Throws:
        java.lang.AssertionError - if the actual group is null.
        java.lang.AssertionError - if the other group is null.
        java.lang.AssertionError - if actual and other Iterable don't have the same size.
      • assertContains

        public void assertContains​(AssertionInfo info,
                                   java.lang.Iterable<?> actual,
                                   java.lang.Object[] values)
        Asserts that the given Iterable contains the given values, in any order.
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        values - the values that are expected to be in the given Iterable.
        Throws:
        java.lang.NullPointerException - if the array of values is null.
        java.lang.IllegalArgumentException - if the array of values is empty.
        java.lang.AssertionError - if the given Iterable is null.
        java.lang.AssertionError - if the given Iterable does not contain the given values.
      • ensureActualCanBeReadMultipleTimes

        private static java.util.Collection<?> ensureActualCanBeReadMultipleTimes​(java.lang.Iterable<?> actual)
      • assertIterableContainsGivenValues

        private void assertIterableContainsGivenValues​(java.lang.Class<? extends java.lang.Iterable> clazz,
                                                       java.lang.Iterable<?> actual,
                                                       java.lang.Object[] values,
                                                       AssertionInfo info)
      • iterableContains

        private boolean iterableContains​(java.lang.Iterable<?> actual,
                                         java.lang.Object value)
      • iterablesRemoveFirst

        private void iterablesRemoveFirst​(java.lang.Iterable<?> actual,
                                          java.lang.Object value)
      • iterablesRemove

        private void iterablesRemove​(java.lang.Iterable<?> actual,
                                     java.lang.Object value)
      • assertContainsOnly

        public void assertContainsOnly​(AssertionInfo info,
                                       java.lang.Iterable<?> actual,
                                       java.lang.Object[] expectedValues)
        Asserts that the given Iterable contains only the given values and nothing else, in any order.
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        expectedValues - the values that are expected to be in the given Iterable.
        Throws:
        java.lang.NullPointerException - if the array of values is null.
        java.lang.IllegalArgumentException - if the array of values is empty.
        java.lang.AssertionError - if the given Iterable is null.
        java.lang.AssertionError - if the given Iterable does not contain the given values or if the given Iterable contains values that are not in the given array.
      • assertContainsOnlyOnce

        public void assertContainsOnlyOnce​(AssertionInfo info,
                                           java.lang.Iterable<?> actual,
                                           java.lang.Object[] values)
        Asserts that the given Iterable contains the given values and only once.
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        values - the values that are expected to be in the given Iterable.
        Throws:
        java.lang.NullPointerException - if the array of values is null.
        java.lang.IllegalArgumentException - if the array of values is empty.
        java.lang.AssertionError - if the given Iterable is null.
        java.lang.AssertionError - if the given Iterable does not contain the given values or if the given Iterable contains values that are not in the given array.
      • assertContainsOnlyNulls

        public void assertContainsOnlyNulls​(AssertionInfo info,
                                            java.lang.Iterable<?> actual)
        Asserts that the given Iterable contains only null elements and nothing else.
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        Throws:
        java.lang.AssertionError - if the given Iterable is null.
        java.lang.AssertionError - if the given Iterable does not contain at least a null element or if the given Iterable contains values that are not null elements.
      • assertContainsSequence

        public void assertContainsSequence​(AssertionInfo info,
                                           java.lang.Iterable<?> actual,
                                           java.lang.Object[] sequence)
        Verifies that the given Iterable contains the given sequence of objects, without any other objects between them.
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        sequence - the sequence of objects to look for.
        Throws:
        java.lang.AssertionError - if the given Iterable is null.
        java.lang.NullPointerException - if the given sequence is null.
        java.lang.IllegalArgumentException - if the given sequence is empty.
        java.lang.AssertionError - if the given Iterable does not contain the given sequence of objects.
      • assertDoesNotContainSequence

        public void assertDoesNotContainSequence​(AssertionInfo info,
                                                 java.lang.Iterable<?> actual,
                                                 java.lang.Object[] sequence)
        Verifies that the given Iterable does not contain the given sequence of objects in order.
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        sequence - the sequence of objects to look for.
        Throws:
        java.lang.AssertionError - if the given Iterable is null.
        java.lang.NullPointerException - if the given sequence is null.
        java.lang.IllegalArgumentException - if the given sequence is empty.
        java.lang.AssertionError - if the given Iterable does contain the given sequence of objects.
      • assertContainsSubsequence

        public void assertContainsSubsequence​(AssertionInfo info,
                                              java.lang.Iterable<?> actual,
                                              java.lang.Object[] subsequence)
        Verifies that the given Iterable contains the given subsequence of objects (possibly with other values between them).
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        subsequence - the subsequence of objects to look for.
        Throws:
        java.lang.AssertionError - if the given Iterable is null.
        java.lang.NullPointerException - if the given sequence is null.
        java.lang.IllegalArgumentException - if the given subsequence is empty.
        java.lang.AssertionError - if the given Iterable does not contain the given subsequence of objects.
      • assertDoesNotContainSubsequence

        public void assertDoesNotContainSubsequence​(AssertionInfo info,
                                                    java.lang.Iterable<?> actual,
                                                    java.lang.Object[] subsequence)
        Verifies that the given Iterable does not contain the given subsequence of objects (possibly with other values between them).
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        subsequence - the subsequence of objects to look for.
        Throws:
        java.lang.AssertionError - if the given Iterable is null.
        java.lang.NullPointerException - if the given sequence is null.
        java.lang.IllegalArgumentException - if the given subsequence is empty.
        java.lang.AssertionError - if the given Iterable contains the given subsequence of objects.
      • assertIsSubsetOf

        public void assertIsSubsetOf​(AssertionInfo info,
                                     java.lang.Iterable<?> actual,
                                     java.lang.Iterable<?> values)
        Verifies that the actual Iterable is a subset of values Iterable.
        Both actual and given iterable are treated as sets, therefore duplicates on either of them are ignored.
        Parameters:
        info - contains information about the assertion.
        actual - the actual Iterable.
        values - the Iterable that should contain all actual elements.
        Throws:
        java.lang.AssertionError - if the actual Iterable is null.
        java.lang.NullPointerException - if the given Iterable is null.
        java.lang.AssertionError - if the actual Iterable is not subset of set Iterable
      • containsSequenceAtGivenIndex

        private boolean containsSequenceAtGivenIndex​(java.util.List<?> actualAsList,
                                                     java.lang.Object[] sequence,
                                                     int startingIndex)
        Return true if actualAsList contains exactly the given sequence at given starting index, false otherwise.
        Parameters:
        actualAsList - the list to look sequence in
        sequence - the sequence to look for
        startingIndex - the index of actual list at which we start looking for sequence.
        Returns:
        true if actualAsList contains exactly the given sequence at given starting index, false otherwise.
      • areEqual

        private boolean areEqual​(java.lang.Object actual,
                                 java.lang.Object other)
      • actualDoesNotContainSequence

        private java.lang.AssertionError actualDoesNotContainSequence​(AssertionInfo info,
                                                                      java.lang.Iterable<?> actual,
                                                                      java.lang.Object[] sequence)
      • actualDoesContainSequence

        private java.lang.AssertionError actualDoesContainSequence​(AssertionInfo info,
                                                                   java.lang.Iterable<?> actual,
                                                                   java.lang.Object[] sequence,
                                                                   int index)
      • actualDoesNotContainSubsequence

        private java.lang.AssertionError actualDoesNotContainSubsequence​(AssertionInfo info,
                                                                         java.lang.Iterable<?> actual,
                                                                         java.lang.Object[] subsequence,
                                                                         int subsequenceIndex)
      • actualContainsSubsequence

        private java.lang.AssertionError actualContainsSubsequence​(AssertionInfo info,
                                                                   java.lang.Iterable<?> actual,
                                                                   java.lang.Object[] subsequence,
                                                                   int index)
      • assertDoesNotContain

        public void assertDoesNotContain​(AssertionInfo info,
                                         java.lang.Iterable<?> actual,
                                         java.lang.Object[] values)
        Asserts that the given Iterable does not contain the given values.
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        values - the values that are expected not to be in the given Iterable.
        Throws:
        java.lang.NullPointerException - if the array of values is null.
        java.lang.IllegalArgumentException - if the array of values is empty.
        java.lang.AssertionError - if the given Iterable is null.
        java.lang.AssertionError - if the given Iterable contains any of given values.
      • assertDoesNotContainAnyElementsOf

        public <T> void assertDoesNotContainAnyElementsOf​(AssertionInfo info,
                                                          java.lang.Iterable<? extends T> actual,
                                                          java.lang.Iterable<? extends T> iterable)
        Asserts that the given Iterable does not contain the given values.
        Type Parameters:
        T - the type of actual elements
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        iterable - the values that are expected not to be in the given Iterable.
        Throws:
        java.lang.NullPointerException - if the array of values is null.
        java.lang.IllegalArgumentException - if the array of values is empty.
        java.lang.AssertionError - if the given Iterable is null.
        java.lang.AssertionError - if the given Iterable contains any of given values.
      • assertDoesNotHaveDuplicates

        public void assertDoesNotHaveDuplicates​(AssertionInfo info,
                                                java.lang.Iterable<?> actual)
        Asserts that the given Iterable does not have duplicate values.
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        Throws:
        java.lang.NullPointerException - if the array of values is null.
        java.lang.IllegalArgumentException - if the array of values is empty.
        java.lang.AssertionError - if the given Iterable is null.
        java.lang.AssertionError - if the given Iterable contains duplicate values.
      • assertStartsWith

        public void assertStartsWith​(AssertionInfo info,
                                     java.lang.Iterable<?> actual,
                                     java.lang.Object[] sequence)
        Verifies that the given Iterable starts with the given sequence of objects, without any other objects between them. Similar to assertContainsSequence(AssertionInfo, Iterable, Object[]), but it also verifies that the first element in the sequence is also the first element of the given Iterable.
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        sequence - the sequence of objects to look for.
        Throws:
        java.lang.NullPointerException - if the given argument is null.
        java.lang.IllegalArgumentException - if the given argument is an empty array.
        java.lang.AssertionError - if the given Iterable is null.
        java.lang.AssertionError - if the given Iterable does not start with the given sequence of objects.
      • actualDoesNotStartWithSequence

        private java.lang.AssertionError actualDoesNotStartWithSequence​(AssertionInfo info,
                                                                        java.lang.Iterable<?> actual,
                                                                        java.lang.Object[] sequence)
      • assertEndsWith

        public void assertEndsWith​(AssertionInfo info,
                                   java.lang.Iterable<?> actual,
                                   java.lang.Object first,
                                   java.lang.Object[] rest)
        Verifies that the given Iterable ends with the given sequence of objects, without any other objects between them. Similar to assertContainsSequence(AssertionInfo, Iterable, Object[]), but it also verifies that the last element in the sequence is also the last element of the given Iterable.
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        first - the first element of the end sequence.
        rest - the optional next elements of the end sequence.
        Throws:
        java.lang.NullPointerException - if the given argument is null.
        java.lang.IllegalArgumentException - if the given argument is an empty array.
        java.lang.AssertionError - if the given Iterable is null.
        java.lang.AssertionError - if the given Iterable does not end with the given sequence of objects.
      • assertEndsWith

        public void assertEndsWith​(AssertionInfo info,
                                   java.lang.Iterable<?> actual,
                                   java.lang.Object[] sequence)
        Verifies that the given Iterable ends with the given sequence of objects, without any other objects between them. Similar to assertContainsSequence(AssertionInfo, Iterable, Object[]), but it also verifies that the last element in the sequence is also the last element of the given Iterable.
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        sequence - the sequence of objects to look for.
        Throws:
        java.lang.NullPointerException - if the given argument is null.
        java.lang.IllegalArgumentException - if the given argument is an empty array.
        java.lang.AssertionError - if the given Iterable is null.
        java.lang.AssertionError - if the given Iterable does not end with the given sequence of objects.
      • commonCheckThatIterableAssertionSucceeds

        private boolean commonCheckThatIterableAssertionSucceeds​(AssertionInfo info,
                                                                 Failures failures,
                                                                 java.lang.Iterable<?> actual,
                                                                 java.lang.Object[] sequence)
      • checkNotNullIterables

        private void checkNotNullIterables​(AssertionInfo info,
                                           java.lang.Iterable<?> actual,
                                           java.lang.Object[] sequence)
      • assertContainsNull

        public void assertContainsNull​(AssertionInfo info,
                                       java.lang.Iterable<?> actual)
        Asserts that the given Iterable contains at least a null element.
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        Throws:
        java.lang.AssertionError - if the given Iterable is null.
        java.lang.AssertionError - if the given Iterable does not contain at least a null element.
      • assertDoesNotContainNull

        public void assertDoesNotContainNull​(AssertionInfo info,
                                             java.lang.Iterable<?> actual)
        Asserts that the given Iterable does not contain null elements.
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        Throws:
        java.lang.AssertionError - if the given Iterable is null.
        java.lang.AssertionError - if the given Iterable contains a null element.
      • assertAre

        public <T> void assertAre​(AssertionInfo info,
                                  java.lang.Iterable<? extends T> actual,
                                  Condition<? super T> condition)
        Assert that each element of given Iterable satisfies the given condition.
        Type Parameters:
        T - the type of actual elements
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        condition - the given Condition.
        Throws:
        java.lang.NullPointerException - if the given condition is null.
        java.lang.AssertionError - if an element cannot be cast to T.
        java.lang.AssertionError - if one or more elements do not satisfy the given condition.
      • assertAreNot

        public <E> void assertAreNot​(AssertionInfo info,
                                     java.lang.Iterable<? extends E> actual,
                                     Condition<? super E> condition)
        Assert that each element of given Iterable not satisfies the given condition.
        Type Parameters:
        E - the type of actual elements
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        condition - the given Condition.
        Throws:
        java.lang.NullPointerException - if the given condition is null.
        java.lang.AssertionError - if an element cannot be cast to E.
        java.lang.AssertionError - if one or more elements satisfy the given condition.
      • assertHave

        public <E> void assertHave​(AssertionInfo info,
                                   java.lang.Iterable<? extends E> actual,
                                   Condition<? super E> condition)
        Assert that each element of given Iterable satisfies the given condition.
        Type Parameters:
        E - the type of actual elements
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        condition - the given Condition.
        Throws:
        java.lang.NullPointerException - if the given condition is null.
        java.lang.AssertionError - if an element cannot be cast to E.
        java.lang.AssertionError - if one or more elements do not satisfy the given condition.
      • assertDoNotHave

        public <E> void assertDoNotHave​(AssertionInfo info,
                                        java.lang.Iterable<? extends E> actual,
                                        Condition<? super E> condition)
        Assert that each element of given Iterable not satisfies the given condition.
        Type Parameters:
        E - the type of actual elements
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        condition - the given Condition.
        Throws:
        java.lang.NullPointerException - if the given condition is null.
        java.lang.AssertionError - if an element cannot be cast to E.
        java.lang.AssertionError - if one or more elements satisfy the given condition.
      • assertAreAtLeast

        public <E> void assertAreAtLeast​(AssertionInfo info,
                                         java.lang.Iterable<? extends E> actual,
                                         int times,
                                         Condition<? super E> condition)
        Assert that there are at least n elements in the actual Iterable satisfying the given condition.
        Type Parameters:
        E - the type of actual elements
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        times - the minimum number of times the condition should be verified.
        condition - the given Condition.
        Throws:
        java.lang.NullPointerException - if the given condition is null.
        java.lang.AssertionError - if an element cannot be cast to E.
        java.lang.AssertionError - if the number of elements satisfying the given condition is < n.
      • conditionIsSatisfiedAtLeastNTimes

        private <E> boolean conditionIsSatisfiedAtLeastNTimes​(java.lang.Iterable<? extends E> actual,
                                                              int n,
                                                              Condition<? super E> condition)
      • assertAreAtMost

        public <E> void assertAreAtMost​(AssertionInfo info,
                                        java.lang.Iterable<? extends E> actual,
                                        int n,
                                        Condition<? super E> condition)
        Assert that there are at most n elements in the actual Iterable satisfying the given condition.
        Type Parameters:
        E - the type of actual elements
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        n - the number of times the condition should be at most verified.
        condition - the given Condition.
        Throws:
        java.lang.NullPointerException - if the given condition is null.
        java.lang.AssertionError - if an element cannot be cast to E.
        java.lang.AssertionError - if the number of elements satisfying the given condition is > n.
      • conditionIsSatisfiedAtMostNTimes

        private <E> boolean conditionIsSatisfiedAtMostNTimes​(java.lang.Iterable<? extends E> actual,
                                                             Condition<? super E> condition,
                                                             int n)
      • assertAreExactly

        public <E> void assertAreExactly​(AssertionInfo info,
                                         java.lang.Iterable<? extends E> actual,
                                         int times,
                                         Condition<? super E> condition)
        Verifies that there are exactly n elements in the actual Iterable satisfying the given condition.
        Type Parameters:
        E - the type of actual elements
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        times - the exact number of times the condition should be verified.
        condition - the given Condition.
        Throws:
        java.lang.NullPointerException - if the given condition is null.
        java.lang.AssertionError - if an element cannot be cast to E.
        java.lang.AssertionError - if the number of elements satisfying the given condition is ≠ n.
      • conditionIsSatisfiedNTimes

        private <E> boolean conditionIsSatisfiedNTimes​(java.lang.Iterable<? extends E> actual,
                                                       Condition<? super E> condition,
                                                       int times)
      • assertHaveAtLeast

        public <E> void assertHaveAtLeast​(AssertionInfo info,
                                          java.lang.Iterable<? extends E> actual,
                                          int times,
                                          Condition<? super E> condition)
        An alias method of assertAreAtLeast(AssertionInfo, Iterable, int, Condition) to provide a richer fluent api (same logic, only error message differs).
        Type Parameters:
        E - the type of actual elements
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        times - the minimum number of times the condition should be verified.
        condition - the given Condition.
        Throws:
        java.lang.NullPointerException - if the given condition is null.
        java.lang.AssertionError - if an element cannot be cast to E.
        java.lang.AssertionError - if the number of elements satisfying the given condition is < n.
      • assertHaveAtMost

        public <E> void assertHaveAtMost​(AssertionInfo info,
                                         java.lang.Iterable<? extends E> actual,
                                         int times,
                                         Condition<? super E> condition)
        An alias method of assertAreAtMost(AssertionInfo, Iterable, int, Condition) to provide a richer fluent api (same logic, only error message differs).
        Type Parameters:
        E - the type of actual elements
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        times - the number of times the condition should be at most verified.
        condition - the given Condition.
        Throws:
        java.lang.NullPointerException - if the given condition is null.
        java.lang.AssertionError - if an element cannot be cast to E.
        java.lang.AssertionError - if the number of elements satisfying the given condition is > n.
      • assertHaveExactly

        public <E> void assertHaveExactly​(AssertionInfo info,
                                          java.lang.Iterable<? extends E> actual,
                                          int times,
                                          Condition<? super E> condition)
        An alias method of assertAreExactly(AssertionInfo, Iterable, int, Condition) to provide a richer fluent api (same logic, only error message differs).
        Type Parameters:
        E - the type of actual elements
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        times - the exact number of times the condition should be verified.
        condition - the given Condition.
        Throws:
        java.lang.NullPointerException - if the given condition is null.
        java.lang.AssertionError - if an element cannot be cast to E.
        java.lang.AssertionError - if the number of elements satisfying the given condition is ≠ n.
      • assertContainsAll

        public void assertContainsAll​(AssertionInfo info,
                                      java.lang.Iterable<?> actual,
                                      java.lang.Iterable<?> other)
        Asserts that the given Iterable contains all the elements of the other Iterable, in any order.
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        other - the other Iterable.
        Throws:
        java.lang.NullPointerException - if Iterable is null.
        java.lang.AssertionError - if the given Iterable is null.
        java.lang.AssertionError - if the given Iterable does not contain all the elements of the other Iterable, in any order.
      • assertContainsExactly

        public void assertContainsExactly​(AssertionInfo info,
                                          java.lang.Iterable<?> actual,
                                          java.lang.Object[] values)
        Asserts that the given Iterable contains exactly the given values and nothing else, in order.
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        values - the values that are expected to be in the given Iterable in order.
        Throws:
        java.lang.NullPointerException - if the array of values is null.
        java.lang.AssertionError - if the given Iterable is null.
        java.lang.AssertionError - if the given Iterable does not contain the given values or if the given Iterable contains values that are not in the given array, in order.
      • assertEquivalency

        private void assertEquivalency​(AssertionInfo info,
                                       java.lang.Iterable<?> actual,
                                       java.lang.Object[] values,
                                       java.util.List<java.lang.Object> actualAsList)
      • assertElementOrder

        private void assertElementOrder​(AssertionInfo info,
                                        java.lang.Iterable<?> actual,
                                        java.lang.Object[] values,
                                        java.util.List<java.lang.Object> actualAsList)
      • compareOrder

        private java.util.List<IndexedDiff> compareOrder​(java.lang.Object[] values,
                                                         java.util.List<java.lang.Object> actualAsList)
      • shouldContainExactlyWithIndexAssertionError

        private java.lang.AssertionError shouldContainExactlyWithIndexAssertionError​(java.lang.Iterable<?> actual,
                                                                                     java.lang.Object[] values,
                                                                                     java.util.List<IndexedDiff> indexedDiffs,
                                                                                     AssertionInfo info)
      • shouldContainExactlyWithDiffAssertionError

        private java.lang.AssertionError shouldContainExactlyWithDiffAssertionError​(IterableDiff<java.lang.Object> diff,
                                                                                    java.lang.Iterable<?> actual,
                                                                                    java.lang.Object[] values,
                                                                                    AssertionInfo info)
      • assertAllSatisfy

        public <E> void assertAllSatisfy​(AssertionInfo info,
                                         java.lang.Iterable<? extends E> actual,
                                         java.util.function.Consumer<? super E> requirements)
      • failsRequirements

        private static <E> java.util.Optional<UnsatisfiedRequirement> failsRequirements​(java.util.function.Consumer<? super E> requirements,
                                                                                        E element)
      • assertSatisfiesExactly

        public <E> void assertSatisfiesExactly​(AssertionInfo info,
                                               java.lang.Iterable<? extends E> actual,
                                               java.util.function.Consumer<? super E>[] allRequirements)
      • assertSatisfiesExactlyInAnyOrder

        public <E> void assertSatisfiesExactlyInAnyOrder​(AssertionInfo info,
                                                         java.lang.Iterable<? extends E> actual,
                                                         java.util.function.Consumer<? super E>[] consumers)
      • assertSatisfiesOnlyOnce

        public <E> void assertSatisfiesOnlyOnce​(AssertionInfo info,
                                                java.lang.Iterable<? extends E> actual,
                                                java.util.function.Consumer<? super E> requirements)
      • satisfiedElementsPerConsumer

        @SafeVarargs
        private static <E> java.util.Deque<ElementsSatisfyingConsumer<E>> satisfiedElementsPerConsumer​(java.lang.Iterable<? extends E> actual,
                                                                                                       java.util.function.Consumer<? super E>... consumers)
      • areAllConsumersSatisfied

        private static <E> boolean areAllConsumersSatisfied​(java.util.Queue<ElementsSatisfyingConsumer<E>> satisfiedElementsPerConsumer)
      • assertZipSatisfy

        public <ACTUAL_ELEMENT,​OTHER_ELEMENT> void assertZipSatisfy​(AssertionInfo info,
                                                                          java.lang.Iterable<? extends ACTUAL_ELEMENT> actual,
                                                                          java.lang.Iterable<OTHER_ELEMENT> other,
                                                                          java.util.function.BiConsumer<? super ACTUAL_ELEMENT,​OTHER_ELEMENT> zipRequirements)
      • failsZipRequirements

        private <ACTUAL_ELEMENT,​OTHER_ELEMENT> java.util.Optional<ZippedElementsShouldSatisfy.ZipSatisfyError> failsZipRequirements​(ACTUAL_ELEMENT actualElement,
                                                                                                                                          OTHER_ELEMENT otherElement,
                                                                                                                                          java.util.function.BiConsumer<ACTUAL_ELEMENT,​OTHER_ELEMENT> zipRequirements)
      • assertAnySatisfy

        public <E> void assertAnySatisfy​(AssertionInfo info,
                                         java.lang.Iterable<? extends E> actual,
                                         java.util.function.Consumer<? super E> requirements)
      • assertAllMatch

        public <E> void assertAllMatch​(AssertionInfo info,
                                       java.lang.Iterable<? extends E> actual,
                                       java.util.function.Predicate<? super E> predicate,
                                       PredicateDescription predicateDescription)
      • assertNoneSatisfy

        public <E> void assertNoneSatisfy​(AssertionInfo info,
                                          java.lang.Iterable<? extends E> actual,
                                          java.util.function.Consumer<? super E> restrictions)
      • failsRestrictions

        private <E> java.util.Optional<E> failsRestrictions​(E element,
                                                            java.util.function.Consumer<? super E> restrictions)
      • assertAnyMatch

        public <E> void assertAnyMatch​(AssertionInfo info,
                                       java.lang.Iterable<? extends E> actual,
                                       java.util.function.Predicate<? super E> predicate,
                                       PredicateDescription predicateDescription)
      • assertNoneMatch

        public <E> void assertNoneMatch​(AssertionInfo info,
                                        java.lang.Iterable<? extends E> actual,
                                        java.util.function.Predicate<? super E> predicate,
                                        PredicateDescription predicateDescription)
      • assertContainsAnyOf

        public void assertContainsAnyOf​(AssertionInfo info,
                                        java.lang.Iterable<?> actual,
                                        java.lang.Object[] values)
        Asserts that the given Iterable contains at least one of the given values.
        Parameters:
        info - contains information about the assertion.
        actual - the given Iterable.
        values - the values that, at least one of which is expected to be in the given Iterable.
        Throws:
        java.lang.NullPointerException - if the array of values is null.
        java.lang.IllegalArgumentException - if the array of values is empty and given Iterable is not empty.
        java.lang.AssertionError - if the given Iterable is null.
        java.lang.AssertionError - if the given Iterable does not contain any of given values.
      • assertContainsExactlyInAnyOrder

        public void assertContainsExactlyInAnyOrder​(AssertionInfo info,
                                                    java.lang.Iterable<?> actual,
                                                    java.lang.Object[] values)
      • assertNotNull

        void assertNotNull​(AssertionInfo info,
                           java.lang.Iterable<?> actual)
      • actualDoesNotEndWithSequence

        private java.lang.AssertionError actualDoesNotEndWithSequence​(AssertionInfo info,
                                                                      java.lang.Iterable<?> actual,
                                                                      java.lang.Object[] sequence)
      • notSatisfyingCondition

        private <E> java.util.List<E> notSatisfyingCondition​(java.lang.Iterable<? extends E> actual,
                                                             Condition<? super E> condition)
      • satisfiesCondition

        private <E> java.util.List<E> satisfiesCondition​(java.lang.Iterable<? extends E> actual,
                                                         Condition<? super E> condition)
      • byPassingAssertions

        public static <T> java.util.function.Predicate<T> byPassingAssertions​(java.util.function.Consumer<? super T> assertions)
      • checkIsNotEmptySequence

        private static void checkIsNotEmptySequence​(java.lang.Object[] sequence)
      • checkIsNotEmptySubsequence

        private static void checkIsNotEmptySubsequence​(java.lang.Object[] subsequence)