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

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

Source:Iterables_assertContainsExactlyInAnyOrder_Test.java Github

copy

Full Screen

...26import org.assertj.core.util.Lists;27import org.junit.jupiter.api.Test;28import org.mockito.Mockito;29/**30 * Tests for <code>{@link Iterables#assertContainsExactlyInAnyOrder(AssertionInfo, Iterable, Object[])} </code>.31 *32 * @author Lovro Pandzic33 */34public class Iterables_assertContainsExactlyInAnyOrder_Test extends IterablesBaseTest {35 @Test36 public void should_pass_if_actual_contains_exactly_given_values() {37 iterables.assertContainsExactlyInAnyOrder(TestData.someInfo(), actual, Arrays.array("Luke", "Yoda", "Leia"));38 }39 @Test40 public void should_pass_if_actual_contains_given_values_exactly_with_null_elements() {41 iterables.assertContainsExactlyInAnyOrder(TestData.someInfo(), actual, Arrays.array("Leia", "Yoda", "Luke"));42 actual.add(null);43 iterables.assertContainsExactlyInAnyOrder(TestData.someInfo(), actual, Arrays.array("Leia", null, "Yoda", "Luke"));44 }45 @Test46 public void should_pass_if_actual_and_given_values_are_empty() {47 actual.clear();48 iterables.assertContainsExactlyInAnyOrder(TestData.someInfo(), actual, Arrays.array());49 }50 @Test51 public void should_fail_if_array_of_values_to_look_for_is_empty_and_actual_is_not() {52 Assertions.assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> iterables.assertContainsExactlyInAnyOrder(someInfo(), actual, emptyArray()));53 }54 @Test55 public void should_fail_if_expected_is_null() {56 Assertions.assertThatNullPointerException().isThrownBy(() -> iterables.assertContainsExactlyInAnyOrder(someInfo(), emptyList(), null)).withMessage(ErrorMessages.valuesToLookForIsNull());57 }58 @Test59 public void should_fail_if_actual_is_null() {60 Assertions.assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> iterables.assertContainsExactlyInAnyOrder(someInfo(), null, emptyArray())).withMessage(FailureMessages.actualIsNull());61 }62 @Test63 public void should_fail_if_actual_does_not_contain_given_values_exactly() {64 AssertionInfo info = TestData.someInfo();65 Object[] expected = new Object[]{ "Luke", "Yoda", "Han" };66 try {67 iterables.assertContainsExactlyInAnyOrder(info, actual, expected);68 } catch (AssertionError e) {69 Mockito.verify(failures).failure(info, ShouldContainExactlyInAnyOrder.shouldContainExactlyInAnyOrder(actual, expected, Lists.newArrayList("Han"), Lists.newArrayList("Leia"), StandardComparisonStrategy.instance()));70 return;71 }72 TestFailures.failBecauseExpectedAssertionErrorWasNotThrown();73 }74 @Test75 public void should_pass_if_actual_contains_all_given_values_in_different_order() {76 AssertionInfo info = TestData.someInfo();77 Object[] expected = new Object[]{ "Luke", "Leia", "Yoda" };78 iterables.assertContainsExactlyInAnyOrder(info, actual, expected);79 }80 @Test81 public void should_fail_if_actual_contains_duplicates_and_expected_does_not() {82 AssertionInfo info = TestData.someInfo();83 actual = Lists.newArrayList("Luke", "Leia", "Luke");84 Object[] expected = new Object[]{ "Luke", "Leia" };85 try {86 iterables.assertContainsExactlyInAnyOrder(info, actual, expected);87 } catch (AssertionError e) {88 Mockito.verify(failures).failure(info, ShouldContainExactlyInAnyOrder.shouldContainExactlyInAnyOrder(actual, expected, Collections.emptyList(), Lists.newArrayList("Luke"), StandardComparisonStrategy.instance()));89 return;90 }91 TestFailures.failBecauseExpectedAssertionErrorWasNotThrown();92 }93 @Test94 public void should_fail_if_expected_contains_duplicates_and_actual_does_not() {95 AssertionInfo info = TestData.someInfo();96 actual = Lists.newArrayList("Luke", "Leia");97 Object[] expected = new Object[]{ "Luke", "Leia", "Luke" };98 try {99 iterables.assertContainsExactlyInAnyOrder(info, actual, expected);100 } catch (AssertionError e) {101 Mockito.verify(failures).failure(info, ShouldContainExactlyInAnyOrder.shouldContainExactlyInAnyOrder(actual, expected, Lists.newArrayList("Luke"), Collections.emptyList(), StandardComparisonStrategy.instance()));102 return;103 }104 TestFailures.failBecauseExpectedAssertionErrorWasNotThrown();105 }106 // ------------------------------------------------------------------------------------------------------------------107 // tests using a custom comparison strategy108 // ------------------------------------------------------------------------------------------------------------------109 @Test110 public void should_pass_if_actual_contains_given_values_exactly_according_to_custom_comparison_strategy() {111 iterablesWithCaseInsensitiveComparisonStrategy.assertContainsExactlyInAnyOrder(TestData.someInfo(), actual, Arrays.array("LUKE", "YODA", "Leia"));112 }113 @Test114 public void should_fail_if_actual_does_not_contain_given_values_exactly_according_to_custom_comparison_strategy() {115 AssertionInfo info = TestData.someInfo();116 Object[] expected = new Object[]{ "Luke", "Yoda", "Han" };117 try {118 iterablesWithCaseInsensitiveComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected);119 } catch (AssertionError e) {120 Mockito.verify(failures).failure(info, ShouldContainExactlyInAnyOrder.shouldContainExactlyInAnyOrder(actual, expected, Lists.newArrayList("Han"), Lists.newArrayList("Leia"), comparisonStrategy));121 return;122 }123 TestFailures.failBecauseExpectedAssertionErrorWasNotThrown();124 }125 @Test126 public void should_pass_if_actual_contains_all_given_values_in_different_order_according_to_custom_comparison_strategy() {127 AssertionInfo info = TestData.someInfo();128 Object[] expected = new Object[]{ "Luke", "Leia", "Yoda" };129 iterablesWithCaseInsensitiveComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected);130 }131 @Test132 public void should_fail_if_actual_contains_all_given_values_but_size_differ_according_to_custom_comparison_strategy() {133 AssertionInfo info = TestData.someInfo();134 actual = Lists.newArrayList("Luke", "Leia", "Luke");135 Object[] expected = new Object[]{ "LUKE", "Leia" };136 try {137 iterablesWithCaseInsensitiveComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected);138 } catch (AssertionError e) {139 Mockito.verify(failures).failure(info, ShouldContainExactlyInAnyOrder.shouldContainExactlyInAnyOrder(actual, expected, Collections.emptyList(), Lists.newArrayList("Luke"), comparisonStrategy));140 return;141 }142 TestFailures.failBecauseExpectedAssertionErrorWasNotThrown();143 }144}...

