Skip to content

Commit

Permalink
Fix: use custom element comparator when provided for SeqAssertions (#188
Browse files Browse the repository at this point in the history
)
  • Loading branch information
freekk authored Jan 9, 2023
1 parent cd52116 commit f4d7f27
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/main/java/org/assertj/vavr/api/AbstractSeqAssert.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.assertj.core.data.Index;
import org.assertj.core.internal.ComparatorBasedComparisonStrategy;
import org.assertj.core.internal.ComparisonStrategy;
import org.assertj.core.internal.Iterables;
import org.assertj.core.internal.StandardComparisonStrategy;
import org.assertj.core.util.CheckReturnValue;

Expand Down Expand Up @@ -67,6 +68,7 @@ abstract class AbstractSeqAssert<SELF extends AbstractSeqAssert<SELF, ACTUAL, EL
*/
@CheckReturnValue
public SELF usingElementComparator(Comparator<? super ELEMENT> customComparator) {
this.iterables = new Iterables(new ComparatorBasedComparisonStrategy(customComparator));
seqElementComparisonStrategy = new ComparatorBasedComparisonStrategy(customComparator);
return myself;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ void should_pass_if_List_contains_exactly_elements_in_any_order() {
.containsExactlyInAnyOrder(expectedInAnyOrder);
}

@Test
void should_pass_if_List_contains_exactly_elements_in_any_order_using_element_comparator() {
final Set<String> expectedInAnyOrder = HashSet.of("other", "and", "else", "something");
final List<String> uppercaseList = expectedInAnyOrder.map(String::toUpperCase).toList().reverse();
assertThat(uppercaseList)
.usingElementComparator(String::compareToIgnoreCase)
.containsExactlyInAnyOrder(expectedInAnyOrder);
}

@Test
void should_fail_when_List_is_null() {
final Set<String> expectedInAnyOrder = HashSet.of("other", "and", "else", "something");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void should_rule_for_soft_assertion_work() {
// THEN
List<Throwable> failures = multipleFailuresError.getFailures();
assertThat(failures).hasSize(2);
assertThat(failures.get(0)).hasMessageStartingWith(format("[contains] %nExpecting:%n <Left(something)>%nto contain:%n <\"else\">%nbut did not."));
assertThat(failures.get(0)).hasMessageStartingWith(format("[contains] %nExpecting:%n <Left(something)>%nto contain:%n <\"else\"> on the [LEFT]%nbut did not."));
assertThat(failures.get(1)).hasMessageStartingWith(format("[instance] %nExpecting:%n" +
" <Left>%n" +
"to contain a value that is an instance of:%n" +
Expand All @@ -53,4 +53,4 @@ public void should_rule_for_soft_assertion_work() {
" <java.lang.String>"));
}

}
}

0 comments on commit f4d7f27

Please sign in to comment.