https://kotlinlang.org logo
#android
Title
# android
t

thuytrinh

12/03/2018, 10:52 AM
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

rkeazor

12/03/2018, 1:29 PM
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

stojan

12/03/2018, 5:44 PM
Why not create an object, it only has one property? Mocking value object is not recommended by Mockito
👍 3
t

thuytrinh

12/06/2018, 8:25 PM
@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

stojan

12/08/2018, 8:15 PM
I guess I didn't understand the problem. I apologize for the misunderstanding
13 Views