question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

equals calls performed by the library internally are recorded

See original GitHub issue

Expected Behavior

I expect internal calls done to <mockedObject>.equals(<otherObject>) not being recorded This happens when I have mocked calls with different arguments like

every { obj.call(mock1) } just runs
every { obj.call(mock2) } just runs

I expect confirmVerified not to consider calls being performed internally by the library

Stack trace

at io.mockk.impl.recording.CommonVerificationAcknowledger.acknowledgeVerified(CommonVerificationAcknowledger.kt:36)
	at io.mockk.MockKDsl.internalConfirmVerified(API.kt:272)
	at io.mockk.MockKKt.confirmVerified(MockK.kt:319)
	at data.booking.AcceptedBookingSourceImplTest.wtf(AcceptedBookingSourceImplTest.kt:348)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)

Code snippet

//
package test

import io.mockk.confirmVerified
import io.mockk.justRun
import io.mockk.mockk
import io.mockk.verify
import org.junit.Test

class InternalEqualsCallTest {
    class Arg

    class Caller() {
        fun call(arg: Arg) {}
    }

    class TestMe(val caller: Caller) {
        fun superCall(arg: Arg) {
            caller.call(arg)
        }
    }

    @Test
    fun test() {
        val caller = mockk<Caller>()
        val subject = TestMe(caller)
        val arg = mockk<Arg>()
        val arg1 = mockk<Arg>()
        justRun { caller.call(arg) }
        justRun { caller.call(arg1) }
        subject.superCall(arg)
        verify {
            caller.call(arg)
        }
        confirmVerified(
            caller,
            arg
        )
    }
}

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
jayudey-wfcommented, Mar 28, 2022

Seeing the same behavior, with mockkConstructor as well (don’t know if that matters)

0reactions
drx777commented, Feb 14, 2022
verify {
    arg wasNot called
}

I ran into that, here’s an example test:


    class MyTest {
        fun run() {}
    }

    @Test
    fun testTestFails() {
        val mock = mockk<MyTest>()
        verify { mock.run() wasNot Called }
    }

    @Test
    fun testTestWorks() {
        val mock = mockk<MyTest>()
        verify (exactly = 0) { mock.run() }
    }

Is that a misunderstanding of how wasNot Called works or a bug?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Records - C# reference - Microsoft Learn
For record types, including record struct and readonly record struct , two objects are equal if they are of the same type and...
Read more >
Why do I need to override the equals and hashCode methods ...
If only equals is overriden, then when you call myMap.put(first,someValue) first will hash to some bucket and when you call myMap.put(second,someOtherValue) ...
Read more >
Mock Functions or Spies Demystified - How Does jest.fn() Work?
Internally jest.fn will track all the calls and will perform the execution of the implementation function itself.
Read more >
Bug descriptions — spotbugs 4.7.3 documentation
Invoking System.exit shuts down the entire Java virtual machine. This should only been done when it is appropriate. Such calls make it hard...
Read more >
A Unit Testing Practitioner's Guide to Everyday Mockito - Toptal
These calls are recorded and the facts of these calls can be verified (see ... In those cases, Mockito just calls equals() internally...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found