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

Support function with generic types stubbing #173

Open
rgonciarz opened this issue Dec 10, 2022 · 1 comment
Open

Support function with generic types stubbing #173

rgonciarz opened this issue Dec 10, 2022 · 1 comment

Comments

@rgonciarz
Copy link

Reflection utils cannot find both bean instance and qualifier.
For bean instance a problem is related with suspended Functions using generic type.

import arrow.core.Either

typealias AssignKeyboard = suspend (Computer) -> Either<KeyboardError, Unit>
typealias AssignMouse = suspend (Computer) -> Either<MouseError, Unit>

To be more precise that's the exact type:

kotlin.jvm.functions.Function2<? super rg.zerokvm.domain.model.Computer, ? super kotlin.coroutines.Continuation<? super arrow.core.Either<? extends rg.zerokvm.domain.port.api.AssignMouse, ? extends kotlin.Unit>>, ?>

Most likely (?) literal type should be used, e.g. I'm able to find my bean instance with the code:

val typeLiteral = object : TypeLiteral<AssignMouse>() {}
val beanInstance = CDI.current().select(typeLiteral, @Named("AssignMouse"))

instead:

Arc.container().instance(fieldClass, *getQualifier(field))?.get()

Below you may see the rest of the code:

class ApiConfig {

    @ApplicationScoped
    @Named("AssignMouse")
    fun assignMouseBean(): AssignMouse = // ...

    @ApplicationScoped
    @Named("AssignKeyboard")
    fun assignKeyboardBean(): AssignKeyboard = // ...

}

// ...
@Path("/api")
class AssignMouseRestApiAdapter(
    @Named("AssignMouse")
    private val assignMouse: AssignMouse,
) {

    @Path("/assigment")
    @POST
    suspend fun foo() {
        // some code
    }

}


@QuarkusTest
internal class AssignMouseRestApiAdapterTest {

    @InjectMock
    @Named("AssignMouse")
    private lateinit var assignMouse: AssignMouse,

    fun `should foo`() {
        // ...
    }

}

Also Named Qualifier is not seen for declared annotations.

@glefloch
Copy link
Member

Thanks for reporting this. I think there is two separate issue. One regarding named qualifier, and the other regarding the type.
I will try to fix both of them in separate pull request

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