Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression in 1.12.3: multiple calls verified using withArg make test fail #814

Closed
3 tasks done
jnizet opened this issue Apr 27, 2022 · 2 comments
Closed
3 tasks done

Comments

@jnizet
Copy link

jnizet commented Apr 27, 2022

  • I am running the latest version
  • I checked the documentation and found no answer
  • I checked to make sure that this issue has not already been filed

Expected Behavior

The following test passes

import io.mockk.every
import io.mockk.just
import io.mockk.mockk
import io.mockk.runs
import io.mockk.verify
import org.junit.Assert.assertEquals
import org.junit.Test

data class Bar(val id: String, val name: String)

class Foo {
    fun doSomething(bar: Bar) = Unit
}

class FooTest {
    @Test
    fun `should verify with WithArg`() {
        val mockFoo = mockk<Foo>();

        every {
            mockFoo.doSomething(any())
        } just runs

        mockFoo.doSomething(Bar("id1", "name 1"))
        mockFoo.doSomething(Bar("id2", "name 2"))

        verify {
            mockFoo.doSomething(withArg {
                assertEquals("id1", it.id)
                assertEquals("name 1", it.name)
            })

            mockFoo.doSomething(withArg {
                assertEquals("id2", it.id)
                assertEquals("name 2", it.name)
            })
        }
    }
}

Current Behavior

The test fails .
Note that this test used to pass with version 1.12.1 and 1.12.2.

Failure Information (for bugs)

org.junit.ComparisonFailure: 
Expected :id1
Actual   :id2


	at org.junit.Assert.assertEquals(Assert.java:117)
	at org.junit.Assert.assertEquals(Assert.java:146)
	at com.fairphone.factory.FooTest$should verify with WithArg$2$1.invoke(FooTest.kt:31)
	at com.fairphone.factory.FooTest$should verify with WithArg$2$1.invoke(FooTest.kt:30)
	at com.fairphone.factory.FooTest$should verify with WithArg$2$invoke$$inlined$withArg$1.invoke(API.kt:2012)
	at com.fairphone.factory.FooTest$should verify with WithArg$2$invoke$$inlined$withArg$1.invoke(API.kt:2011)
	at io.mockk.FunctionMatcher.match(Matchers.kt:62)
	at io.mockk.InvocationMatcher.match(API.kt:3760)
	at io.mockk.impl.verify.UnorderedCallVerifier.matchCall(UnorderedCallVerifier.kt:126)
	at io.mockk.impl.verify.UnorderedCallVerifier.verify(UnorderedCallVerifier.kt:38)
	at io.mockk.impl.recording.states.VerifyingState$recordingDone$outcome$1.invoke(VerifyingState.kt:31)
	at io.mockk.impl.recording.states.VerifyingState$recordingDone$outcome$1.invoke(VerifyingState.kt:30)
	at io.mockk.impl.recording.CommonCallRecorder.safeExec(CommonCallRecorder.kt:72)
	at io.mockk.impl.recording.states.VerifyingState.recordingDone(VerifyingState.kt:30)
	at io.mockk.impl.recording.CommonCallRecorder.done(CommonCallRecorder.kt:47)
	at io.mockk.impl.eval.RecordedBlockEvaluator.record(RecordedBlockEvaluator.kt:64)
	at io.mockk.impl.eval.VerifyBlockEvaluator.verify(VerifyBlockEvaluator.kt:30)
	at io.mockk.MockKDsl.internalVerify(API.kt:119)
	at io.mockk.MockKKt.verify(MockK.kt:149)
	at io.mockk.MockKKt.verify$default(MockK.kt:140)

Context

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

  • MockK version: 1.12.3
  • OS: macOS
  • Kotlin version: 1.6.10
  • JDK version: 11
  • JUnit version: 5.8.2
  • Type of test: unit test
@lnhrdt
Copy link

lnhrdt commented May 1, 2022

I am experiencing the same issue.

  • MockK version: 1.12.3
  • OS: macOS
  • Kotlin version: 1.6.21
  • JDK version: 17
  • JUnit version: 5.8.2

@Raibaz
Copy link
Collaborator

Raibaz commented May 3, 2022

Fixed by #792

@Raibaz Raibaz closed this as completed May 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants