diff --git a/src/main/java/org/assertj/vavr/internal/Maps.java b/src/main/java/org/assertj/vavr/internal/Maps.java index f795043d..de390ba2 100644 --- a/src/main/java/org/assertj/vavr/internal/Maps.java +++ b/src/main/java/org/assertj/vavr/internal/Maps.java @@ -26,6 +26,8 @@ import java.util.function.Predicate; import static io.vavr.Predicates.not; +import static java.util.Objects.deepEquals; +import static java.util.Objects.requireNonNull; import static org.assertj.core.error.ElementsShouldBe.elementsShouldBe; import static org.assertj.core.error.ShouldContain.shouldContain; import static org.assertj.core.error.ShouldContainExactly.elementsDifferAtIndex; @@ -41,9 +43,7 @@ import static org.assertj.core.internal.Arrays.assertIsArray; import static org.assertj.core.internal.CommonValidations.failIfEmptySinceActualIsNotEmpty; import static org.assertj.core.internal.CommonValidations.hasSameSizeAsCheck; -import static org.assertj.core.util.Objects.areEqual; import static org.assertj.core.util.Preconditions.checkArgument; -import static org.assertj.core.util.Preconditions.checkNotNull; import static org.assertj.vavr.api.ShouldNotContainValues.shouldNotContainValues; public final class Maps { @@ -89,7 +89,7 @@ public void assertContainsAnyOf(AssertionInfo info, Map actual, Tuple2[] entries) { doCommonContainsCheck(info, actual, entries); if (actual.isEmpty() && entries.length == 0) return; - failIfEmptySinceActualIsNotEmpty(entries); + failIfEmptySinceActualIsNotEmpty(info, failures, actual, entries); for (Tuple2 entry : entries) { if (containsEntry(actual, entry)) return; } @@ -114,7 +114,7 @@ public void assertContains(AssertionInfo info, Map actual, Tuple2[] entries) { doCommonContainsCheck(info, actual, entries); if (actual.isEmpty() && entries.length == 0) return; - failIfEmptySinceActualIsNotEmpty(entries); + failIfEmptySinceActualIsNotEmpty(info, failures, actual, entries); final Set> notFound = Array.of(entries).filter(entryNotPresentIn(actual)).toSet(); if (isNotEmpty(notFound)) { throw failures.failure(info, shouldContain(actual, entries, notFound)); @@ -139,7 +139,7 @@ public void assertDoesNotContain(AssertionInfo info, Map actual, Tuple2[] entries) { failIfNullOrEmpty(entries); assertNotNull(info, actual); - failIfEmptySinceActualIsNotEmpty(entries); + failIfEmptySinceActualIsNotEmpty(info, failures, actual, entries); final Set> found = Array.of(entries).filter(actual::contains).toSet(); if (isNotEmpty(found)) { throw failures.failure(info, shouldNotContain(actual, entries, found)); @@ -308,7 +308,7 @@ public void assertContainsOnlyKeys(AssertionInfo info, Map actual, public void assertContainsValues(AssertionInfo info, Map actual, @SuppressWarnings("unchecked") V... values) { assertNotNull(info, actual); - checkNotNull(values, "The array of values to look for should not be null"); + requireNonNull(values, "The array of values to look for should not be null"); if (actual.isEmpty() && values.length == 0) return; Set expected = HashSet.of(values); @@ -331,7 +331,7 @@ public void assertContainsValues(AssertionInfo info, Map actual, public void assertDoesNotContainValues(AssertionInfo info, Map actual, @SuppressWarnings("unchecked") V... values) { assertNotNull(info, actual); - checkNotNull(values, "The array of values to look for should not be null"); + requireNonNull(values, "The array of values to look for should not be null"); if (actual.isEmpty() && values.length == 0) return; Set expected = HashSet.of(values); @@ -407,8 +407,8 @@ private boolean doCommonEmptinessChecks(Map actual, K[] keys) { } private boolean containsEntry(Map actual, Tuple2 entry) { - checkNotNull(entry, "Entries to look for should not be null"); - return actual.containsKey(entry._1) && areEqual(actual.get(entry._1).get(), entry._2); + requireNonNull(entry, "Entries to look for should not be null"); + return actual.containsKey(entry._1) && deepEquals(actual.get(entry._1).get(), entry._2); } private static void failIfEmpty(Tuple2[] entries) { @@ -429,19 +429,19 @@ private static void failIfNullOrEmpty(Tuple2[] } private static void failIfNull(Tuple2[] entries) { - checkNotNull(entries, "The array of entries to look for should not be null"); + requireNonNull(entries, "The array of entries to look for should not be null"); } private static void failIfNull(Iterable> entries) { - checkNotNull(entries, "The entries to look for should not be null"); + requireNonNull(entries, "The entries to look for should not be null"); } private static void failIfNull(K[] keys) { - checkNotNull(keys, "The array of keys to look for should not be null"); + requireNonNull(keys, "The array of keys to look for should not be null"); } private static boolean areNotEqual(K actualKey, K expectedKey) { - return !areEqual(actualKey, expectedKey); + return !deepEquals(actualKey, expectedKey); } private static void assertNotNull(AssertionInfo info, Map actual) { diff --git a/src/main/java/org/assertj/vavr/internal/Multimaps.java b/src/main/java/org/assertj/vavr/internal/Multimaps.java index ef8e972a..f033f2d5 100644 --- a/src/main/java/org/assertj/vavr/internal/Multimaps.java +++ b/src/main/java/org/assertj/vavr/internal/Multimaps.java @@ -25,6 +25,8 @@ import java.util.function.Predicate; import static io.vavr.Predicates.not; +import static java.util.Objects.deepEquals; +import static java.util.Objects.requireNonNull; import static org.assertj.core.error.ElementsShouldBe.elementsShouldBe; import static org.assertj.core.error.ShouldContain.shouldContain; import static org.assertj.core.error.ShouldContainAnyOf.shouldContainAnyOf; @@ -41,9 +43,7 @@ import static org.assertj.core.internal.Arrays.assertIsArray; import static org.assertj.core.internal.CommonValidations.failIfEmptySinceActualIsNotEmpty; import static org.assertj.core.internal.CommonValidations.hasSameSizeAsCheck; -import static org.assertj.core.util.Objects.areEqual; import static org.assertj.core.util.Preconditions.checkArgument; -import static org.assertj.core.util.Preconditions.checkNotNull; import static org.assertj.vavr.api.ShouldNotContainValues.shouldNotContainValues; public final class Multimaps { @@ -91,7 +91,7 @@ public void assertContainsAnyOf(AssertionInfo info, Multimap actual Tuple2[] entries) { doCommonContainsCheck(info, actual, entries); if (actual.isEmpty() && entries.length == 0) return; - failIfEmptySinceActualIsNotEmpty(entries); + failIfEmptySinceActualIsNotEmpty(info, failures, actual, entries); for (Tuple2 entry : entries) { if (containsEntry(actual, entry)) return; } @@ -116,7 +116,7 @@ public void assertContains(AssertionInfo info, Multimap actual, Tuple2[] entries) { doCommonContainsCheck(info, actual, entries); if (actual.isEmpty() && entries.length == 0) return; - failIfEmptySinceActualIsNotEmpty(entries); + failIfEmptySinceActualIsNotEmpty(info, failures, actual, entries); final Set> notFound = Array.of(entries).filter(entryNotPresentIn(actual)).toSet(); if (isNotEmpty(notFound)) { throw failures.failure(info, shouldContain(actual, entries, notFound)); @@ -214,7 +214,7 @@ public void assertDoesNotContain(AssertionInfo info, Multimap actua Tuple2[] entries) { failIfNullOrEmpty(entries); assertNotNull(info, actual); - failIfEmptySinceActualIsNotEmpty(entries); + failIfEmptySinceActualIsNotEmpty(info, failures, actual, entries); final Set> found = Array.of(entries).filter(actual::contains).toSet(); if (isNotEmpty(found)) { throw failures.failure(info, shouldNotContain(actual, entries, found)); @@ -327,7 +327,7 @@ public void assertContainsValue(AssertionInfo info, Multimap actual public void assertContainsValues(AssertionInfo info, Multimap actual, @SuppressWarnings("unchecked") V... values) { assertNotNull(info, actual); - checkNotNull(values, "The array of values to look for should not be null"); + requireNonNull(values, "The array of values to look for should not be null"); if (actual.isEmpty() && values.length == 0) return; Set expected = HashSet.of(values); @@ -366,7 +366,7 @@ public void assertDoesNotContainValue(AssertionInfo info, Multimap public void assertDoesNotContainValues(AssertionInfo info, Multimap actual, @SuppressWarnings("unchecked") V... values) { assertNotNull(info, actual); - checkNotNull(values, "The array of values to look for should not be null"); + requireNonNull(values, "The array of values to look for should not be null"); if (actual.isEmpty() && values.length == 0) return; Set expected = HashSet.of(values); @@ -423,12 +423,12 @@ private static Multimap asLinkedMultimap(Tuple2 boolean containsEntry(Multimap actual, Tuple2 entry) { - checkNotNull(entry, "Entry to look for should not be null"); + requireNonNull(entry, "Entry to look for should not be null"); return actual.containsKey(entry._1) && actual.get(entry._1).get().contains(entry._2); } private static boolean areNotEqual(K actualKey, K expectedKey) { - return !areEqual(actualKey, expectedKey); + return !deepEquals(actualKey, expectedKey); } private static void failIfNullOrEmpty(Tuple2[] entries) { @@ -437,15 +437,15 @@ private static void failIfNullOrEmpty(Tuple2[] } private static void failIfNull(Iterable> entries) { - checkNotNull(entries, "The entries should not be null"); + requireNonNull(entries, "The entries should not be null"); } private static void failIfNull(K[] keys) { - checkNotNull(keys, "The array of keys to look for should not be null"); + requireNonNull(keys, "The array of keys to look for should not be null"); } private static void failIfNull(Tuple2[] entries) { - checkNotNull(entries, "The array of entries should not be null"); + requireNonNull(entries, "The array of entries should not be null"); } private static void failIfEmpty(Iterable> entries) { diff --git a/src/test/java/org/assertj/vavr/api/MapAssert_containsAllEntriesOf_Test.java b/src/test/java/org/assertj/vavr/api/MapAssert_containsAllEntriesOf_Test.java index 5d1a8d57..e212343f 100644 --- a/src/test/java/org/assertj/vavr/api/MapAssert_containsAllEntriesOf_Test.java +++ b/src/test/java/org/assertj/vavr/api/MapAssert_containsAllEntriesOf_Test.java @@ -50,7 +50,10 @@ void should_fail_if_Map_is_not_empty_and_entries_is_an_empty_array() { () -> assertThat(actual).containsAllEntriesOf(List.empty()) ) .isInstanceOf(AssertionError.class) - .hasMessage("actual is not empty while group of values to look for is."); + .hasMessage("\n" + + "Actual:\n" + + " HashMap((key1, value1), (key3, value3))\n" + + "is not empty while group of values to look for is."); } @Test diff --git a/src/test/java/org/assertj/vavr/api/MapAssert_contains_anyOf_entries_Test.java b/src/test/java/org/assertj/vavr/api/MapAssert_contains_anyOf_entries_Test.java index 85d80ed2..674beed4 100644 --- a/src/test/java/org/assertj/vavr/api/MapAssert_contains_anyOf_entries_Test.java +++ b/src/test/java/org/assertj/vavr/api/MapAssert_contains_anyOf_entries_Test.java @@ -53,7 +53,10 @@ void should_fail_if_Map_is_not_empty_and_entries_is_an_empty_array() { () -> assertThat(actual).containsAnyOf(entries) ) .isInstanceOf(AssertionError.class) - .hasMessage("actual is not empty while group of values to look for is."); + .hasMessage("\n" + + "Actual:\n" + + " HashMap((key1, value1), (key3, value3))\n" + + "is not empty while group of values to look for is."); } @Test diff --git a/src/test/java/org/assertj/vavr/api/MapAssert_contains_entries_Test.java b/src/test/java/org/assertj/vavr/api/MapAssert_contains_entries_Test.java index 371eff77..808d79ff 100644 --- a/src/test/java/org/assertj/vavr/api/MapAssert_contains_entries_Test.java +++ b/src/test/java/org/assertj/vavr/api/MapAssert_contains_entries_Test.java @@ -52,7 +52,10 @@ void should_fail_if_Map_is_not_empty_and_entries_is_an_empty_array() { () -> assertThat(actual).contains(entries) ) .isInstanceOf(AssertionError.class) - .hasMessage("actual is not empty while group of values to look for is."); + .hasMessage("\n" + + "Actual:\n" + + " HashMap((key1, value1), (key3, value3))\n" + + "is not empty while group of values to look for is."); } @Test diff --git a/src/test/java/org/assertj/vavr/api/MultimapAssert_containsAllEntriesOf_Test.java b/src/test/java/org/assertj/vavr/api/MultimapAssert_containsAllEntriesOf_Test.java index 1fd0e6f5..1e791237 100644 --- a/src/test/java/org/assertj/vavr/api/MultimapAssert_containsAllEntriesOf_Test.java +++ b/src/test/java/org/assertj/vavr/api/MultimapAssert_containsAllEntriesOf_Test.java @@ -48,7 +48,10 @@ void should_fail_if_Multimap_is_not_empty_and_entries_is_an_empty_array() { () -> assertThat(actual).containsAllEntriesOf(List.empty()) ) .isInstanceOf(AssertionError.class) - .hasMessage("actual is not empty while group of values to look for is."); + .hasMessage("\n" + + "Actual:\n" + + " HashMultimap[List]((key1, value1), (key3, value3))\n" + + "is not empty while group of values to look for is."); } @Test diff --git a/src/test/java/org/assertj/vavr/api/MultimapAssert_contains_anyOf_entries_Test.java b/src/test/java/org/assertj/vavr/api/MultimapAssert_contains_anyOf_entries_Test.java index 71fac11e..1b93cf02 100644 --- a/src/test/java/org/assertj/vavr/api/MultimapAssert_contains_anyOf_entries_Test.java +++ b/src/test/java/org/assertj/vavr/api/MultimapAssert_contains_anyOf_entries_Test.java @@ -53,7 +53,10 @@ void should_fail_if_Multimap_is_not_empty_and_entries_is_an_empty_array() { () -> assertThat(actual).containsAnyOf(entries) ) .isInstanceOf(AssertionError.class) - .hasMessage("actual is not empty while group of values to look for is."); + .hasMessage("\n" + + "Actual:\n" + + " HashMultimap[List]((key1, value1), (key3, value3))\n" + + "is not empty while group of values to look for is."); } @Test diff --git a/src/test/java/org/assertj/vavr/api/MultimapAssert_contains_entries_Test.java b/src/test/java/org/assertj/vavr/api/MultimapAssert_contains_entries_Test.java index ea0cbdc7..08fec14f 100644 --- a/src/test/java/org/assertj/vavr/api/MultimapAssert_contains_entries_Test.java +++ b/src/test/java/org/assertj/vavr/api/MultimapAssert_contains_entries_Test.java @@ -52,7 +52,10 @@ void should_fail_if_Multimap_is_not_empty_and_entries_is_an_empty_array() { () -> assertThat(actual).contains(entries) ) .isInstanceOf(AssertionError.class) - .hasMessage("actual is not empty while group of values to look for is."); + .hasMessage("\n" + + "Actual:\n" + + " HashMultimap[List]((key1, value1), (key3, value3))\n" + + "is not empty while group of values to look for is."); } @Test