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

@InjectMock does not behave like a mock created via "mockk()" #244

Open
Obirah opened this issue Nov 21, 2023 · 1 comment
Open

@InjectMock does not behave like a mock created via "mockk()" #244

Obirah opened this issue Nov 21, 2023 · 1 comment

Comments

@Obirah
Copy link

Obirah commented Nov 21, 2023

I am developing a Quarkus Kubernetes operator that is interacting with AWS through the AWS SDK for Java and I'm using mockk in my unit and integration tests.

One of the cases that I need to mock are calls to AWS SDK's paginators, for example:
organizationsClient.listAccountsPaginator() where organizationsClient is an OrganizationsAsyncClient.

In my unit tests I create the mock via the @MockK annotation and the mocking is fairly straightfoward:

every { organizationsClient.listAccountsPaginator() } answers { callOriginal() }
every { organizationsClient.listAccounts(any<ListAccountsRequest>()) } returns CompletableFuture.completedFuture(ListAccountsResponse.builder().accounts(account).build())

In my integration tests (which are @QuarkusTests), if I use @InjectMock and mock the paginator calls in the same way, I get exceptions of the following kind:

io.mockk.MockKException: no answer found for: AwsClientBean_ProducerMethod_organizationsClient_162d3fc8f8a3dacbf06a8e602ca1d5cf033cb60b_ClientProxy(#1).arc$delegate()

However, if I create a bean that replaces the original bean and create my mock with mockk() my mocks are working as expected:

class AwsTestClientBean {
    @Alternative
    @Priority(1)
    @ApplicationScoped
    fun organizationsClient(): OrganizationsAsyncClient = mockk()
}
@glefloch
Copy link
Member

Thanks @Obirah for reporting this. Do you have a minimal project setup that reproduce the error ?
It doesn't looks like, but do you use co-routine in your application ?

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