quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.35k stars 2.56k forks source link

QuarkusComponentTest is not working in kotlin #35997

Open elgabbouch opened 9 months ago

elgabbouch commented 9 months ago

Describe the bug

I re-wrote the same example in the documentation: https://quarkus.io/blog/quarkus-component-test/ using kotlin

Expected behavior

should work as in java

Actual behavior

jakarta.enterprise.inject.spi.DeploymentException: Normal scoped beans must declare a non-private constructor with no parameters: CLASS bean [types=[com.test.Foo, java.lang.Object], qualifiers=[@Default, @Any], target=com.test.Foo]

at io.quarkus.arc.processor.Beans.validateBean(Beans.java:767)
at io.quarkus.arc.processor.BeanInfo.validate(BeanInfo.java:605)
at io.quarkus.arc.processor.BeanDeployment.validateBeans(BeanDeployment.java:1559)
at io.quarkus.arc.processor.BeanDeployment.validate(BeanDeployment.java:482)
at io.quarkus.arc.processor.BeanProcessor.validate(BeanProcessor.java:167)

How to Reproduce?

import jakarta.enterprise.context.ApplicationScoped

@ApplicationScoped
class Charlie

import jakarta.enterprise.context.ApplicationScoped

@ApplicationScoped
class Foo(private val charlie: Charlie)

@QuarkusComponentTest
internal class FooTest {

    @Inject
    lateinit var foo: Foo

    @InjectMock
    lateinit var charlieMock: Charlie

    @Test
    fun testPing() {
        println("ping")
    }
}

Output of uname -a or ver

No response

Output of java -version

No response

GraalVM version (if different from Java)

No response

Quarkus version or git rev

3.3.3 and 3.3.2

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

quarkus-bot[bot] commented 9 months ago

/cc @evanchooly (kotlin), @geoand (kotlin)

geoand commented 9 months ago

cc @mkouba

geoand commented 9 months ago

With @Ladicek's improvement that brings the ability to do transformations, the no-args constructor transformation is probably one we want incluided

geoand commented 9 months ago

@elgabbouch we'll need to know the Quarkus version you are using

mkouba commented 9 months ago

@geoand is right that QuarkusComponentTest does not support bytecode transformations yet and thus simplified constructor injection does not work. Simplified constructor injection is a Quarkus-specific feature to relax a requirement from the CDI spec where every normal scoped bean must declare a no-args constructor.

However, the same applies to Java - there's no difference. If you modify Foo so that a field injection point is used then it should just work.

Ladicek commented 9 months ago

The PR to allow bytecode transformations in @QuarkusComponentTest (#35473) wasn't merged and likely won't in its current form because it's super intrusive. I think we're in a waiting mode, to see if @holly-cummins can escape the classloader hell in @QuarkusTest and if we can use some of her tricks.

geoand commented 9 months ago

Ah okay, thanks for the update

elgabbouch commented 9 months ago

@geoand I tested it with version 3.3.2 and 3.3.3

miladjafary commented 1 month ago

I'm using the version 3.10.0 and it is still not working

mkouba commented 1 month ago

I'm using the version 3.10.0 and it is still not working

Yes, that's why this issue is still open :shrug:. We don't have an estimate when this will be fixed and AFAIK nobody is working on it right now.