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

QuarkusComponentTest is not working in kotlin #35997

Closed
elgabbouch opened this issue Sep 18, 2023 · 11 comments
Closed

QuarkusComponentTest is not working in kotlin #35997

elgabbouch opened this issue Sep 18, 2023 · 11 comments
Labels
area/arc Issue related to ARC (dependency injection) area/kotlin area/testing kind/bug Something isn't working triage/duplicate This issue or pull request already exists

Comments

@elgabbouch
Copy link

elgabbouch commented Sep 18, 2023

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

@elgabbouch elgabbouch added the kind/bug Something isn't working label Sep 18, 2023
@quarkus-bot
Copy link

quarkus-bot bot commented Sep 18, 2023

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

@geoand geoand added area/testing area/arc Issue related to ARC (dependency injection) labels Sep 19, 2023
@geoand
Copy link
Contributor

geoand commented Sep 19, 2023

cc @mkouba

@geoand
Copy link
Contributor

geoand commented Sep 19, 2023

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

@geoand
Copy link
Contributor

geoand commented Sep 19, 2023

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

@mkouba
Copy link
Contributor

mkouba commented Sep 19, 2023

@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
Copy link
Contributor

Ladicek commented Sep 19, 2023

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
Copy link
Contributor

geoand commented Sep 19, 2023

Ah okay, thanks for the update

@elgabbouch
Copy link
Author

@geoand I tested it with version 3.3.2 and 3.3.3

@miladjafary
Copy link

miladjafary commented May 15, 2024

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

@mkouba
Copy link
Contributor

mkouba commented May 15, 2024

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

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

@mkouba
Copy link
Contributor

mkouba commented Sep 17, 2024

This issue duplicates #43339.

@mkouba mkouba closed this as completed Sep 17, 2024
@geoand geoand added the triage/duplicate This issue or pull request already exists label Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/arc Issue related to ARC (dependency injection) area/kotlin area/testing kind/bug Something isn't working triage/duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

5 participants