I am having a strange issue with an object mock. given:
Copy code
mockkObject(AppLockedState)
every { AppLockedState.isLocked() } answers { locked }
it seems to be executing the
isLocked
method rather than using the answer. it's complaining that Boolean can't be cast to one of the types being used in the method implementation
Kris Wong
04/22/2020, 7:24 PM
Copy code
java.lang.ClassCastException: java.lang.Boolean cannot be cast to <redacted>.SDKContext$State
at <redacted>_1_Proxy.getCurrentState(Unknown Source:19)
at <redacted>.AppLockedState.isLocked(AppLockedState.kt:34)
Kris Wong
04/22/2020, 7:27 PM
it's because of the way
every
works by recording calls. it's also recording the call from a separate mocked object that is invoked by
isLocked
. it's then using the same answer for both calls
Kris Wong
04/22/2020, 8:30 PM
hmm, i am not able to find any workaround for this issue
o
oleksiyp
04/22/2020, 9:46 PM
It should not execute, should intercept, maybe you have some kind of extension method.
oleksiyp
04/22/2020, 9:47 PM
Whatever it is, try to mininize your example and submit via github issur
k
Kris Wong
04/22/2020, 10:03 PM
I tried filtering out the subsequent call with a matcher, but then it threw an error about not being able to find a match for it