Best Assertj code snippet using org.assertj.core.error.ShouldContainExactlyInAnyOrder
Source:ByteArrays_assertContainsExactlyInAnyOrder_Test.java
...12 */13package org.assertj.core.internal.bytearrays;14import org.assertj.core.api.AssertionInfo;15import org.assertj.core.api.Assertions;16import org.assertj.core.error.ShouldContainExactlyInAnyOrder;17import org.assertj.core.internal.ByteArraysBaseTest;18import org.assertj.core.internal.ErrorMessages;19import org.assertj.core.internal.StandardComparisonStrategy;20import org.assertj.core.test.ByteArrays;21import org.assertj.core.test.TestData;22import org.assertj.core.test.TestFailures;23import org.assertj.core.util.FailureMessages;24import org.assertj.core.util.Lists;25import org.junit.jupiter.api.Test;26import org.mockito.Mockito;27/**28 * Tests for <code>{@link ByteArrays#assertContainsExactlyInAnyOrder(AssertionInfo, byte[], byte[])}</code>.29 */30public class ByteArrays_assertContainsExactlyInAnyOrder_Test extends ByteArraysBaseTest {31 @Test32 public void should_pass_if_actual_contains_given_values_exactly_in_any_order() {33 arrays.assertContainsExactlyInAnyOrder(TestData.someInfo(), actual, ByteArrays.arrayOf(6, 8, 10));34 }35 @Test36 public void should_pass_if_actual_and_given_values_are_empty() {37 arrays.assertContainsExactlyInAnyOrder(TestData.someInfo(), ByteArrays.emptyArray(), ByteArrays.emptyArray());38 }39 @Test40 public void should_pass_if_actual_contains_given_values_exactly_but_in_different_order() {41 AssertionInfo info = TestData.someInfo();42 arrays.assertContainsExactlyInAnyOrder(info, actual, ByteArrays.arrayOf(6, 10, 8));43 }44 @Test45 public void should_fail_if_arrays_have_different_sizes() {46 Assertions.assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, arrayOf(6, 8)));47 }48 @Test49 public void should_fail_if_expected_is_empty_and_actual_is_not() {50 Assertions.assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, emptyArray()));51 }52 @Test53 public void should_throw_error_expected_is_null() {54 Assertions.assertThatNullPointerException().isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, ((byte[]) (null)))).withMessage(ErrorMessages.valuesToLookForIsNull());55 }56 @Test57 public void should_fail_if_actual_is_null() {58 Assertions.assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), null, arrayOf(8))).withMessage(FailureMessages.actualIsNull());59 }60 @Test61 public void should_fail_if_actual_does_not_contain_given_values_exactly() {62 AssertionInfo info = TestData.someInfo();63 byte[] expected = new byte[]{ 6, 8, 20 };64 try {65 arrays.assertContainsExactlyInAnyOrder(info, actual, expected);66 } catch (AssertionError e) {67 Mockito.verify(failures).failure(info, ShouldContainExactlyInAnyOrder.shouldContainExactlyInAnyOrder(actual, expected, Lists.newArrayList(((byte) (20))), Lists.newArrayList(((byte) (10))), StandardComparisonStrategy.instance()));68 return;69 }70 TestFailures.failBecauseExpectedAssertionErrorWasNotThrown();71 }72 @Test73 public void should_fail_if_actual_contains_all_given_values_but_size_differ() {74 AssertionInfo info = TestData.someInfo();75 byte[] expected = new byte[]{ 6, 8 };76 try {77 arrays.assertContainsExactlyInAnyOrder(info, actual, expected);78 } catch (AssertionError e) {79 Mockito.verify(failures).failure(info, ShouldContainExactlyInAnyOrder.shouldContainExactlyInAnyOrder(actual, expected, Lists.emptyList(), Lists.newArrayList(((byte) (10))), StandardComparisonStrategy.instance()));80 return;81 }82 TestFailures.failBecauseExpectedAssertionErrorWasNotThrown();83 }84 @Test85 public void should_fail_if_actual_contains_duplicates_and_expected_does_not() {86 AssertionInfo info = TestData.someInfo();87 actual = ByteArrays.arrayOf(6, 8, 8);88 byte[] expected = new byte[]{ 6, 8 };89 try {90 arrays.assertContainsExactlyInAnyOrder(info, actual, expected);91 } catch (AssertionError e) {92 Mockito.verify(failures).failure(info, ShouldContainExactlyInAnyOrder.shouldContainExactlyInAnyOrder(actual, expected, Lists.emptyList(), Lists.newArrayList(((byte) (8))), StandardComparisonStrategy.instance()));93 return;94 }95 TestFailures.failBecauseExpectedAssertionErrorWasNotThrown();96 }97 @Test98 public void should_fail_if_expected_contains_duplicates_and_actual_does_not() {99 AssertionInfo info = TestData.someInfo();100 actual = ByteArrays.arrayOf(6, 8);101 byte[] expected = new byte[]{ 6, 8, 8 };102 try {103 arrays.assertContainsExactlyInAnyOrder(info, actual, expected);104 } catch (AssertionError e) {105 Mockito.verify(failures).failure(info, ShouldContainExactlyInAnyOrder.shouldContainExactlyInAnyOrder(actual, expected, Lists.newArrayList(((byte) (8))), Lists.emptyList(), StandardComparisonStrategy.instance()));106 return;107 }108 TestFailures.failBecauseExpectedAssertionErrorWasNotThrown();109 }110 // ------------------------------------------------------------------------------------------------------------------111 // tests using a custom comparison strategy112 // ------------------------------------------------------------------------------------------------------------------113 @Test114 public void should_pass_if_actual_contains_given_values_exactly_in_any_order_according_to_custom_comparison_strategy() {115 arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(TestData.someInfo(), actual, ByteArrays.arrayOf(6, (-8), 10));116 }117 @Test118 public void should_pass_if_actual_contains_given_values_exactly_in_different_order_according_to_custom_comparison_strategy() {119 byte[] expected = new byte[]{ -6, 10, 8 };120 arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(TestData.someInfo(), actual, expected);121 }122 @Test123 public void should_fail_if_expected_is_empty_and_actual_is_not_whatever_custom_comparison_strategy_is() {124 Assertions.assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), actual, emptyArray()));125 }126 @Test127 public void should_throw_error_if_expected_is_null_whatever_custom_comparison_strategy_is() {128 Assertions.assertThatNullPointerException().isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), actual, ((byte[]) (null)))).withMessage(ErrorMessages.valuesToLookForIsNull());129 }130 @Test131 public void should_fail_if_actual_is_null_whatever_custom_comparison_strategy_is() {132 Assertions.assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), null, arrayOf((-8)))).withMessage(FailureMessages.actualIsNull());133 }134 @Test135 public void should_fail_if_actual_does_not_contain_given_values_exactly_in_any_order_according_to_custom_comparison_strategy() {136 AssertionInfo info = TestData.someInfo();137 byte[] expected = new byte[]{ 6, -8, 20 };138 try {139 arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected);140 } catch (AssertionError e) {141 Mockito.verify(failures).failure(info, ShouldContainExactlyInAnyOrder.shouldContainExactlyInAnyOrder(actual, expected, Lists.newArrayList(((byte) (20))), Lists.newArrayList(((byte) (10))), absValueComparisonStrategy));142 return;143 }144 TestFailures.failBecauseExpectedAssertionErrorWasNotThrown();145 }146 @Test147 public void should_fail_if_actual_contains_all_given_values_but_size_differ_according_to_custom_comparison_strategy() {148 AssertionInfo info = TestData.someInfo();149 byte[] expected = new byte[]{ 6, 8 };150 try {151 arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected);152 } catch (AssertionError e) {153 Mockito.verify(failures).failure(info, ShouldContainExactlyInAnyOrder.shouldContainExactlyInAnyOrder(actual, expected, Lists.emptyList(), Lists.newArrayList(((byte) (10))), absValueComparisonStrategy));154 return;155 }156 TestFailures.failBecauseExpectedAssertionErrorWasNotThrown();157 }158 @Test159 public void should_fail_if_actual_contains_duplicates_and_expected_does_not_according_to_custom_comparison_strategy() {160 AssertionInfo info = TestData.someInfo();161 actual = ByteArrays.arrayOf(6, 8, 8);162 byte[] expected = new byte[]{ 6, 8 };163 try {164 arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected);165 } catch (AssertionError e) {166 Mockito.verify(failures).failure(info, ShouldContainExactlyInAnyOrder.shouldContainExactlyInAnyOrder(actual, expected, Lists.emptyList(), Lists.newArrayList(((byte) (8))), absValueComparisonStrategy));167 return;168 }169 TestFailures.failBecauseExpectedAssertionErrorWasNotThrown();170 }171 @Test172 public void should_fail_if_expected_contains_duplicates_and_actual_does_not_according_to_custom_comparison_strategy() {173 AssertionInfo info = TestData.someInfo();174 actual = ByteArrays.arrayOf(6, 8);175 byte[] expected = new byte[]{ 6, 8, 8 };176 try {177 arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected);178 } catch (AssertionError e) {179 Mockito.verify(failures).failure(info, ShouldContainExactlyInAnyOrder.shouldContainExactlyInAnyOrder(actual, expected, Lists.newArrayList(((byte) (8))), Lists.emptyList(), absValueComparisonStrategy));180 return;181 }182 TestFailures.failBecauseExpectedAssertionErrorWasNotThrown();183 }184}...
Source:CharArrays_assertContainsExactlyInAnyOrder_Test.java
...12 */13package org.assertj.core.internal.chararrays;14import org.assertj.core.api.AssertionInfo;15import org.assertj.core.api.Assertions;16import org.assertj.core.error.ShouldContainExactlyInAnyOrder;17import org.assertj.core.internal.CharArraysBaseTest;18import org.assertj.core.internal.ErrorMessages;19import org.assertj.core.internal.StandardComparisonStrategy;20import org.assertj.core.test.CharArrays;21import org.assertj.core.test.TestData;22import org.assertj.core.test.TestFailures;23import org.assertj.core.util.FailureMessages;24import org.assertj.core.util.Lists;25import org.junit.jupiter.api.Test;26import org.mockito.Mockito;27/**28 * Tests for <code>{@link CharArrays#assertContainsExactlyInAnyOrder(AssertionInfo, char[], char[])}</code>.29 */30public class CharArrays_assertContainsExactlyInAnyOrder_Test extends CharArraysBaseTest {31 @Test32 public void should_pass_if_actual_contains_given_values_exactly_in_any_order() {33 arrays.assertContainsExactlyInAnyOrder(TestData.someInfo(), actual, CharArrays.arrayOf('a', 'b', 'c'));34 }35 @Test36 public void should_pass_if_actual_and_given_values_are_empty() {37 arrays.assertContainsExactlyInAnyOrder(TestData.someInfo(), CharArrays.emptyArray(), CharArrays.emptyArray());38 }39 @Test40 public void should_pass_if_actual_contains_given_values_exactly_but_in_different_order() {41 AssertionInfo info = TestData.someInfo();42 arrays.assertContainsExactlyInAnyOrder(info, actual, CharArrays.arrayOf('a', 'c', 'b'));43 }44 @Test45 public void should_fail_if_arrays_have_different_sizes() {46 Assertions.assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, arrayOf('a', 'b')));47 }48 @Test49 public void should_fail_if_expected_empty_and_actual_is_not() {50 Assertions.assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, emptyArray()));51 }52 @Test53 public void should_throw_error_if_expected_null() {54 Assertions.assertThatNullPointerException().isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, null)).withMessage(ErrorMessages.valuesToLookForIsNull());55 }56 @Test57 public void should_fail_if_actual_is_null() {58 Assertions.assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), null, arrayOf('b'))).withMessage(FailureMessages.actualIsNull());59 }60 @Test61 public void should_fail_if_actual_does_not_contain_given_values_exactly() {62 AssertionInfo info = TestData.someInfo();63 char[] expected = new char[]{ 'a', 'b', 'e' };64 try {65 arrays.assertContainsExactlyInAnyOrder(info, actual, expected);66 } catch (AssertionError e) {67 Mockito.verify(failures).failure(info, ShouldContainExactlyInAnyOrder.shouldContainExactlyInAnyOrder(actual, expected, Lists.newArrayList('e'), Lists.newArrayList('c'), StandardComparisonStrategy.instance()));68 return;69 }70 TestFailures.failBecauseExpectedAssertionErrorWasNotThrown();71 }72 @Test73 public void should_fail_if_actual_contains_all_given_values_but_size_differ() {74 AssertionInfo info = TestData.someInfo();75 char[] expected = new char[]{ 'a', 'b' };76 try {77 arrays.assertContainsExactlyInAnyOrder(info, actual, expected);78 } catch (AssertionError e) {79 Mockito.verify(failures).failure(info, ShouldContainExactlyInAnyOrder.shouldContainExactlyInAnyOrder(actual, expected, Lists.emptyList(), Lists.newArrayList('c'), StandardComparisonStrategy.instance()));80 return;81 }82 TestFailures.failBecauseExpectedAssertionErrorWasNotThrown();83 }84 @Test85 public void should_fail_if_actual_contains_duplicates_and_expected_does_not() {86 AssertionInfo info = TestData.someInfo();87 actual = CharArrays.arrayOf('a', 'b', 'b');88 char[] expected = new char[]{ 'a', 'b' };89 try {90 arrays.assertContainsExactlyInAnyOrder(info, actual, expected);91 } catch (AssertionError e) {92 Mockito.verify(failures).failure(info, ShouldContainExactlyInAnyOrder.shouldContainExactlyInAnyOrder(actual, expected, Lists.emptyList(), Lists.newArrayList('b'), StandardComparisonStrategy.instance()));93 return;94 }95 TestFailures.failBecauseExpectedAssertionErrorWasNotThrown();96 }97 @Test98 public void should_fail_if_expected_contains_duplicates_and_actual_does_not() {99 AssertionInfo info = TestData.someInfo();100 actual = CharArrays.arrayOf('a', 'b');101 char[] expected = new char[]{ 'a', 'b', 'b' };102 try {103 arrays.assertContainsExactlyInAnyOrder(info, actual, expected);104 } catch (AssertionError e) {105 Mockito.verify(failures).failure(info, ShouldContainExactlyInAnyOrder.shouldContainExactlyInAnyOrder(actual, expected, Lists.newArrayList('b'), Lists.emptyList(), StandardComparisonStrategy.instance()));106 return;107 }108 TestFailures.failBecauseExpectedAssertionErrorWasNotThrown();109 }110 // ------------------------------------------------------------------------------------------------------------------111 // tests using a custom comparison strategy112 // ------------------------------------------------------------------------------------------------------------------113 @Test114 public void should_pass_if_actual_contains_given_values_exactly_in_any_order_according_to_custom_comparison_strategy() {115 arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(TestData.someInfo(), actual, CharArrays.arrayOf('a', 'B', 'c'));116 }117 @Test118 public void should_pass_if_actual_contains_given_values_exactly_in_different_order_according_to_custom_comparison_strategy() {119 char[] expected = new char[]{ 'A', 'c', 'b' };120 arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(TestData.someInfo(), actual, expected);121 }122 @Test123 public void should_fail_if_expected_empty_and_actual_is_not_whatever_custom_comparison_strategy_is() {124 Assertions.assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), actual, emptyArray()));125 }126 @Test127 public void should_throw_error_if_expected_null_whatever_custom_comparison_strategy_is() {128 Assertions.assertThatNullPointerException().isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), actual, null)).withMessage(ErrorMessages.valuesToLookForIsNull());129 }130 @Test131 public void should_fail_if_actual_is_null_whatever_custom_comparison_strategy_is() {132 Assertions.assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(someInfo(), null, arrayOf('b'))).withMessage(FailureMessages.actualIsNull());133 }134 @Test135 public void should_fail_if_actual_does_not_contain_given_values_exactly_according_to_custom_comparison_strategy() {136 AssertionInfo info = TestData.someInfo();137 char[] expected = new char[]{ 'a', 'B', 'e' };138 try {139 arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected);140 } catch (AssertionError e) {141 Mockito.verify(failures).failure(info, ShouldContainExactlyInAnyOrder.shouldContainExactlyInAnyOrder(actual, expected, Lists.newArrayList('e'), Lists.newArrayList('c'), caseInsensitiveComparisonStrategy));142 return;143 }144 TestFailures.failBecauseExpectedAssertionErrorWasNotThrown();145 }146 @Test147 public void should_fail_if_actual_contains_all_given_values_but_size_differ_according_to_custom_comparison_strategy() {148 AssertionInfo info = TestData.someInfo();149 char[] expected = new char[]{ 'a', 'b' };150 try {151 arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected);152 } catch (AssertionError e) {153 Mockito.verify(failures).failure(info, ShouldContainExactlyInAnyOrder.shouldContainExactlyInAnyOrder(actual, expected, Lists.emptyList(), Lists.newArrayList('c'), caseInsensitiveComparisonStrategy));154 return;155 }156 TestFailures.failBecauseExpectedAssertionErrorWasNotThrown();157 }158 @Test159 public void should_fail_if_actual_contains_duplicates_and_expected_does_not_according_to_custom_comparison_strategy() {160 AssertionInfo info = TestData.someInfo();161 actual = CharArrays.arrayOf('a', 'b', 'b');162 char[] expected = new char[]{ 'a', 'b' };163 try {164 arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected);165 } catch (AssertionError e) {166 Mockito.verify(failures).failure(info, ShouldContainExactlyInAnyOrder.shouldContainExactlyInAnyOrder(actual, expected, Lists.emptyList(), Lists.newArrayList('b'), caseInsensitiveComparisonStrategy));167 return;168 }169 TestFailures.failBecauseExpectedAssertionErrorWasNotThrown();170 }171 @Test172 public void should_fail_if_expected_contains_duplicates_and_actual_does_not_according_to_custom_comparison_strategy() {173 AssertionInfo info = TestData.someInfo();174 actual = CharArrays.arrayOf('a', 'b');175 char[] expected = new char[]{ 'a', 'b', 'b' };176 try {177 arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected);178 } catch (AssertionError e) {179 Mockito.verify(failures).failure(info, ShouldContainExactlyInAnyOrder.shouldContainExactlyInAnyOrder(actual, expected, Lists.newArrayList('b'), Lists.emptyList(), caseInsensitiveComparisonStrategy));180 return;181 }182 TestFailures.failBecauseExpectedAssertionErrorWasNotThrown();183 }184}...
Source:ObjectArrays_assertContainsExactlyInAnyOrder_Test.java
...12 */13package org.assertj.core.internal.objectarrays;14import org.assertj.core.api.AssertionInfo;15import org.assertj.core.api.Assertions;16import org.assertj.core.error.ShouldContainExactlyInAnyOrder;17import org.assertj.core.internal.ErrorMessages;18import org.assertj.core.internal.ObjectArraysBaseTest;19import org.assertj.core.internal.StandardComparisonStrategy;20import org.assertj.core.test.TestData;21import org.assertj.core.test.TestFailures;22import org.assertj.core.util.Arrays;23import org.assertj.core.util.FailureMessages;24import org.assertj.core.util.Lists;25import org.junit.jupiter.api.Test;26import org.mockito.Mockito;27/**28 * Tests for <code>{@link Iterables#assertContainsExactlyInAnyOrder(AssertionInfo, Iterable, Object[])}</code>.29 *30 * @author Lovro Pandzic31 */32public class ObjectArrays_assertContainsExactlyInAnyOrder_Test extends ObjectArraysBaseTest {33 @Test34 public void should_pass_if_actual_contains_exactly_in_any_order_given_values() {35 arrays.assertContainsExactlyInAnyOrder(TestData.someInfo(), actual, Arrays.array("Leia", "Yoda", "Luke"));36 }37 @Test38 public void should_pass_if_actual_contains_given_values_exactly_in_any_order_with_null_elements() {39 actual = Arrays.array("Luke", "Yoda", "Leia", null);40 arrays.assertContainsExactlyInAnyOrder(TestData.someInfo(), actual, Arrays.array("Leia", null, "Yoda", "Luke"));41 }42 @Test43 public void should_pass_if_actual_and_given_values_are_empty() {44 arrays.assertContainsExactlyInAnyOrder(TestData.someInfo(), Arrays.array(), Arrays.array());45 }46 @Test47 public void should_fail_if_array_of_values_to_look_for_is_empty_and_actual_is_not() {48 Assertions.assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, array()));49 }50 @Test51 public void should_fail_if_arrays_have_different_sizes() {52 Assertions.assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, array("Luke", "Yoda")));53 }54 @Test55 public void should_throw_error_if_array_of_values_to_look_for_is_null() {56 Assertions.assertThatNullPointerException().isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), actual, null)).withMessage(ErrorMessages.valuesToLookForIsNull());57 }58 @Test59 public void should_fail_if_actual_is_null() {60 Assertions.assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> arrays.assertContainsExactlyInAnyOrder(someInfo(), null, array("Yoda"))).withMessage(FailureMessages.actualIsNull());61 }62 @Test63 public void should_fail_if_actual_does_not_contain_given_values_exactly_in_any_order() {64 AssertionInfo info = TestData.someInfo();65 Object[] expected = new Object[]{ "Luke", "Yoda", "Han" };66 try {67 arrays.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_fail_if_actual_contains_duplicates_and_expected_does_not() {76 AssertionInfo info = TestData.someInfo();77 actual = Arrays.array("Luke", "Leia", "Luke");78 Object[] expected = new Object[]{ "Luke", "Leia" };79 try {80 arrays.assertContainsExactlyInAnyOrder(info, actual, expected);81 } catch (AssertionError e) {82 Mockito.verify(failures).failure(info, ShouldContainExactlyInAnyOrder.shouldContainExactlyInAnyOrder(actual, expected, Lists.emptyList(), Lists.newArrayList("Luke"), StandardComparisonStrategy.instance()));83 return;84 }85 TestFailures.failBecauseExpectedAssertionErrorWasNotThrown();86 }87 @Test88 public void should_fail_if_expected_contains_duplicates_and_actual_does_not() {89 AssertionInfo info = TestData.someInfo();90 actual = Arrays.array("Luke", "Leia");91 Object[] expected = new Object[]{ "Luke", "Leia", "Luke" };92 try {93 arrays.assertContainsExactlyInAnyOrder(info, actual, expected);94 } catch (AssertionError e) {95 Mockito.verify(failures).failure(info, ShouldContainExactlyInAnyOrder.shouldContainExactlyInAnyOrder(actual, expected, Lists.newArrayList("Luke"), Lists.emptyList(), StandardComparisonStrategy.instance()));96 return;97 }98 TestFailures.failBecauseExpectedAssertionErrorWasNotThrown();99 }100 // ------------------------------------------------------------------------------------------------------------------101 // tests using a custom comparison strategy102 // ------------------------------------------------------------------------------------------------------------------103 @Test104 public void should_pass_if_actual_contains_given_values_exactly_in_any_order_according_to_custom_comparison_strategy() {105 arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(TestData.someInfo(), actual, Arrays.array("LUKE", "YODA", "Leia"));106 }107 @Test108 public void should_fail_if_actual_does_not_contain_given_values_exactly_in_any_order_according_to_custom_comparison_strategy() {109 AssertionInfo info = TestData.someInfo();110 Object[] expected = new Object[]{ "Luke", "Yoda", "Han" };111 try {112 arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected);113 } catch (AssertionError e) {114 Mockito.verify(failures).failure(info, ShouldContainExactlyInAnyOrder.shouldContainExactlyInAnyOrder(actual, expected, Lists.newArrayList("Han"), Lists.newArrayList("Leia"), caseInsensitiveStringComparisonStrategy));115 return;116 }117 TestFailures.failBecauseExpectedAssertionErrorWasNotThrown();118 }119 @Test120 public void should_fail_if_actual_contains_duplicates_and_expected_does_not_according_to_custom_comparison_strategy() {121 AssertionInfo info = TestData.someInfo();122 actual = Arrays.array("Luke", "Leia", "Luke");123 Object[] expected = new Object[]{ "Luke", "Leia" };124 try {125 arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected);126 } catch (AssertionError e) {127 Mockito.verify(failures).failure(info, ShouldContainExactlyInAnyOrder.shouldContainExactlyInAnyOrder(actual, expected, Lists.emptyList(), Lists.newArrayList("Luke"), caseInsensitiveStringComparisonStrategy));128 return;129 }130 TestFailures.failBecauseExpectedAssertionErrorWasNotThrown();131 }132 @Test133 public void should_fail_if_expected_contains_duplicates_and_actual_does_not_according_to_custom_comparison_strategy() {134 AssertionInfo info = TestData.someInfo();135 actual = Arrays.array("Luke", "Leia");136 Object[] expected = new Object[]{ "Luke", "Leia", "Luke" };137 try {138 arraysWithCustomComparisonStrategy.assertContainsExactlyInAnyOrder(info, actual, expected);139 } catch (AssertionError e) {140 Mockito.verify(failures).failure(info, ShouldContainExactlyInAnyOrder.shouldContainExactlyInAnyOrder(actual, expected, Lists.newArrayList("Luke"), Lists.emptyList(), caseInsensitiveStringComparisonStrategy));141 return;142 }143 TestFailures.failBecauseExpectedAssertionErrorWasNotThrown();144 }145}...
ShouldContainExactlyInAnyOrder
Using AI Code Generation
1package org.assertj.core.error;2import static org.assertj.core.api.Assertions.assertThat;3import static org.assertj.core.error.ShouldContainExactlyInAnyOrder.shouldContainExactlyInAnyOrder;4import static org.assertj.core.util.Lists.newArrayList;5import java.util.List;6import org.junit.Test;7public class ShouldContainExactlyInAnyOrder_Test {8 public void should_create_error_message() {9 ErrorMessageFactory factory = shouldContainExactlyInAnyOrder(newArrayList("Yoda", "Luke"), newArrayList("Luke"), newArrayList("Yoda"));10 assertThat(factory.create()).isEqualTo("[Test] %n" +11 "to contain exactly (and in same order):%n" +12 " <[\"Yoda\"]>");13 }14}15to contain exactly (and in same order):
ShouldContainExactlyInAnyOrder
Using AI Code Generation
1import org.assertj.core.error.ShouldContainExactlyInAnyOrder;2import org.assertj.core.internal.TestDescription;3import org.assertj.core.presentation.StandardRepresentation;4public class ShouldContainExactlyInAnyOrderExample {5 public static void main(String[] args) {6 ShouldContainExactlyInAnyOrder shouldContainExactlyInAnyOrder = new ShouldContainExactlyInAnyOrder(new TestDescription("TEST"), new StandardRepresentation(), new Object[] { "apple", "banana", "mango" }, new Object[] { "apple", "mango", "grapes" }, new Object[] { "grapes" }, new Object[] { "banana" });7 System.out.println(shouldContainExactlyInAnyOrder);8 }9}
ShouldContainExactlyInAnyOrder
Using AI Code Generation
1package org.assertj.core.error;2import org.assertj.core.internal.TestDescription;3import org.assertj.core.presentation.StandardRepresentation;4import org.assertj.core.util.Lists;5import org.junit.Test;6import static org.assertj.core.api.Assertions.assertThat;7import static org.assertj.core.error.ShouldContainExactlyInAnyOrder.shouldContainExactlyInAnyOrder;8import static org.assertj.core.util.Lists.newArrayList;9public class ShouldContainExactlyInAnyOrderTest {10 public void should_create_error_message() {11 String message = shouldContainExactlyInAnyOrder(newArrayList("Yoda", "Luke"), newArrayList("Yoda", "Luke", "Han"), newArrayList("Han"), newArrayList()).create(new TestDescription("Test"), new StandardRepresentation());12 assertThat(message).isEqualTo(String.format("[Test] %n" +13 "to contain exactly (and in same order):%n" +14 " <[]>%n"));15 }16}17package org.assertj.core.error;18import static org.assertj.core.util.Lists.newArrayList;19import static org.assertj.core.error.ShouldContainExactlyInAnyOrder.shouldContainExactlyInAnyOrder;20import static org.assertj.core.util.Lists.newArrayList;21import static org.assertj.core.api.Assertions.*;22import org.junit.Test;23public class ShouldContainExactlyInAnyOrder_create_Test {24 public void should_create_error_message() {25 String message = shouldContainExactlyInAnyOrder(newArrayList("Yoda", "Luke"), newArrayList("Yoda", "Luke", "Han"), newArrayList("Han"), newArrayList()).create();26 assertThat(message).isEqualTo(String.format("%n" +27 "to contain exactly (and in same order):%n" +
ShouldContainExactlyInAnyOrder
Using AI Code Generation
1package org.assertj.core.error;2import java.util.List;3import org.assertj.core.util.VisibleForTesting;4import org.assertj.core.util.introspection.IntrospectionError;5import org.assertj.core.util.introspection.IntrospectionError.IntrospectionErrorBuilder;6import org.assertj.core.util.introspection.IntrospectionUtils;7import org.assertj.core.util.introspection.PropertyOrFieldSupport;8import org.assertj.core.util.introspection.PropertyOrFieldSupport.ComparisonStrategy;9import static org.assertj.core.error.ElementsShouldBe.elementsShouldBe;10import static org.assertj.core.error.ShouldContainExactly.shouldContainExactly;11import static org.assertj.core.error.ShouldContainExactlyInAnyOrder.shouldContainExactlyInAnyOrder;12import static org.assertj.core.util.IterableUtil.sizeOf;13import static org.assertj.core.util.Lists.newArrayList;14import static org.assertj.core.util.Objects.areEqual;15import static org.assertj.core.util.Objects.areEqualIncludingNullFields;16import static org.assertj.core.util.Objects.areEqualIncludingPrivateFields;17import static org.assertj.core.util.Objects.areEqualIncludingPrivateFieldsOf;18import static org.assertj.core.util.Objects.areEqualIncludingPrivateFieldsOfExcept;19import static org.assertj.core.util.Objects.areEqualIncludingPrivateFieldsOfExceptInherited;20import static org.assertj.core.util.Objects.areEqualIncludingPrivateFieldsOfInherited;21import static org.assertj.core.util.Objects.areEqualIncludingPrivateFieldsOfInheritedExcept;22import static org.assertj.core.util.Objects.areEqualIncludingPrivateFieldsOfInheritedExceptInherited;23import static org.assertj.core.util.Objects.areEqualIncludingPrivateFieldsOfInheritedIn;24import static org.assertj.core.util.Objects.areEqualIncludingPrivateFieldsOfInheritedInExcept;25import static org.assertj.core.util.Objects.areEqualIncludingPrivateFieldsOfInheritedInExceptInherited;26import static org.assertj.core.util.Objects.areEqualIncludingPrivateFieldsOfInheritedInInherited;27import static org.assertj.core.util.Objects.areEqualIncludingPrivateFieldsOfInheritedInInheritedExcept;28import static org.assertj.core.util.Objects.areEqualIncludingPrivateFieldsOfInheritedInInheritedExceptInherited;29import static org.assertj.core.util.Objects.areEqualIncludingPrivateFieldsOfInheritedInInheritedIn;30import static org.assertj.core.util.Objects.areEqualIncludingPrivateFieldsOfInheritedInInheritedInExcept;31import static org.assertj.core.util.Objects.areEqualIncludingPrivateFieldsOfInheritedInInheritedInExceptInherited;32import static org.assertj.core.util.Objects.areEqualIncludingPrivateFieldsOfInheritedInInheritedInInherited;33import static
ShouldContainExactlyInAnyOrder
Using AI Code Generation
1package org.assertj.core.error;2import java.util.List;3import java.util.Set;4import org.assertj.core.internal.ComparisonStrategy;5import org.assertj.core.internal.StandardComparisonStrategy;6import org.assertj.core.util.VisibleForTesting;7import org.assertj.core.util.introspection.IntrospectionError;8import org.assertj.core.util.introspection.Introspector;9import org.assertj.core.util.introspection.PropertyOrFieldSupport;10import org.assertj.core.util.introspection.PropertyOrFieldSupport.Comparison;11public class ShouldContainExactlyInAnyOrder extends BasicErrorMessageFactory {12 private static final String SHOULD_CONTAIN_EXACTLY_IN_ANY_ORDER = "%nExpecting:%n <%s>%nto contain exactly (and in same order) the following elements:%n <%s>%nbut could not find the following elements:%n <%s>%n%s";13 private static final String SHOULD_CONTAIN_EXACTLY_IN_ANY_ORDER_WITH_COMPARISON_STRATEGY = "%nExpecting:%n <%s>%nto contain exactly (and in same order) the following elements:%n <%s>%nbut could not find the following elements:%n <%s>%n%s%nwhen comparing values using '%s'";14 private static final String SHOULD_CONTAIN_EXACTLY_IN_ANY_ORDER_WITH_COMPARISON_STRATEGY_AND_EXTRACTED_FIELDS = "%nExpecting:%n <%s>%nto contain exactly (and in same order) the following elements:%n <%s>%nbut could not find the following elements:%n <%s>%n%s%nwhen comparing values using '%s' and comparing extracted fields/properties %s";15 Failures failures = Failures.instance();16 public ShouldContainExactlyInAnyOrder(Object actual, Object expected, Set<?> notFound, Set<?> notExpected, ComparisonStrategy comparisonStrategy) {17 super(SHOULD_CONTAIN_EXACTLY_IN_ANY_ORDER, actual, expected, notFound, comparisonStrategy);18 }19 public ShouldContainExactlyInAnyOrder(Object actual, Object expected, Set<?> notFound, Set<?> notExpected, ComparisonStrategy comparisonStrategy, List<String> extractedFields) {20 super(SHOULD_CONTAIN_EXACTLY_IN_ANY_ORDER_WITH_COMPARISON_STRATEGY_AND_EXTRACTED_FIELDS, actual, expected, notFound, comparisonStrategy, extractedFields);21 }22 public ShouldContainExactlyInAnyOrder(Object actual, Object expected, Set<?> notFound, Set<?> notExpected) {23 super(S
ShouldContainExactlyInAnyOrder
Using AI Code Generation
1import org.assertj.core.error.ShouldContainExactlyInAnyOrder;2import org.assertj.core.error.ErrorMessageFactory;3import java.util.List;4import java.util.ArrayList;5import java.util.Arrays;6public class ShouldContainExactlyInAnyOrderExample {7 public static void main(String[] args) {8 ErrorMessageFactory factory = ShouldContainExactlyInAnyOrder.shouldContainExactlyInAnyOrder(Arrays.asList("a", "b", "c"), Arrays.asList("a", "c"), Arrays.asList("b"), null);9 String message = factory.create("Test", "Test");10 System.out.println(message);11 }12}13to contain exactly (and in same order):
ShouldContainExactlyInAnyOrder
Using AI Code Generation
1import org.assertj.core.error.ShouldContainExactlyInAnyOrder;2import org.assertj.core.error.ErrorMessageFactory;3public class ShouldContainExactlyInAnyOrder {4 public static void main(String[] args) {5 ErrorMessageFactory errorMessageFactory = ShouldContainExactlyInAnyOrder.shouldContainExactlyInAnyOrder("abc", new ArrayList<>(), new ArrayList<>(), new ArrayList<>());6 System.out.println(errorMessageFactory.create("Test", "test"));7 }8}9import java.util.ArrayList;10import org.assertj.core.error.ShouldContainExactlyInAnyOrder;11public class ShouldContainExactlyInAnyOrderExample2 {12 public static void main(String[] args) {13 ShouldContainExactlyInAnyOrder shouldContainExactlyInAnyOrder = new ShouldContainExactlyInAnyOrder();14 System.out.println(shouldContainExactlyInAnyOrder);15 }16}17import java.util.ArrayList;18import org.assertj.core.error.ShouldContainExactlyInAnyOrder;19public class ShouldContainExactlyInAnyOrderExample3 {20 public static void main(String[] args) {21 ShouldContainExactlyInAnyOrder shouldContainExactlyInAnyOrder = new ShouldContainExactlyInAnyOrder();22 System.out.println(shouldContainExactlyInAnyOrder.toString());23 }24}25import java.util.ArrayList;26import org.assertj.core.error.ShouldContainExactlyInAnyOrder;27public class ShouldContainExactlyInAnyOrderExample4 {28 public static void main(String[] args) {
ShouldContainExactlyInAnyOrder
Using AI Code Generation
1import org.assertj.core.api.Assertions;2import org.assertj.core.error.ShouldContainExactlyInAnyOrder;3import org.assertj.core.internal.Failures;4import java.util.Arrays;5import static org.assertj.core.api.Assertions.assertThat;6public class ShouldContainExactlyInAnyOrderExample {7 public static void main(String[] args) {8 Failures failures = Assertions.getFailures();9 ShouldContainExactlyInAnyOrder shouldContainExactlyInAnyOrder = new ShouldContainExactlyInAnyOrder(Arrays.asList("A", "B", "C"), Arrays.asList("A", "B", "C", "D"), Arrays.asList("D"));10 String message = failures.failureInfo.descriptionText("Test").create();11 String errorMessage = shouldContainExactlyInAnyOrder.create(message);12 System.out.println(errorMessage);13 }14}15to contain exactly (and in same order):16import org.assertj.core.api.Assertions;17import org.assertj.core.error.ShouldContainExactlyInAnyOrder;18import org.assertj.core.internal.Failures;19import java.util.Arrays;20import static org.assertj.core.api.Assertions.assertThat;21public class ShouldContainExactlyInAnyOrderExample {22 public static void main(String[] args) {23 Failures failures = Assertions.getFailures();24 ShouldContainExactlyInAnyOrder shouldContainExactlyInAnyOrder = new ShouldContainExactlyInAnyOrder(Arrays.asList("A", "B", "C"), Arrays.asList("A", "B", "C", "D"), Arrays.asList("D"));25 String message = failures.failureInfo.descriptionText("Test").actualValue("Actual").create();26 String errorMessage = shouldContainExactlyInAnyOrder.create(message);27 System.out.println(errorMessage);28 }29}
ShouldContainExactlyInAnyOrder
Using AI Code Generation
1import org.assertj.core.error.ShouldContainExactlyInAnyOrder;2import java.util.ArrayList;3import java.util.List;4public class AssertionTest {5public static void main(String[] args) {6List<String> actual = new ArrayList<>();7List<String> expected = new ArrayList<>();8actual.add("one");9actual.add("two");10expected.add("two");11expected.add("one");12ShouldContainExactlyInAnyOrder shouldContainExactlyInAnyOrder = new ShouldContainExactlyInAnyOrder(actual, expected);13System.out.println(shouldContainExactlyInAnyOrder.create("Test", "Test"));14}15}
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!!