quarkus-junit5-mockito is deprecated - How to mock rest clients when unittesting a Quarkus application?

879 Views Asked by At

I'm using the latest version of quarkus (3.4 at this moment) and as usual I used the following dependency:

<dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-junit5-mockito</artifactId>
      <scope>test</scope>
</dependency>

mockito is deprecated

When I imported it I had this issue, it is deprecated from version 3.2 of Quarkus.

And now how to mock ?

I tried using mockito but in new versions of quarkus it is deprecated. I hope I can mock it somehow without using something deprecated.

2

There are 2 best solutions below

1
Natan On

I found a way. I'm not using something deprecated.

Mocking with QuarkusMock

My example:

 ExtensionsService customMock = new ExtensionsService() {
            @Override
            public JsonObject getForbiddenNumbers() {
                return new JsonObject("{\"forbiddenNumbers\":[5,7,23]}");
            }
        };
        QuarkusMock.installMockForType(customMock, ExtensionsService.class, RestClient.LITERAL);

In this example ExtensionsService is the rest client.

For more information: Quarkus documentation

0
Ladicek On

quarkus-junit5-mockito is NOT deprecated.

What is deprecated is the io.quarkus.test.junit.mockito.InjectMock annotation, nothing else.

The replacement is the io.quarkus.test.InjectMock annotation, together with io.quarkus.test.junit.mockito.InjectMock if you need the extra options.