Mockito is a Java mocking framework for replacing collaborators with dynamically configured test doubles. It keeps tests focused on production behavior when remote services are costly, unavailable, slow, or unsuitable for the test environment. section 5.3 section 5.3.2
A Quarkus test commonly uses Mockito in this sequence:
- Add the test-scoped io.quarkus:quarkus-junit5-mockito Maven artifact. section 5.3.2
- Create a mock for an object, configure method results with Mockito.when(...).thenReturn(...), and install it for the target CDI type with QuarkusMock. section 5.3.2
- Exercise the application through its resource and verify behavior without calling the real inventory service. section 5.3
Unlike replacing a CDI implementation with a test class, Mockito can mock any object. CDI use requires a normal, proxyable scope; @Singleton and @Dependent beans cannot be mocked, while other built-in CDI scopes work. Mock-based tests also cannot run in native mode when they use mocks or inject CDI into the test itself, because the application runs in another process. section 5.3.2 section 5.6
Mocking inventory availability
Create a GraphQLInventoryClient mock, configure allCars() to return one Peugeot, and install it for that interface. Call the availability endpoint, reserve the returned car, then call availability again to check that the reserved car is no longer offered.

