You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It looks like Mockito is using null as a default value for properties in a interface even though they are non-nullable.
Reproduce:
interfaceDog {
val name:String
}
classDogCaller {
funcallDog(dog:Dog) = callSomeone(dog.name)
privatefuncallSomeone(name:String) ="Hey $name come here!"
}
classDogCallerTests {
privateval dogCaller =DogCaller()
@Test
fun`dog caller should call dog by its name`() {
val beagle:Dog= mock()
// This makes the test pass // whenever(beagle.name).thenReturn("Firulais")
dogCaller.callDog(beagle)
verify(beagle).name // This fails cause it detects dog.name : String = null !
}
}
The text was updated successfully, but these errors were encountered:
Sorry, now I see I got this error cause inside callDog() I passed dog.name to another function which expected a non-nullable type. That's where the nullability of String check failed.
Though from thecastNull() in the file you referenced I see this is a totally intentional behaviour. Should it be the case though? String has always been a "special" type. I expected the mock to return a '"nice" value such as "".
It would make sense to handle it that way. Would actually solve the issue seen in #241 without using the proposed workaround I believe. Strings have always been kind of problematic in regards to Mockito-kotlin.
It looks like Mockito is using
null
as a default value for properties in a interface even though they are non-nullable.Reproduce:
The text was updated successfully, but these errors were encountered: