Search code examples
kotlingenericsintellij-ideamockito

IntellIJ IDEA Kotlin - Expecting an element


I am new to Kotlin and am now struggling with unit testing my code.

I am trying to mock the restTemplate that uses an array in the exchange method. I found that the correct way to do that would be

ArgumentMatchers.<ParameterizedTypeReference<Array<DataDto>>>any()

however compiler throws an error saying Expecting an element and doesn't allow me to qualify the type for any(). Is there any setting for IDEA to fix this compiler error?

I use Java 17 as the SDK, but I tried it Kotlin SDK 1.6.10 as well.

enter image description here


Solution

  • type arguments go after the function name (and before the ()), not before so you need to use

    ArgumentMatchers.any<ParameterizedTypeReference<Array<DataDto>>>()