How to use checkIsNotEmptySequence method of org.assertj.core.internal.Iterables class

Best Assertj code snippet using org.assertj.core.internal.Iterables.checkIsNotEmptySequence

Source:Iterables.java Github

copy

Full Screen

...354 * @throws AssertionError if the given {@code Iterable} does contain the given sequence of objects.355 */356 public void assertDoesNotContainSequence(AssertionInfo info, Iterable<?> actual, Object[] sequence) {357 checkIsNotNullSequence(sequence);358 checkIsNotEmptySequence(sequence);359 assertNotNull(info, actual);360 // check for elements in values that are missing in actual.361 List<?> actualAsList = newArrayList(actual);362 for (int index = 0; index < actualAsList.size(); index++) {363 // look for given sequence in actual starting from current index (i)364 if (containsSequenceAtGivenIndex(actualAsList, sequence, index)) {365 throw actualDoesContainSequence(info, actual, sequence, index);366 }367 }368 }369 /**370 * Verifies that the given <code>{@link Iterable}</code> contains the given subsequence of objects (possibly with371 * other values between them).372 * 373 * @param info contains information about the assertion.374 * @param actual the given {@code Iterable}.375 * @param subsequence the subsequence of objects to look for.376 * @throws AssertionError if the given {@code Iterable} is {@code null}.377 * @throws NullPointerException if the given sequence is {@code null}.378 * @throws IllegalArgumentException if the given subsequence is empty.379 * @throws AssertionError if the given {@code Iterable} does not contain the given subsequence of objects.380 */381 public void assertContainsSubsequence(AssertionInfo info, Iterable<?> actual, Object[] subsequence) {382 if (commonCheckThatIterableAssertionSucceeds(info, actual, subsequence)) return;383 Iterator<?> actualIterator = actual.iterator();384 int subsequenceIndex = 0;385 while (actualIterator.hasNext() && subsequenceIndex < subsequence.length) {386 Object actualNext = actualIterator.next();387 Object subsequenceNext = subsequence[subsequenceIndex];388 if (areEqual(actualNext, subsequenceNext)) subsequenceIndex++;389 }390 if (subsequenceIndex < subsequence.length) throw actualDoesNotContainSubsequence(info, actual, subsequence);391 }392 public void assertContainsSubsequence(AssertionInfo info, Iterable<?> actual, List<?> subsequence) {393 checkIsNotNull(subsequence);394 assertContainsSubsequence(info, actual, subsequence.toArray());395 }396 /**397 * Verifies that the given <code>{@link Iterable}</code> does not contain the given subsequence of objects (possibly398 * with other values between them).399 *400 * @param info contains information about the assertion.401 * @param actual the given {@code Iterable}.402 * @param subsequence the subsequence of objects to look for.403 * @throws AssertionError if the given {@code Iterable} is {@code null}.404 * @throws NullPointerException if the given sequence is {@code null}.405 * @throws IllegalArgumentException if the given subsequence is empty.406 * @throws AssertionError if the given {@code Iterable} contains the given subsequence of objects.407 */408 public void assertDoesNotContainSubsequence(AssertionInfo info, Iterable<?> actual, Object[] subsequence) {409 checkIsNotNullSubsequence(subsequence);410 checkIsNotEmptySubsequence(subsequence);411 assertNotNull(info, actual);412 int subsequenceIndex = 0;413 int subsequenceStartIndex = 0;414 List<?> actualAsList = newArrayList(actual);415 for (int index = 0; index < actualAsList.size(); index++) {416 Object actualNext = actualAsList.get(index);417 Object subsequenceNext = subsequence[subsequenceIndex];418 if (areEqual(actualNext, subsequenceNext)) {419 if (subsequenceIndex == 0) subsequenceStartIndex = index;420 subsequenceIndex++;421 }422 if (subsequenceIndex == subsequence.length) {423 throw actualContainsSubsequence(info, actual, subsequence, subsequenceStartIndex);424 }425 }426 }427 /**428 * Verifies that the actual <code>Iterable</code> is a subset of values <code>Iterable</code>. <br>429 * Both actual and given iterable are treated as sets, therefore duplicates on either of them are ignored.430 * 431 * @param info contains information about the assertion.432 * @param actual the actual {@code Iterable}.433 * @param values the {@code Iterable} that should contain all actual elements.434 * @throws AssertionError if the actual {@code Iterable} is {@code null}.435 * @throws NullPointerException if the given Iterable is {@code null}.436 * @throws AssertionError if the actual {@code Iterable} is not subset of set <code>{@link Iterable}</code>437 */438 public void assertIsSubsetOf(AssertionInfo info, Iterable<?> actual, Iterable<?> values) {439 assertNotNull(info, actual);440 checkIterableIsNotNull(info, values);441 List<Object> extra = newArrayList();442 for (Object actualElement : actual) {443 if (!iterableContains(values, actualElement)) extra.add(actualElement);444 }445 if (extra.size() > 0) throw failures.failure(info, shouldBeSubsetOf(actual, values, extra, comparisonStrategy));446 }447 /**448 * Return true if actualAsList contains exactly the given sequence at given starting index, false otherwise.449 * 450 * @param actualAsList the list to look sequence in451 * @param sequence the sequence to look for452 * @param startingIndex the index of actual list at which we start looking for sequence.453 * @return true if actualAsList contains exactly the given sequence at given starting index, false otherwise.454 */455 private boolean containsSequenceAtGivenIndex(List<?> actualAsList, Object[] sequence, int startingIndex) {456 // check that, starting from given index, actualAsList has enough remaining elements to contain sequence457 if (actualAsList.size() - startingIndex < sequence.length) return false;458 for (int i = 0; i < sequence.length; i++) {459 if (!areEqual(actualAsList.get(startingIndex + i), sequence[i])) return false;460 }461 return true;462 }463 /**464 * Delegates to {@link ComparisonStrategy#areEqual(Object, Object)}465 */466 private boolean areEqual(Object actual, Object other) {467 return comparisonStrategy.areEqual(actual, other);468 }469 private AssertionError actualDoesNotContainSequence(AssertionInfo info, Iterable<?> actual, Object[] sequence) {470 return failures.failure(info, shouldContainSequence(actual, sequence, comparisonStrategy));471 }472 private AssertionError actualDoesContainSequence(AssertionInfo info, Iterable<?> actual, Object[] sequence,473 int index) {474 return failures.failure(info, shouldNotContainSequence(actual, sequence, index, comparisonStrategy));475 }476 private AssertionError actualDoesNotContainSubsequence(AssertionInfo info, Iterable<?> actual, Object[] subsequence) {477 return failures.failure(info, shouldContainSubsequence(actual, subsequence, comparisonStrategy));478 }479 private AssertionError actualContainsSubsequence(AssertionInfo info, Iterable<?> actual, Object[] subsequence,480 int index) {481 return failures.failure(info, shouldNotContainSubsequence(actual, subsequence, comparisonStrategy, index));482 }483 /**484 * Asserts that the given {@code Iterable} does not contain the given values.485 * 486 * @param info contains information about the assertion.487 * @param actual the given {@code Iterable}.488 * @param values the values that are expected not to be in the given {@code Iterable}.489 * @throws NullPointerException if the array of values is {@code null}.490 * @throws IllegalArgumentException if the array of values is empty.491 * @throws AssertionError if the given {@code Iterable} is {@code null}.492 * @throws AssertionError if the given {@code Iterable} contains any of given values.493 */494 public void assertDoesNotContain(AssertionInfo info, Iterable<?> actual, Object[] values) {495 checkIsNotNullAndNotEmpty(values);496 assertNotNull(info, actual);497 Set<Object> found = new LinkedHashSet<>();498 for (Object o : values) {499 if (iterableContains(actual, o)) found.add(o);500 }501 if (!found.isEmpty()) throw failures.failure(info, shouldNotContain(actual, values, found, comparisonStrategy));502 }503 /**504 * Asserts that the given {@code Iterable} does not contain the given values.505 * 506 * @param info contains information about the assertion.507 * @param actual the given {@code Iterable}.508 * @param iterable the values that are expected not to be in the given {@code Iterable}.509 * @throws NullPointerException if the array of values is {@code null}.510 * @throws IllegalArgumentException if the array of values is empty.511 * @throws AssertionError if the given {@code Iterable} is {@code null}.512 * @throws AssertionError if the given {@code Iterable} contains any of given values.513 */514 public <T> void assertDoesNotContainAnyElementsOf(AssertionInfo info, Iterable<? extends T> actual,515 Iterable<? extends T> iterable) {516 checkIsNotNullAndNotEmpty(iterable);517 List<T> values = newArrayList(iterable);518 assertDoesNotContain(info, actual, values.toArray());519 }520 /**521 * Asserts that the given {@code Iterable} does not have duplicate values.522 * 523 * @param info contains information about the assertion.524 * @param actual the given {@code Iterable}.525 * @throws NullPointerException if the array of values is {@code null}.526 * @throws IllegalArgumentException if the array of values is empty.527 * @throws AssertionError if the given {@code Iterable} is {@code null}.528 * @throws AssertionError if the given {@code Iterable} contains duplicate values.529 */530 public void assertDoesNotHaveDuplicates(AssertionInfo info, Iterable<?> actual) {531 assertNotNull(info, actual);532 Iterable<?> duplicates = comparisonStrategy.duplicatesFrom(actual);533 if (!isNullOrEmpty(duplicates))534 throw failures.failure(info, shouldNotHaveDuplicates(actual, duplicates, comparisonStrategy));535 }536 /**537 * Verifies that the given {@code Iterable} starts with the given sequence of objects, without any other objects538 * between them. Similar to <code>{@link #assertContainsSequence(AssertionInfo, Iterable, Object[])}</code>, but it539 * also verifies that the first element in the sequence is also the first element of the given {@code Iterable}.540 * 541 * @param info contains information about the assertion.542 * @param actual the given {@code Iterable}.543 * @param sequence the sequence of objects to look for.544 * @throws NullPointerException if the given argument is {@code null}.545 * @throws IllegalArgumentException if the given argument is an empty array.546 * @throws AssertionError if the given {@code Iterable} is {@code null}.547 * @throws AssertionError if the given {@code Iterable} does not start with the given sequence of objects.548 */549 public void assertStartsWith(AssertionInfo info, Iterable<?> actual, Object[] sequence) {550 if (commonCheckThatIterableAssertionSucceeds(info, actual, sequence)) return;551 int i = 0;552 for (Object actualCurrentElement : actual) {553 if (i >= sequence.length) break;554 if (areEqual(actualCurrentElement, sequence[i++])) continue;555 throw actualDoesNotStartWithSequence(info, actual, sequence);556 }557 if (sequence.length > i) {558 // sequence has more elements than actual559 throw actualDoesNotStartWithSequence(info, actual, sequence);560 }561 }562 private AssertionError actualDoesNotStartWithSequence(AssertionInfo info, Iterable<?> actual, Object[] sequence) {563 return failures.failure(info, shouldStartWith(actual, sequence, comparisonStrategy));564 }565 /**566 * Verifies that the given {@code Iterable} ends with the given sequence of objects, without any other objects between567 * them. Similar to <code>{@link #assertContainsSequence(AssertionInfo, Iterable, Object[])}</code>, but it also568 * verifies that the last element in the sequence is also the last element of the given {@code Iterable}.569 * 570 * @param info contains information about the assertion.571 * @param actual the given {@code Iterable}.572 * @param first the first element of the end sequence.573 * @param rest the optional next elements of the end sequence.574 * @throws NullPointerException if the given argument is {@code null}.575 * @throws IllegalArgumentException if the given argument is an empty array.576 * @throws AssertionError if the given {@code Iterable} is {@code null}.577 * @throws AssertionError if the given {@code Iterable} does not end with the given sequence of objects.578 */579 public void assertEndsWith(AssertionInfo info, Iterable<?> actual, Object first, Object[] rest) {580 Object[] sequence = prepend(first, rest);581 assertEndsWith(info, actual, sequence);582 }583 /**584 * Verifies that the given {@code Iterable} ends with the given sequence of objects, without any other objects between585 * them. Similar to <code>{@link #assertContainsSequence(AssertionInfo, Iterable, Object[])}</code>, but it also586 * verifies that the last element in the sequence is also the last element of the given {@code Iterable}.587 *588 * @param info contains information about the assertion.589 * @param actual the given {@code Iterable}.590 * @param sequence the sequence of objects to look for.591 * @throws NullPointerException if the given argument is {@code null}.592 * @throws IllegalArgumentException if the given argument is an empty array.593 * @throws AssertionError if the given {@code Iterable} is {@code null}.594 * @throws AssertionError if the given {@code Iterable} does not end with the given sequence of objects.595 */596 public void assertEndsWith(AssertionInfo info, Iterable<?> actual, Object[] sequence) {597 checkNotNullIterables(info, actual, sequence);598 int sizeOfActual = sizeOf(actual);599 if (sizeOfActual < sequence.length) throw actualDoesNotEndWithSequence(info, actual, sequence);600 int start = sizeOfActual - sequence.length;601 int sequenceIndex = 0, indexOfActual = 0;602 for (Object actualElement : actual) {603 if (indexOfActual++ < start) continue;604 if (areEqual(actualElement, sequence[sequenceIndex++])) continue;605 throw actualDoesNotEndWithSequence(info, actual, sequence);606 }607 }608 private boolean commonCheckThatIterableAssertionSucceeds(AssertionInfo info, Iterable<?> actual, Object[] sequence) {609 checkNotNullIterables(info, actual, sequence);610 // if both actual and values are empty, then assertion passes.611 if (!actual.iterator().hasNext() && sequence.length == 0) return true;612 failIfEmptySinceActualIsNotEmpty(sequence);613 return false;614 }615 private void checkNotNullIterables(AssertionInfo info, Iterable<?> actual, Object[] sequence) {616 checkIsNotNull(sequence);617 assertNotNull(info, actual);618 }619 /**620 * Asserts that the given {@code Iterable} contains at least a null element.621 * 622 * @param info contains information about the assertion.623 * @param actual the given {@code Iterable}.624 * @throws AssertionError if the given {@code Iterable} is {@code null}.625 * @throws AssertionError if the given {@code Iterable} does not contain at least a null element.626 */627 public void assertContainsNull(AssertionInfo info, Iterable<?> actual) {628 assertNotNull(info, actual);629 if (!iterableContains(actual, null)) throw failures.failure(info, shouldContainNull(actual));630 }631 /**632 * Asserts that the given {@code Iterable} does not contain null elements.633 * 634 * @param info contains information about the assertion.635 * @param actual the given {@code Iterable}.636 * @throws AssertionError if the given {@code Iterable} is {@code null}.637 * @throws AssertionError if the given {@code Iterable} contains a null element.638 */639 public void assertDoesNotContainNull(AssertionInfo info, Iterable<?> actual) {640 assertNotNull(info, actual);641 if (iterableContains(actual, null)) throw failures.failure(info, shouldNotContainNull(actual));642 }643 /**644 * Assert that each element of given {@code Iterable} satisfies the given condition.645 * 646 * @param info contains information about the assertion.647 * @param actual the given {@code Iterable}.648 * @param condition the given {@code Condition}.649 * @throws NullPointerException if the given condition is {@code null}.650 * @throws AssertionError if an element cannot be cast to E.651 * @throws AssertionError if one or more elements do not satisfy the given condition.652 */653 public <E> void assertAre(AssertionInfo info, Iterable<? extends E> actual, Condition<? super E> condition) {654 assertNotNull(info, actual);655 conditions.assertIsNotNull(condition);656 try {657 List<E> notSatisfiesCondition = notSatisfyingCondition(actual, condition);658 if (!notSatisfiesCondition.isEmpty())659 throw failures.failure(info, elementsShouldBe(actual, notSatisfiesCondition, condition));660 } catch (ClassCastException e) {661 throw failures.failure(info, shouldBeSameGenericBetweenIterableAndCondition(actual, condition));662 }663 }664 /**665 * Assert that each element of given {@code Iterable} not satisfies the given condition.666 * 667 * @param info contains information about the assertion.668 * @param actual the given {@code Iterable}.669 * @param condition the given {@code Condition}.670 * @throws NullPointerException if the given condition is {@code null}.671 * @throws AssertionError if an element cannot be cast to E.672 * @throws AssertionError if one or more elements satisfy the given condition.673 */674 public <E> void assertAreNot(AssertionInfo info, Iterable<? extends E> actual, Condition<? super E> condition) {675 assertNotNull(info, actual);676 conditions.assertIsNotNull(condition);677 try {678 List<E> satisfiesCondition = satisfiesCondition(actual, condition);679 if (!satisfiesCondition.isEmpty())680 throw failures.failure(info, elementsShouldNotBe(actual, satisfiesCondition, condition));681 } catch (ClassCastException e) {682 throw failures.failure(info, shouldBeSameGenericBetweenIterableAndCondition(actual, condition));683 }684 }685 /**686 * Assert that each element of given {@code Iterable} satisfies the given condition.687 * 688 * @param info contains information about the assertion.689 * @param actual the given {@code Iterable}.690 * @param condition the given {@code Condition}.691 * @throws NullPointerException if the given condition is {@code null}.692 * @throws AssertionError if an element cannot be cast to E.693 * @throws AssertionError if one or more elements do not satisfy the given condition.694 */695 public <E> void assertHave(AssertionInfo info, Iterable<? extends E> actual, Condition<? super E> condition) {696 assertNotNull(info, actual);697 conditions.assertIsNotNull(condition);698 try {699 List<E> notSatisfiesCondition = notSatisfyingCondition(actual, condition);700 if (!notSatisfiesCondition.isEmpty())701 throw failures.failure(info, elementsShouldHave(actual, notSatisfiesCondition, condition));702 } catch (ClassCastException e) {703 throw failures.failure(info, shouldBeSameGenericBetweenIterableAndCondition(actual, condition));704 }705 }706 /**707 * Assert that each element of given {@code Iterable} not satisfies the given condition.708 * 709 * @param info contains information about the assertion.710 * @param actual the given {@code Iterable}.711 * @param condition the given {@code Condition}.712 * @throws NullPointerException if the given condition is {@code null}.713 * @throws AssertionError if an element cannot be cast to E.714 * @throws AssertionError if one or more elements satisfy the given condition.715 */716 public <E> void assertDoNotHave(AssertionInfo info, Iterable<? extends E> actual, Condition<? super E> condition) {717 assertNotNull(info, actual);718 conditions.assertIsNotNull(condition);719 try {720 List<E> satisfiesCondition = satisfiesCondition(actual, condition);721 if (!satisfiesCondition.isEmpty())722 throw failures.failure(info, elementsShouldNotHave(actual, satisfiesCondition, condition));723 } catch (ClassCastException e) {724 throw failures.failure(info, shouldBeSameGenericBetweenIterableAndCondition(actual, condition));725 }726 }727 /**728 * Assert that there are <b>at least</b> <i>n</i> elements in the actual {@code Iterable} satisfying the given729 * condition.730 * 731 * @param info contains information about the assertion.732 * @param actual the given {@code Iterable}.733 * @param times the minimum number of times the condition should be verified.734 * @param condition the given {@code Condition}.735 * @throws NullPointerException if the given condition is {@code null}.736 * @throws AssertionError if an element cannot be cast to E.737 * @throws AssertionError if the number of elements satisfying the given condition is &lt; n.738 */739 public <E> void assertAreAtLeast(AssertionInfo info, Iterable<? extends E> actual, int times,740 Condition<? super E> condition) {741 assertNotNull(info, actual);742 conditions.assertIsNotNull(condition);743 try {744 if (!conditionIsSatisfiedAtLeastNTimes(actual, times, condition))745 throw failures.failure(info, elementsShouldBeAtLeast(actual, times, condition));746 } catch (ClassCastException e) {747 throw failures.failure(info, shouldBeSameGenericBetweenIterableAndCondition(actual, condition));748 }749 }750 private <E> boolean conditionIsSatisfiedAtLeastNTimes(Iterable<? extends E> actual, int n,751 Condition<? super E> condition) {752 List<E> satisfiesCondition = satisfiesCondition(actual, condition);753 return satisfiesCondition.size() >= n;754 }755 /**756 * Assert that there are <b>at most</b> <i>n</i> elements in the actual {@code Iterable} satisfying the given757 * condition.758 * 759 * @param info contains information about the assertion.760 * @param actual the given {@code Iterable}.761 * @param n the number of times the condition should be at most verified.762 * @param condition the given {@code Condition}.763 * @throws NullPointerException if the given condition is {@code null}.764 * @throws AssertionError if an element cannot be cast to E.765 * @throws AssertionError if the number of elements satisfying the given condition is &gt; n.766 */767 public <E> void assertAreAtMost(AssertionInfo info, Iterable<? extends E> actual, int n,768 Condition<? super E> condition) {769 assertNotNull(info, actual);770 conditions.assertIsNotNull(condition);771 try {772 if (!conditionIsSatisfiedAtMostNTimes(actual, condition, n))773 throw failures.failure(info, elementsShouldBeAtMost(actual, n, condition));774 } catch (ClassCastException e) {775 throw failures.failure(info, shouldBeSameGenericBetweenIterableAndCondition(actual, condition));776 }777 }778 private <E> boolean conditionIsSatisfiedAtMostNTimes(Iterable<? extends E> actual, Condition<? super E> condition,779 int n) {780 List<E> satisfiesCondition = satisfiesCondition(actual, condition);781 return satisfiesCondition.size() <= n;782 }783 /**784 * Verifies that there are <b>exactly</b> <i>n</i> elements in the actual {@code Iterable} satisfying the given785 * condition.786 * 787 * @param info contains information about the assertion.788 * @param actual the given {@code Iterable}.789 * @param times the exact number of times the condition should be verified.790 * @param condition the given {@code Condition}.791 * @throws NullPointerException if the given condition is {@code null}.792 * @throws AssertionError if an element cannot be cast to E.793 * @throws AssertionError if the number of elements satisfying the given condition is &ne; n.794 */795 public <E> void assertAreExactly(AssertionInfo info, Iterable<? extends E> actual, int times,796 Condition<? super E> condition) {797 assertNotNull(info, actual);798 conditions.assertIsNotNull(condition);799 try {800 if (!conditionIsSatisfiedNTimes(actual, condition, times))801 throw failures.failure(info, elementsShouldBeExactly(actual, times, condition));802 } catch (ClassCastException e) {803 throw failures.failure(info, shouldBeSameGenericBetweenIterableAndCondition(actual, condition));804 }805 }806 private <E> boolean conditionIsSatisfiedNTimes(Iterable<? extends E> actual, Condition<? super E> condition,807 int times) {808 List<E> satisfiesCondition = satisfiesCondition(actual, condition);809 return satisfiesCondition.size() == times;810 }811 /**812 * An alias method of {@link #assertAreAtLeast(AssertionInfo, Iterable, int, Condition)} to provide a richer fluent813 * api (same logic, only error message differs).814 */815 public <E> void assertHaveAtLeast(AssertionInfo info, Iterable<? extends E> actual, int times,816 Condition<? super E> condition) {817 assertNotNull(info, actual);818 conditions.assertIsNotNull(condition);819 try {820 if (!conditionIsSatisfiedAtLeastNTimes(actual, times, condition))821 throw failures.failure(info, elementsShouldHaveAtLeast(actual, times, condition));822 } catch (ClassCastException e) {823 throw failures.failure(info, shouldBeSameGenericBetweenIterableAndCondition(actual, condition));824 }825 }826 /**827 * An alias method of {@link #assertAreAtMost(AssertionInfo, Iterable, int, Condition)} to provide a richer fluent api828 * (same logic, only error message differs).829 */830 public <E> void assertHaveAtMost(AssertionInfo info, Iterable<? extends E> actual, int times,831 Condition<? super E> condition) {832 assertNotNull(info, actual);833 conditions.assertIsNotNull(condition);834 try {835 if (!conditionIsSatisfiedAtMostNTimes(actual, condition, times))836 throw failures.failure(info, elementsShouldHaveAtMost(actual, times, condition));837 } catch (ClassCastException e) {838 throw failures.failure(info, shouldBeSameGenericBetweenIterableAndCondition(actual, condition));839 }840 }841 /**842 * An alias method of {@link #assertAreExactly(AssertionInfo, Iterable, int, Condition)} to provide a richer fluent843 * api (same logic, only error message differs).844 */845 public <E> void assertHaveExactly(AssertionInfo info, Iterable<? extends E> actual, int times,846 Condition<? super E> condition) {847 assertNotNull(info, actual);848 conditions.assertIsNotNull(condition);849 try {850 if (!conditionIsSatisfiedNTimes(actual, condition, times))851 throw failures.failure(info, elementsShouldHaveExactly(actual, times, condition));852 } catch (ClassCastException e) {853 throw failures.failure(info, shouldBeSameGenericBetweenIterableAndCondition(actual, condition));854 }855 }856 /**857 * Asserts that the given {@code Iterable} contains all the elements of the other {@code Iterable}, in any order.858 * 859 * @param info contains information about the assertion.860 * @param actual the given {@code Iterable}.861 * @param other the other {@code Iterable}.862 * @throws NullPointerException if {@code Iterable} is {@code null}.863 * @throws AssertionError if the given {@code Iterable} is {@code null}.864 * @throws AssertionError if the given {@code Iterable} does not contain all the elements of the other865 * {@code Iterable}, in any order.866 */867 public void assertContainsAll(AssertionInfo info, Iterable<?> actual, Iterable<?> other) {868 if (other == null) throw iterableToLookForIsNull();869 assertNotNull(info, actual);870 Object[] values = newArrayList(other).toArray();871 assertIterableContainsGivenValues(actual, values, info);872 }873 /**874 * Asserts that the given {@code Iterable} contains exactly the given values and nothing else, <b>in order</b>.875 * 876 * @param info contains information about the assertion.877 * @param actual the given {@code Iterable}.878 * @param values the values that are expected to be in the given {@code Iterable} in order.879 * @throws NullPointerException if the array of values is {@code null}.880 * @throws AssertionError if the given {@code Iterable} is {@code null}.881 * @throws AssertionError if the given {@code Iterable} does not contain the given values or if the given882 * {@code Iterable} contains values that are not in the given array, in order.883 */884 public void assertContainsExactly(AssertionInfo info, Iterable<?> actual, Object[] values) {885 checkIsNotNull(values);886 assertNotNull(info, actual);887 int actualSize = sizeOf(actual);888 if (values.length != actualSize)889 throw failures.failure(info, shouldHaveSameSize(actual, values, actualSize, values.length, comparisonStrategy));890 assertHasSameSizeAs(info, actual, values); // include check that actual is not null891 List<Object> actualAsList = newArrayList(actual);892 IterableDiff diff = diff(actualAsList, asList(values), comparisonStrategy);893 if (!diff.differencesFound()) {894 // actual and values have the same elements but are they in the same order ?895 int i = 0;896 for (Object elementFromActual : actual) {897 if (!areEqual(elementFromActual, values[i])) {898 throw failures.failure(info, elementsDifferAtIndex(elementFromActual, values[i], i, comparisonStrategy));899 }900 i++;901 }902 return;903 }904 throw failures.failure(info,905 shouldContainExactly(actual, values, diff.missing, diff.unexpected, comparisonStrategy));906 }907 /**908 * Asserts that the given {@code Iterable} contains at least one of the given {@code values}.909 *910 * @param info contains information about the assertion.911 * @param actual the given {@code Iterable}.912 * @param values the values that, at least one of which is expected to be in the given {@code Iterable}.913 * @throws NullPointerException if the array of values is {@code null}.914 * @throws IllegalArgumentException if the array of values is empty and given {@code Iterable} is not empty.915 * @throws AssertionError if the given {@code Iterable} is {@code null}.916 * @throws AssertionError if the given {@code Iterable} does not contain any of given {@code values}.917 */918 public void assertContainsAnyOf(AssertionInfo info, Iterable<?> actual, Object[] values) {919 if (commonCheckThatIterableAssertionSucceeds(info, actual, values))920 return;921 Set<Object> valuesToSearchFor = newTreeSet(values);922 for (Object element : actual) {923 if (iterableContains(valuesToSearchFor, element)) return;924 }925 throw failures.failure(info, shouldContainAnyOf(actual, values, comparisonStrategy));926 }927 public void assertContainsExactlyInAnyOrder(AssertionInfo info, Iterable<?> actual, Object[] values) {928 checkIsNotNull(values);929 assertNotNull(info, actual);930 List<Object> notExpected = newArrayList(actual);931 List<Object> notFound = newArrayList(values);932 for (Object value : values) {933 if (iterableContains(notExpected, value)) {934 iterablesRemoveFirst(notExpected, value);935 iterablesRemoveFirst(notFound, value);936 }937 }938 if (notExpected.isEmpty() && notFound.isEmpty()) return;939 throw failures.failure(info,940 shouldContainExactlyInAnyOrder(actual, values, notFound, notExpected, comparisonStrategy));941 }942 void assertNotNull(AssertionInfo info, Iterable<?> actual) {943 Objects.instance().assertNotNull(info, actual);944 }945 private AssertionError actualDoesNotEndWithSequence(AssertionInfo info, Iterable<?> actual, Object[] sequence) {946 return failures.failure(info, shouldEndWith(actual, sequence, comparisonStrategy));947 }948 private <E> List<E> notSatisfyingCondition(Iterable<? extends E> actual, Condition<? super E> condition) {949 List<E> notSatisfiesCondition = new LinkedList<>();950 for (E o : actual) {951 if (!condition.matches(o)) notSatisfiesCondition.add(o);952 }953 return notSatisfiesCondition;954 }955 private <E> List<E> satisfiesCondition(Iterable<? extends E> actual, Condition<? super E> condition) {956 List<E> satisfiesCondition = new LinkedList<>();957 for (E o : actual) {958 if (condition.matches(o)) satisfiesCondition.add(o);959 }960 return satisfiesCondition;961 }962 private static void checkIsNotEmptySequence(Object[] sequence) {963 if (sequence.length == 0) throw new IllegalArgumentException(emptySequence());964 }965 private static void checkIsNotNullSequence(Object sequence) {966 if (sequence == null) throw new NullPointerException(nullSequence());967 }968 private static void checkIsNotEmptySubsequence(Object[] subsequence) {969 if (subsequence.length == 0) throw new IllegalArgumentException(emptySubsequence());970 }971 private static void checkIsNotNullSubsequence(Object subsequence) {972 if (subsequence == null) throw new NullPointerException(nullSubsequence());973 }974}...

Full Screen

Full Screen

checkIsNotEmptySequence

Using AI Code Generation

copy

Full Screen

1package org.assertj.core.api.iterable;2import static org.assertj.core.api.Assertions.assertThat;3import static org.assertj.core.test.TestData.someInfo;4import static org.assertj.core.util.FailureMessages.actualIsNull;5import java.util.Arrays;6import org.assertj.core.api.AbstractIterableAssert;7import org.assertj.core.api.IterableAssert;8import org.assertj.core.api.IterableAssertBaseTest;9import org.assertj.core.internal.Iterables;10import org.assertj.core.internal.IterablesBaseTest;11import org.junit.jupiter.api.Test;

Full Screen

Full Screen

checkIsNotEmptySequence

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.api.Assertions;2import org.assertj.core.internal.Iterables;3import java.util.Arrays;4import java.util.List;5public class AssertJAssertIterableIsNotEmpty {6 public static void main(String[] args) {7 List<String> list = Arrays.asList("one", "two", "three");8 Assertions.assertThat(list).isNotEmpty();9 Assertions.assertThat(list).isNotNull();10 Iterables iterables = new Iterables();11 iterables.checkIsNotEmptySequence(list);12 }13}14org.assertj.core.internal.Iterables.checkIsNotEmptySequence(Iterables.java:50)15org.assertj.core.internal.Iterables.checkIsNotEmpty(Iterables.java:46)16org.assertj.core.api.AbstractIterableAssert.checkIsNotNullAndNotEmpty(AbstractIterableAssert.java:110)17org.assertj.core.api.AbstractIterableAssert.isNotEmpty(AbstractIterableAssert.java:103)18com.baeldung.assertj.AssertJAssertIterableIsNotEmpty.main(AssertJAssertIterableIsNotEmpty.java:16)

Full Screen

Full Screen

checkIsNotEmptySequence

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.api.Assertions;2import org.assertj.core.internal.Iterables;3public class IterablesExample {4 public static void main(String[] args) {5 Iterables iterables = new Iterables();6 iterables.checkIsNotEmptySequence(Assertions.informationProvider(), Arrays.asList(1, 2, 3), new ArrayList<>());7 }8}9package org.assertj.core.api.iterable;10import static org.assertj.core.api.Assertions.assertThat;11import static org.assertj.core.test.TestData.someInfo;12import static org.assertj.core.util.FailureMessages.actualIsNull;13import java.util.Arrays;14import org.assertj.core.api.AbstractIterableAssert;15import org.assertj.core.api.IterableAssert;16import org.assertj.core.api.IterableAssertBaseTest;17import org.assertj.core.internal.Iterables;18import org.assertj.core.internal.IterablesBaseTest;19import org.junit.jupiter.api.Test;

Full Screen

Full Screen

checkIsNotEmptySequence

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.api.Assertions;2import org.assertj.core.internal.Iterables;3import java.util.Arrays;4import java.util.List;5public class AssertJAssertIterableIsNotEmpty {6 public static void main(String[] args) {7 List<String> list = Arrays.asList("one", "two", "three");8 Assertions.assertThat(list).isNotEmpty();9 Assertions.assertThat(list).isNotNull();10 Iterables iterables = new Iterables();11 iterables.checkIsNotEmptySequence(list);12 }13}14org.assertj.core.internal.Iterables.checkIsNotEmptySequence(Iterables.java:50)15org.assertj.core.internal.Iterables.checkIsNotEmpty(Iterables.java:46)16org.assertj.core.api.AbstractIterableAssert.checkIsNotNullAndNotEmpty(AbstractIterableAssert.java:110)17org.assertj.core.api.AbstractIterableAssert.isNotEmpty(AbstractIterableAssert.java:103)18com.baeldung.assertj.AssertJAssertIterableIsNotEmpty.main(AssertJAssertIterableIsNotEmpty.java:16)

Full Screen

Full Screen

checkIsNotEmptySequence

Using AI Code Generation

copy

Full Screen

1public void test_checkIsNotEmptySequence() {2 final List<String> actual = new ArrayList<String>();3 actual.add("1");4 actual.add("2");5 actual.add("3");6 final List<String> sequence = new ArrayList<String>();7 sequence.add("1");8 sequence.add("2");9 iterables.checkIsNotEmptySequence(info, actual, sequence);10}11public void test_checkIsNotEmptySequence2() {12 final List<String> actual = new ArrayList<String>();13 actual.add("1");14 actual.add("2");15 actual.add("3");16 final List<String> sequence = new ArrayList<String>();17 sequence.add("1");18 sequence.add("2");19 sequence.add("3");20 iterables.checkIsNotEmptySequence(info, actual, sequence);21}22public void test_checkIsNotEmptySequence3() {23 final List<String> actual = new ArrayList<String>();24 actual.add("1");25 actual.add("2");26 actual.add("3");27 final List<String> sequence = new ArrayList<String>();28 sequence.add("1");29 sequence.add("3");30 iterables.checkIsNotEmptySequence(info, actual, sequence);31}32public void test_checkIsNotEmptySequence4() {33 final List<String> actual = new ArrayList<String>();34 actual.add("1");35 actual.add("2");36 actual.add("3");37 final List<String> sequence = new ArrayList<String>();38 sequence.add("1");39 sequence.add("4");40 iterables.checkIsNotEmptySequence(info, actual, sequence);41}42public void test_checkIsNotEmptySequence5() {43 final List<String> actual = new ArrayList<String>();44 actual.add("1");

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Assertj automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in Iterables

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful