Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-11057

STC Generic type matching failure

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 4.0.12
    • 4.0.13
    • Compiler
    • None

    Description

      With Groovy version 4.0.12 this code will no longer compile:

       

      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()
        }
      } 

      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([:])

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              jhunovis Jan Hackel
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: