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

Eric Milles commented on GROOVY-11057:
--------------------------------------

Do you need the map to be mutable?  You should be able to replace "[:]" with 
"Collections.emptyMap()".

> STC Generic type matching failure
> ---------------------------------
>
>                 Key: GROOVY-11057
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11057
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler
>    Affects Versions: 4.0.12
>            Reporter: Jan Hackel
>            Assignee: Eric Milles
>            Priority: Major
>
> With Groovy version 4.0.12 this code will no longer compile:
>  
> {code:java}
> import groovy.transform.CompileStatic
> import org.junit.jupiter.api.Test
> import org.mockito.Mockito
> @CompileStatic
> interface Configuration {
>   Map<String, Object> getSettings()
> }
> @CompileStatic
> class GenericMapStubbing {
>   @Test
>   void stubSettings() {
>     def configuration = Mockito.mock(Configuration).tap {
>       Mockito.when(it.getSettings()).thenReturn([:])
>     }
>     assert configuration.settings.isEmpty()
>   }
> } {code}
> Failure message:
>  
> 18: [Static type checking] - Cannot find matching method 
> org.mockito.stubbing.OngoingStubbing#thenReturn(java.util.LinkedHashMap<#K, 
> #V>). Please check if the declared type is correct and if the method exists.
>  @ line 16, column 7.
>          Mockito.when(it.getSettings()).thenReturn([:])



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

Reply via email to