Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/main/java/org/assertj/vavr/internal/Multimaps.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,8 @@ public <K, V> void assertContainsExactly(AssertionInfo info, Multimap<K, V> actu
if (notExpected.isEmpty() && notFound.isEmpty()) {
// check entries order
int index = 0;
for (K keyFromActual : actual.keySet()) {
if (areNotEqual(keyFromActual, entries[index]._1)) {
Tuple2<K, Traversable<V>> actualEntry = Tuple.of(keyFromActual, actual.get(keyFromActual).get());
for (Tuple2<K, V> actualEntry : actual) {
if (!deepEquals(actualEntry._1, entries[index]._1) || !deepEquals(actualEntry._2, entries[index]._2)) {
throw failures.failure(info, elementsDifferAtIndex(actualEntry, entries[index], index));
}
index++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.vavr.Tuple;
import io.vavr.Tuple2;
import io.vavr.collection.HashMultimap;
import io.vavr.collection.LinkedHashMultimap;
import io.vavr.collection.Multimap;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -136,9 +137,38 @@ void should_fail_if_Multimap_does_not_contain_all_entries_in_same_order() {
.isInstanceOf(AssertionError.class)
.hasMessage(
"\nActual and expected have the same elements but not in the same order, at index 0 actual element was:\n" +
" (key1, List(value1))\n" +
" (key1, value1)\n" +
"whereas expected element was:\n" +
" (key3, value3)\n"
);
}

@Test
void should_pass_if_Multimap_with_duplicate_keys_contains_entries_in_order() {
Multimap<String, String> actual = LinkedHashMultimap.withSeq().of(
"key1", "value1", "key1", "value2", "key2", "value3"
);

assertThat(actual).containsExactly(
Tuple.of("key1", "value1"),
Tuple.of("key1", "value2"),
Tuple.of("key2", "value3")
);
}

@Test
void should_fail_if_Multimap_with_duplicate_keys_has_entries_in_wrong_order() {
Multimap<String, String> actual = LinkedHashMultimap.withSeq().of(
"key1", "value1", "key1", "value2", "key2", "value3"
);

assertThatThrownBy(
() -> assertThat(actual).containsExactly(
Tuple.of("key1", "value2"),
Tuple.of("key1", "value1"),
Tuple.of("key2", "value3")
)
)
.isInstanceOf(AssertionError.class);
}
}
Loading