https://kotlinlang.org logo
#mockk
Title
# mockk
k

Kris Wong

04/22/2020, 6:37 PM
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
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)
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
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.
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
3 Views