Has anyone tried inline classes with Mockito and e...
# android
t
Has anyone tried inline classes with Mockito and encountered this issue https://github.com/nhaarman/mockito-kotlin/issues/309? Any workaround so far?
😱 1
r
Inline Classes are still experimental and support may not be available just yet.
Also you should look into the Mockk mocking library. they are very up to date with the latest Kotlin trends
s
Why not create an object, it only has one property? Mocking value object is not recommended by Mockito
👍 3
t
@stojan Nobody actually tried to mock inline class objects here or in https://github.com/nhaarman/mockito-kotlin/issues/309. If you read carefully, imagine we have a simple interface:
Copy code
interface PokemonProvider {
  fun getPokemon(): Pokemon
}
With
Pokemon
is an inline class. Then if I mock
PokemonProvider
, I say
PokemonProvider
not
Pokemon
, then Mockito will complain incompatible types if I call
whenever(pokemonProvider.getPokemon()).thenReturn(Pokemon("Pikachu"))
.
👍 1
Also you should look into the Mockk mocking library. they are very up to date with the latest Kotlin trends
I believe mockk is also facing the same limitation.
Note the author didn’t try to mock inline class objects.
s
I guess I didn't understand the problem. I apologize for the misunderstanding