You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2024/09/26 21:10:00 UTC
[jira] [Resolved] (GROOVY-11258) AssertJ collection mapping is badly supported
[ https://issues.apache.org/jira/browse/GROOVY-11258?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Milles resolved GROOVY-11258.
----------------------------------
Fix Version/s: 5.0.0-alpha-11
Resolution: Fixed
https://github.com/apache/groovy/commit/7576b86fd5a0ecdb5c64f521d6a1b3de00ca3935
> 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
> Assignee: Eric Milles
> Priority: Major
> Fix For: 5.0.0-alpha-11
>
> Attachments: screenshot-1.png
>
>
> 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)