I use mockito-scala to mock a Java method which return type is
Comparable[_] and which uses
null as a valid return value.
The signature of the method I want to mock:
Comparable getProperty(@NotNull final String propertyName);
The code snippet where I attempt the mocking:
val entity = mock[Entity] val comparableNull: Comparable[_] = null entity.getProperty(EntityMapper.TermEntry.propertyNameDefinition) returns comparableNull
Error I get (in IntelliJ):
Error:(24, 71) type mismatch; found : Comparable[(some other)T(in value <local EntityMapperTest>)] where type (some other)T(in value <local EntityMapperTest>) required: Comparable[T(in value <local EntityMapperTest>)] where type T(in value <local EntityMapperTest>) error after rewriting to EntityMapperTest.this.StubbingOps[Comparable[T]](entity.getProperty(EntityMapper.TermEntry.propertyNameDefinition)).returns.apply possible cause: maybe a wrong Dynamic method signature? entity.getProperty(EntityMapper.TermEntry.propertyNameDefinition) returns value.asInstanceOf[Comparable[_]]
I don’t understand what IntelliJ (or the Scala compiler, for that matter) want to tell me by this.
Side node: Compiler errors in Scala are very often difficult to understand, especially for beginners.