Title
o

oleksiyp

10/10/2018, 10:26 AM
Yes, clear is suggested if you want to return back default behavior, otherwise next mockkStatic will clear it
🙂 1
d

darych

10/10/2018, 10:28 AM
But if I add
clearMocks(SecurityContext.getAgentInfo())
to cleanup after each test I receive error
io.mockk.MockKException: can't find stub [aid=AGENT_ID] [org=ORG_ID] [sid=null]

	at io.mockk.impl.stub.StubRepository.stubFor(StubRepository.kt:15)
	at io.mockk.impl.stub.CommonClearer.clear(CommonClearer.kt:16)
	at io.mockk.MockKKt.clearMocks(MockK.kt:654)
	at io.mockk.MockKKt.clearMocks$default(MockK.kt:227)
o

oleksiyp

10/10/2018, 10:29 AM
clearStaticMockk(SecurityContext::class)
But thats out of my heas
head
You can untranform class at all after test by unmockkAll
d

darych

10/10/2018, 10:30 AM
So the default behavior will be library's default?
o

oleksiyp

10/10/2018, 10:30 AM
But this may be more time consuming then clear
By default static mocks act like spies
So clear will just make all calls pass to original implementation
d

darych

10/10/2018, 10:32 AM
Thanks, will try
Should I after
clearStaticMockk
run
mockkStatic()
again?
For some reason I still get old value from mock...
o

oleksiyp

10/10/2018, 10:36 AM
Not really, but no harm, penalty
Ah maybe it is
clearMockkStatic
There is deorecated set of methoda there. I do not remeber it out of my head
Anyway if it is failing please report github issue
And meanwhile use unmockkStatic or unmockkAll
d

darych

10/10/2018, 10:39 AM
Ok, thank you. will create small repro case.
@oleksiyp I debugged code little bit. Could static function return null?
o

oleksiyp

10/10/2018, 12:17 PM
Should be possible AFAIK
d

darych

10/10/2018, 1:59 PM
While debugging when I'm in StubbingAwaitingAnswerState.kt in answer function
for ((idx, recordedCall) in calls.withIndex()) {
throws ConcurrentModificationException. Do you know who concurrently may change it? I'm still trying to make small repro for this, but when I'm not debugging this repro everything works fine. It looks like there is some multithread issue, but I can't understand why because I think that everything is running in one thread
When I go inside StubbingAwaitingAnswerState.kt I see the following exception inside calls property:
RecordedCall(retValue=<error "io.mockk.MockKException: Bad recording sequence. Please finalize every { ... } block with returns/answers/just Runs">, retType=Info, isRetValueMock=true matcher=class staticmockk.SecurityContext.getInfo()))
It happens when I go inside returns block in debug mode.
o

oleksiyp

10/10/2018, 2:15 PM
Debug may be tricky
As debugger calls toString
d

darych

10/10/2018, 2:17 PM
Yes... Unfortunately. Sometimes I have empty calls list, sometimes it has one elemnt and when I go inside the loop it the
lastCall
is false and debugger shows size = 0
In my main project I saw that mockk puts null as answer and while debugging static method returns not-null value for the call from previous test run even if I have
mockkStatic
function in each test.
@oleksiyp I'm sorry, it looks like I was wrong and mockk works perfectly! I fonud some issues in my tests
o

oleksiyp

10/10/2018, 2:52 PM
no issues, fill free to report anything. I anyway checking in detail it a lot later