Best Assertj code snippet using org.assertj.core.internal.Iterables.assertContainsAnyOf
Source:Iterables_assertContainsAnyOf_Test.java
...25import org.junit.jupiter.api.Test;26import org.mockito.Mockito;27import static java.util.Arrays.asList;28/**29 * Tests for <code>{@link Iterables#assertContainsAnyOf(AssertionInfo, Iterable, Object[])} </code>.30 *31 * @author Marko Bekhta32 */33public class Iterables_assertContainsAnyOf_Test extends IterablesBaseTest {34 @Test35 public void should_pass_if_actual_contains_given_values() {36 iterables.assertContainsAnyOf(TestData.someInfo(), actual, Arrays.array("Luke"));37 }38 @Test39 public void should_pass_with_non_comparable_values() {40 // GIVEN41 Iterable<Name> names = asList(Name.name("John", "Doe"));42 // THEN43 iterables.assertContainsAnyOf(TestData.someInfo(), names, Arrays.array(Name.name("John", "Doe"), Name.name("Jane", "Doe")));44 }45 @Test46 public void should_pass_if_actual_contains_given_values_in_different_order() {47 iterables.assertContainsAnyOf(TestData.someInfo(), actual, Arrays.array("Leia", "Yoda"));48 }49 @Test50 public void should_pass_if_actual_contains_all_given_values() {51 iterables.assertContainsAnyOf(TestData.someInfo(), actual, Arrays.array("Luke", "Yoda", "Leia"));52 }53 @Test54 public void should_pass_if_actual_contains_given_values_more_than_once() {55 actual.addAll(Lists.newArrayList("Luke", "Luke"));56 iterables.assertContainsAnyOf(TestData.someInfo(), actual, Arrays.array("Luke"));57 }58 @Test59 public void should_pass_if_actual_contains_just_one_of_given_values() {60 iterables.assertContainsAnyOf(TestData.someInfo(), actual, Arrays.array("Luke", "John", "Tom"));61 }62 @Test63 public void should_pass_if_actual_contains_given_values_even_if_duplicated() {64 iterables.assertContainsAnyOf(TestData.someInfo(), actual, Arrays.array("Luke", "Luke"));65 }66 @Test67 public void should_pass_if_actual_and_given_values_are_empty() {68 actual.clear();69 iterables.assertContainsAnyOf(TestData.someInfo(), actual, Arrays.array());70 }71 @Test72 public void should_fail_if_array_of_values_to_look_for_is_empty_and_actual_is_not() {73 Assertions.assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> iterables.assertContainsAnyOf(someInfo(), actual, emptyArray()));74 }75 @Test76 public void should_throw_error_if_array_of_values_to_look_for_is_null() {77 Assertions.assertThatNullPointerException().isThrownBy(() -> iterables.assertContainsAnyOf(someInfo(), actual, null)).withMessage(ErrorMessages.valuesToLookForIsNull());78 }79 @Test80 public void should_fail_if_actual_is_null() {81 Assertions.assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> iterables.assertContainsAnyOf(someInfo(), null, array("Yoda"))).withMessage(FailureMessages.actualIsNull());82 }83 @Test84 public void should_fail_if_actual_does_not_contain_any_of_the_given_values() {85 AssertionInfo info = TestData.someInfo();86 Object[] expected = new Object[]{ "Han", "John" };87 try {88 iterables.assertContainsAnyOf(info, actual, expected);89 } catch (AssertionError e) {90 Mockito.verify(failures).failure(info, ShouldContainAnyOf.shouldContainAnyOf(actual, expected));91 return;92 }93 TestFailures.failBecauseExpectedAssertionErrorWasNotThrown();94 }95 // ------------------------------------------------------------------------------------------------------------------96 // tests using a custom comparison strategy97 // ------------------------------------------------------------------------------------------------------------------98 @Test99 public void should_pass_if_actual_contains_given_values_according_to_custom_comparison_strategy() {100 iterablesWithCaseInsensitiveComparisonStrategy.assertContainsAnyOf(TestData.someInfo(), actual, Arrays.array("LUKE"));101 }102 @Test103 public void should_pass_if_actual_contains_given_values_in_different_order_according_to_custom_comparison_strategy() {104 iterablesWithCaseInsensitiveComparisonStrategy.assertContainsAnyOf(TestData.someInfo(), actual, Arrays.array("LEIA", "yODa"));105 }106 @Test107 public void should_pass_if_actual_contains_all_given_values_according_to_custom_comparison_strategy() {108 iterablesWithCaseInsensitiveComparisonStrategy.assertContainsAnyOf(TestData.someInfo(), actual, Arrays.array("luke", "YODA", "leia"));109 }110 @Test111 public void should_pass_if_actual_contains_given_values_more_than_once_according_to_custom_comparison_strategy() {112 actual.addAll(Lists.newArrayList("Luke", "Luke"));113 iterablesWithCaseInsensitiveComparisonStrategy.assertContainsAnyOf(TestData.someInfo(), actual, Arrays.array("LUke"));114 }115 @Test116 public void should_pass_if_actual_contains_given_values_even_if_duplicated_according_to_custom_comparison_strategy() {117 iterablesWithCaseInsensitiveComparisonStrategy.assertContainsAnyOf(TestData.someInfo(), actual, Arrays.array("LUke", "LuKe"));118 }119 @Test120 public void should_pass_if_actual_contains_just_one_of_given_values_according_to_custom_comparison_strategy() {121 iterablesWithCaseInsensitiveComparisonStrategy.assertContainsAnyOf(TestData.someInfo(), actual, Arrays.array("LuKe", "JoHn", "ToM"));122 }123 @Test124 public void should_fail_if_actual_does_not_contain_values_according_to_custom_comparison_strategy() {125 AssertionInfo info = TestData.someInfo();126 Object[] expected = new Object[]{ "Han", "John" };127 try {128 iterablesWithCaseInsensitiveComparisonStrategy.assertContainsAnyOf(info, actual, expected);129 } catch (AssertionError e) {130 Mockito.verify(failures).failure(info, ShouldContainAnyOf.shouldContainAnyOf(actual, expected, comparisonStrategy));131 return;132 }133 TestFailures.failBecauseExpectedAssertionErrorWasNotThrown();134 }135}...
assertContainsAnyOf
Using AI Code Generation
1package com.baeldung.assertj;2import static org.assertj.core.api.Assertions.assertThat;3import java.util.ArrayList;4import java.util.List;5import org.junit.Test;6public class AssertJAssertContainsAnyOfUnitTest {7 public void givenList_whenContainsAnyOf_thenCorrect() {8 List<String> list = new ArrayList<>();9 list.add("One");10 list.add("Two");11 list.add("Three");12 assertThat(list).containsAnyOf("One", "Two");13 }14}15package com.baeldung.assertj;16import static org.assertj.core.api.Assertions.assertThat;17import java.util.ArrayList;18import java.util.List;19import org.junit.Test;20public class AssertJAssertContainsAnyOfUnitTest {21 public void givenList_whenContainsAnyOf_thenCorrect() {22 List<String> list = new ArrayList<>();23 list.add("One");24 list.add("Two");25 list.add("Three");26 assertThat(list).containsAnyOf("One", "Two");27 }28}29package com.baeldung.assertj;30import static org.assertj.core.api.Assertions.assertThat;31import java.util.ArrayList;32import java.util.List;33import org.junit.Test;34public class AssertJAssertContainsAnyOfUnitTest {35 public void givenList_whenContainsAnyOf_thenCorrect() {36 List<String> list = new ArrayList<>();37 list.add("One");38 list.add("Two");39 list.add("Three");40 assertThat(list).containsAnyOf("One", "Two");41 }42}43package com.baeldung.assertj;44import static org.assertj.core.api.Assertions.assertThat;45import org.junit.Test;46public class AssertJAssertContainsAnyOfUnitTest {47 public void givenString_whenContainsAnyOf_thenCorrect() {48 String str = "One Two Three";49 assertThat(str).containsAnyOf("One", "Two");50 }51}52package com.baeldung.assertj;53import static org.assertj.core.api.Assertions.assertThat;54import org.junit.Test;55public class AssertJAssertContainsAnyOfUnitTest {
assertContainsAnyOf
Using AI Code Generation
1package org.assertj.core.internal;2import java.util.Arrays;3import java.util.List;4import org.assertj.core.api.AbstractAssert;5import org.assertj.core.api.AssertionInfo;6import org.assertj.core.internal.Failures;7import org.assertj.core.internal.StandardComparisonStrategy;8import org.assertj.core.util.VisibleForTesting;9import org.assertj.core.util.introspection.IntrospectionError;10import org.assertj.core.util.introspection.IntrospectionUtils;11import org.assertj.core.util.introspection.PropertyOrFieldSupport;12public class Iterables {13 private static final Iterables INSTANCE = new Iterables();14 private final Failures failures = Failures.instance();15 PropertyOrFieldSupport propertyOrFieldSupport = new PropertyOrFieldSupport();16 public static Iterables instance() {17 return INSTANCE;18 }19 Iterables() {20 }21 public void assertContainsAnyOf(AssertionInfo info, Iterable<?> actual, Object[] values) {22 assertNotNull(info, actual);23 assertNotNull(info, values);24 checkIsNotNull(values);25 if (values.length == 0)26 throw failures.failure(info, shouldContainAnyOf(actual, values));27 if (actualIsEmpty(actual))28 throw failures.failure(info, shouldContainAnyOf(actual, values));29 List<?> actualAsList = Arrays.asList(actual.toArray());30 for (Object value : values) {31 if (actualAsList.contains(value))32 return;33 }34 throw failures.failure(info, shouldContainAnyOf(actual, values));35 }36 private void checkIsNotNull(Object[] values) {37 for (Object value : values) {38 if (value == null)39 throw new NullPointerException("Expecting element not to be null but found null");40 }41 }42 private boolean actualIsEmpty(Iterable<?> actual) {43 return !actual.iterator().hasNext();44 }45 private void assertNotNull(AssertionInfo info, Object[] values) {46 if (values == null)47 throw failures.failure(info, shouldNotBeNull());48 }49 private void assertNotNull(AssertionInfo info, Iterable<?> actual) {50 assertNotNull(info, actual);51 }52}53import static org.assertj.core.api.Assertions.assertThat;54import static org.assertj.core.api.Assertions.assertThatThrownBy;55import static org.assertj.core.api.Assertions.catchThrowable;56import static org.assertj.core.error.ShouldContainAnyOf
assertContainsAnyOf
Using AI Code Generation
1public void testAssertContainsAnyOf() {2 List<String> actual = Arrays.asList("foo", "bar", "baz");3 Iterables.assertContainsAnyOf(info, actual, "foo", "bar");4}5public void testAssertContainsAnyOf() {6 List<String> actual = Arrays.asList("foo", "bar", "baz");7 assertThat(actual).containsAnyOf("foo", "bar");8}9public void testAssertContainsAnyOf() {10 List<String> actual = Arrays.asList("foo", "bar", "baz");11 assertThat(actual).containsAnyOf("foo", "bar");12}13public void testAssertContainsAnyOf() {14 List<String> actual = Arrays.asList("foo", "bar", "baz");15 assertThat(actual).containsAnyOf("foo", "bar");16}17public void testAssertContainsAnyOf() {18 List<String> actual = Arrays.asList("foo", "bar", "baz");19 assertThat(actual).containsAnyOf("foo", "bar");20}21public void testAssertContainsAnyOf() {22 List<String> actual = Arrays.asList("foo", "bar", "baz");23 assertThat(actual).containsAnyOf("foo", "bar");24}25public void testAssertContainsAnyOf() {26 List<String> actual = Arrays.asList("foo", "bar", "baz");27 assertThat(actual).containsAnyOf("foo", "bar");28}29public void testAssertContainsAnyOf() {30 List<String> actual = Arrays.asList("foo", "bar", "baz");31 assertThat(actual).containsAnyOf("foo", "bar");32}33public void testAssertContainsAnyOf() {34 List<String> actual = Arrays.asList("foo", "bar", "baz");35 assertThat(actual).containsAnyOf("foo", "bar");36}
assertContainsAnyOf
Using AI Code Generation
1import org.junit.Test;2import static org.assertj.core.api.Assertions.assertThat;3public class IterablesAssert_containsAnyOf_Test {4 public void should_pass_if_actual_contains_any_of_given_values() {5 assertThat(newArrayList("Luke", "Yoda", "Leia")).containsAnyOf("Luke", "Han");6 }7 public void should_fail_if_actual_does_not_contain_any_of_given_values() {8 thrown.expect(AssertionError.class);9 assertThat(newArrayList("Luke", "Yoda", "Leia")).containsAnyOf("Han", "Chewbacca");10 }11}12package org.assertj.core.api.iterable;13import static org.assertj.core.api.Assertions.assertThat;14import static org.assertj.core.test.ExpectedException.none;15import static org.assertj.core.util.Lists.newArrayList;16import org.assertj.core.api.IterableAssert;17import org.assertj.core.api.IterableAssertBaseTest;18import org.assertj.core.test.ExpectedException;19import org.junit.Rule;20import org.junit.Test;21public class IterablesAssert_containsAnyOf_Test extends IterableAssertBaseTest {22 public ExpectedException thrown = none();23 protected IterableAssert<Object> invoke_api_method() {24 return assertions.containsAnyOf("Luke", "Han");25 }26 protected void verify_internal_effects() {27 assertThat(getObjects(assertions)).containsAnyOf("Luke", "Han");28 }29 public void should_fail_if_actual_does_not_contain_any_of_given_values() {30 thrown.expectAssertionError("%nExpecting:%n <[\"Luke\", \"Yoda\", \"Leia\"]>%nto contain any of:%n <[\"Han\", \"Chewbacca\"]>%nbut could not find any of them");31 assertThat(newArrayList("Luke", "Yoda", "Leia")).containsAnyOf("Han", "Chewbacca");32 }33}34package org.assertj.core.internal.iterables;35import static org.assertj.core.error.ShouldContainAnyOf.shouldContainAnyOf;36import static org.assertj.core.test.ErrorMessages.*;37import static org.assertj.core.test.ExpectedException.none;38import static org.assertj.core.test.TestData.someInfo;39import static org.assertj.core
assertContainsAnyOf
Using AI Code Generation
1public class Iterables_assertContainsAnyOf_Test {2 public void test() {3 }4}5[INFO] --- maven-jar-plugin:3.1.2:jar (default-jar) @ assertj-core ---6[INFO] --- maven-failsafe-plugin:2.22.1:integration-test (default) @ assertj-core ---7[INFO] --- maven-failsafe-plugin:2.22.1:verify (default) @ assertj-core ---8[INFO] --- maven-jar-plugin:3.1.2:test-jar (default) @ assertj-core ---
assertContainsAnyOf
Using AI Code Generation
1String[] fruits = {"apple", "banana", "orange", "melon", "mango"};2Iterables iterables = new Iterables();3iterables.assertContainsAnyOf(info, fruits, "apple", "coconut", "banana", "melon");4iterables.assertContainsAnyOf(info, fruits, "coconut", "peach");5iterables.assertContainsAnyOf(info, fruits, "coconut");6iterables.assertContainsAnyOf(info, fruits, "apple", "banana", "orange", "melon", "mango");7iterables.assertContainsAnyOf(info, fruits, "apple", "banana", "orange", "melon", "mango", "coconut");8iterables.assertContainsAnyOf(info, fruits, "coconut", "peach", "apple", "banana", "orange", "melon", "mango");9iterables.assertContainsAnyOf(info, fruits, "coconut", "peach
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!