1 year ago

#239400

test-img

from_tel

Quarkus: how do I mock the smallrye-graphql-client using Mockito?

I am having some issues trying to mock the smallrye-graphql-client in my unit tests. I thought it would be a process similar to mocking the RestClient https://github.com/quarkusio/quarkus/issues/9630 but it doesn't work that way.

GraphQL client:

@GraphQLClientApi(configKey = "graphql-client")
public interface SomeGraphQLClient {
    @Query("accounts")
    List<Account> getAccounts();
}

Test:

@QuarkusTest
public final class SomeGraphQLClientTest {
    @InjectMock()
    SomeGraphQLClient client;

    @BeforeEach
    void setup() {
        when(client.getAccounts()).thenReturn(... list of accounts...);
    }

    @Test
    public void someTest() {
        ...
    }
}

application.yaml

  ...
  smallrye-graphql-client:
    graphql-client:
      url: http://localhost:8081/graphql

Error message:

Invalid use of io.quarkus.test.junit.mockito.InjectMock - the injected bean does not declare a CDI normal scope but: javax.inject.Singleton.

How can I mock the smallrye-graphql-client in Quarkus?

Thank you in advance for your help

unit-testing

graphql

mockito

quarkus

smallrye

0 Answers

Your Answer

Accepted video resources