Closed danielmatthews84 closed 1 year ago
I'm experiencing the same but with a Parameterized Argument of type kotlin.jvm.functions.Function1
(any lambda). Similar to this issue, Micronaut Test is being too greedy about parameter types.
Attach an example please
Hi Graeme, of course. In Kotlin:
fun tokenTypeExpectations() = listOf<Arguments>(
Arguments.of(TokenType.GCM, { token: String -> AddRegistrationOrDeviceTokenData().gcmRegToken(token) }),
Arguments.of(TokenType.APNS, { token: String -> AddRegistrationOrDeviceTokenData().apnsDeviceToken(token) }),
Arguments.of(TokenType.HUAWEI, { token: String -> AddRegistrationOrDeviceTokenData().huaweiDeviceToken(token) }),
)
@ParameterizedTest
@MethodSource("tokenTypeExpectations")
fun `works`(
tokenType: TokenType, (token: String) -> AddRegistrationOrDeviceTokenData
) { ...
Error:
Discovered multiple competing ParameterResolvers for parameter [kotlin.jvm.functions.Function1<? super java.lang.String, ? extends ....AddRegistrationOrDeviceTokenData> reqBody] in method [public final void ....PushRegistrationEventHandlerIT.works(....PushRegistrationEventData$TokenType,kotlin.jvm.functions.Function1<? super java.lang.String, ? extends ....AddRegistrationOrDeviceTokenData>)]: io.micronaut.test.extensions.junit5.MicronautJunit5Extension@635d036b, org.junit.jupiter.params.ParameterizedTestParameterResolver@35965cb6
Dependencies:
added a PR to disable bean resolution for methods which is the only viable solution to this issue https://github.com/micronaut-projects/micronaut-test/pull/727
Expected Behavior
Unit tests using JUnit5
@ParameterizedTest
are no longer working since upgrading to Micronaut 3.7.The following test should run without error:
This was working correctly with Micronaut 3.6
Actual Behaviour
Exception when running test:
The combination of using both Lombok's
@Data
and the custom@Constraint
annotation appears to create a bean definition reference synthetic class$Foo$Definition$Reference
which in turn makes theFoo
class eligible as a Micronaut managed bean and therefore is being picked up by theMicronautJunit5Extension
Removing either annotation prevents the synthetic class from being generated and fixes the test.
Steps To Reproduce
Environment Information
Example Application
No response
Version
3.7