Remove extracting(Function) from Iterable assertions#3854
Remove extracting(Function) from Iterable assertions#3854PatrickWalter214 wants to merge 3 commits intoassertj:mainfrom
extracting(Function) from Iterable assertions#3854Conversation
In Kotlin the call to extracting with a lambda for an iterable assert is ambiguous. This is due to the extracting method existing for ThrowingExtractor and Function, which have the same effective signature, as checked exceptions do not exist in Kotlin. We opt to continue using the extracting method for ThrowingExtractor, since it is the more flexible functional interface, as it supports that the lambda provided can throw an exception.
53df5dd to
fe69a89
Compare
extracting(Function) from Iterable assertions
b2b071f to
2dab02c
Compare
…ing-ambiguous-signature-kotlin
scordio
left a comment
There was a problem hiding this comment.
Many thanks @PatrickWalter214 for your efforts, and sorry for such a big delay!
There are a couple of things I'd like to do differently, but I'm taking care of them directly.
assertj-core/src/main/java/org/assertj/core/extractor/ThrowingExtractors.java
Outdated
Show resolved
Hide resolved
...-core-kotlin/src/test/kotlin/org/assertj/tests/core/kotlin/api/Assertions_assertThat_Test.kt
Outdated
Show resolved
Hide resolved
| * @return a new assertion object whose object under test is the list of values extracted | ||
| */ | ||
| @CheckReturnValue | ||
| public <V> AbstractListAssert<?, List<? extends V>, V, ObjectAssert<V>> extracting(Function<? super ELEMENT, V> extractor) { |
There was a problem hiding this comment.
As discussed today with @filiphr, removing the overload accepting Function will break compatibility with all the existing Function implementations that cannot be easily transformed into a ThrowingExtractor, such as those coming from third parties.
A better strategy is likely to keep extracting(Function) and add to ThrowingExtractor factory methods that ease wrapping code that throws exceptions, similar to how the Spring Framework does.
I'll analyze the topic again and come up with a better proposal.
In Kotlin, the call to extracting with a lambda for an iterable assert is ambiguous. This is due to the
extractingmethod existing forThrowingExtractorandFunction, which have the same effective signature, as checked exceptions do not exist in Kotlin. We opt to continue using the extracting method forThrowingExtractor, since it is the more flexible functional interface, as it supports that the lambda provided can throw an exception.Check List:
extracting()when using Kotlin #1499