[ 
https://issues.apache.org/jira/browse/GROOVY-11258?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17800869#comment-17800869
 ] 

Eric Milles edited comment on GROOVY-11258 at 12/27/23 8:56 PM:
----------------------------------------------------------------

The choices for {{map}} are:
# [map(Function<? super 
E,V>)|https://www.javadoc.io/static/org.assertj/assertj-core/3.24.2/org/assertj/core/api/AbstractIterableAssert.html#map(java.util.function.Function)]
# [map(Function<? super 
E,V>...)|https://www.javadoc.io/static/org.assertj/assertj-core/3.24.2/org/assertj/core/api/AbstractIterableAssert.html#map(java.util.function.Function...)]
# [map(ThrowingExtractor<? super 
E,V>)|https://www.javadoc.io/static/org.assertj/assertj-core/3.24.2/org/assertj/core/api/AbstractIterableAssert.html#map(org.assertj.core.api.iterable.ThrowingExtractor)]

{{ThrowingExtractor}} extends {{Function}}, so there is no help from 
GROOVY-9881 param count disambiguation.
{code:java}
@FunctionalInterface
interface ThrowingExtractor<I, O, T extends Exception> extends Function<I, O> {
  default O apply(I input) { /**/ }
  O extractThrows(I input) throws T
}
{code}


was (Author: emilles):
The choices for {{map}} are:
# 
[map(Function)|https://www.javadoc.io/static/org.assertj/assertj-core/3.24.2/org/assertj/core/api/AbstractIterableAssert.html#map(java.util.function.Function)]
# 
[map(Function...)|https://www.javadoc.io/static/org.assertj/assertj-core/3.24.2/org/assertj/core/api/AbstractIterableAssert.html#map(java.util.function.Function...)]
# 
[map(ThrowingExtractor)|https://www.javadoc.io/static/org.assertj/assertj-core/3.24.2/org/assertj/core/api/AbstractIterableAssert.html#map(org.assertj.core.api.iterable.ThrowingExtractor)]

{{ThrowingExtractor}} extends {{Function}}, so there is no help from 
GROOVY-9881 param count disambiguation.
{code:java}
@FunctionalInterface
interface ThrowingExtractor<I, O, T extends Exception> extends Function<I, O> {
  default O apply(I input) { /**/ }
  O extractThrows(I input) throws T
}
{code}

> AssertJ collection mapping is badly supported
> ---------------------------------------------
>
>                 Key: GROOVY-11258
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11258
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>    Affects Versions: 4.0.17
>            Reporter: Jan Hackel
>            Priority: Major
>
> The following code will fail with the message 
> {noformat}
> [Static type checking] - No such property: x for class: java.lang.Object
>  @ line 8, column 13.
>          .map{ it.x }
>                ^
> {noformat}
> {code:groovy}
> @groovy.transform.CompileStatic
> class AssertJCollectionMappingTest {
>   @org.junit.jupiter.api.Test
>   void mapping() {
>     def texts = somePojos()
>     org.assertj.core.api.Assertions.assertThat(texts)
>       .map{ it.x }
>       .containsExactlyInAnyOrderElementsOf(['a', 'b'])
>   }
>   private static Collection<Pojo> somePojos() {
>     return [new Pojo(x: 'a'), new Pojo(x: 'b')]
>   }
>   static class Pojo {
>     String x
>   }
> }
> {code}
> Changing the line  to  
> {noformat}
> .map({ it.x } as Function<Pojo, String>) 
> {noformat}
> makes it compile but it is clumsy for more complicated types.
> It would be nice if Groovy was able to resolve the types without hints.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to