Full Screen

Full Screen

assertContainsExactlyInAnyOrder

Using AI Code Generation

copy

Full Screen

1import org.junit.Test;2import org.assertj.core.util.Lists;3import org.assertj.core.internal.Iterables;4public class AssertContainsExactlyInAnyOrderTest {5 public void test() {6 Iterables iterables = new Iterables();7 iterables.assertContainsExactlyInAnyOrder(null, Lists.newArrayList(1, 2, 3), Lists.newArrayList(3, 2, 1));8 }9}10assertContainsExactly(AssertionInfo info, Iterable<?> actual, Object[] values)11assertContainsExactly(AssertionInfo info, Iterable<?> actual, Object[] values, Comparator<?> customComparator)12assertContainsExactly(AssertionInfo info, Iterable<?> actual, Iterable<?> values)13assertContainsExactly(AssertionInfo info, Iterable<?> actual, Iterable<?> values, Comparator<?> customComparator)14assertContainsExactly(AssertionInfo info, Iterable<?> actual, Iterable<?> values, Extractor<?, ?> extractor)15assertContainsExactly(AssertionInfo info, Iterable<?> actual, Iterable<?> values, Extractor<?, ?> extractor, Comparator<?> customComparator)16assertContainsExactly(AssertionInfo info, Iterable<?> actual, Iterable<?> values, Extractor<?, ?>[] extractors)17assertContainsExactly(AssertionInfo info, Iterable<?> actual, Iterable<?> values, Extractor<?, ?>

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