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

Upgrade to 3.1.1 leads to 'Failed matching mocking signature for' #79

Closed
vojkny opened this issue Mar 2, 2022 · 2 comments
Closed

Upgrade to 3.1.1 leads to 'Failed matching mocking signature for' #79

vojkny opened this issue Mar 2, 2022 · 2 comments

Comments

@vojkny
Copy link

vojkny commented Mar 2, 2022

In the beggining I thought this is causes by upgrade of mockk, however in the end I found out this is causes by upgrade of springmockk.

For following code we are getting Failed matching mocking signature for errors on:

every { spyEm.after(any()) } answers { firstArg<() -> Any>().invoke() }
                    ^^^^^

Where after method is defined as:

    open fun after(body: () -> Any) {
        TransactionSynchronizationManager.registerSynchronization(
            object : TransactionSynchronizationAdapter() {
                override fun afterCommit() {
                    body()
                }
            }
        )
    }

Current Behavior

Method cannot be mocked:

io.mockk.MockKException: Failed matching mocking signature for

left matchers: [any()]

	at io.mockk.impl.recording.SignatureMatcherDetector.detect(SignatureMatcherDetector.kt:99)
	at io.mockk.impl.recording.states.RecordingState.signMatchers(RecordingState.kt:39)
	at io.mockk.impl.recording.states.RecordingState.round(RecordingState.kt:31)
	at io.mockk.impl.recording.CommonCallRecorder.round(CommonCallRecorder.kt:50)
	at io.mockk.impl.eval.RecordedBlockEvaluator.record(RecordedBlockEvaluator.kt:63)
	at io.mockk.impl.eval.EveryBlockEvaluator.every(EveryBlockEvaluator.kt:30)
	at io.mockk.MockKDsl.internalEvery(API.kt:93)
	at io.mockk.MockKKt.every(MockK.kt:98)

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
  • Springmockk verison 3.1.1 (3.1.0) works correctly
  • OS: Linux + Mac
  • Kotlin version: 1.6.10
  • JDK version: 17
  • Type of test: unit test
@jnizet
Copy link
Member

jnizet commented Mar 2, 2022

Hi @knyttl. Could you please see if you have a similar problem if you test with Spring Boot's native Mockito support?

And please also join a link to a repo containing a minimal reproduction of the issue, so that I can investigate.
Also note that there is an issue with spies on JDK17 (#65), so maybe it's a similar problem.

@vojkny
Copy link
Author

vojkny commented Mar 3, 2022

Hi, thanks for a quick response.

Hi @knyttl. Could you please see if you have a similar problem if you test with Spring Boot's native Mockito support?

Sorry, I use pure Spring and without Mockito and I have no experiences with it, so not sure here.

please also join a link to a repo containing a minimal reproduction of the issue

Minimum reproducible example would be looking like this:

package net.goout.entitystorage.controllers

import com.ninjasquad.springmockk.SpykBean
import io.mockk.every
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.test.context.ContextConfiguration
import org.springframework.test.context.junit.jupiter.SpringExtension

@Configuration
open class SpykedConfig {
    @Bean
    open fun mockedClass() = MockedClass()
}

open class MockedClass {
    open fun after(body: () -> Any) {
        body.invoke()
    }
}

@ExtendWith(SpringExtension::class)
@ContextConfiguration(classes = [SpykedConfig::class])
open class SpykedClassTest {

    @SpykBean
    open lateinit var mockedClass: MockedClass

    @Test
    fun testSpringMockk() {
        every { mockedClass.after(any()) } answers { firstArg<() -> Any>().invoke() }
    }
}

The problem is that – unfortunately it works correctly. I cannot see the difference compared to our code, so I guess I can close this :/

@vojkny vojkny closed this as completed Mar 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

2 participants