1

org.jboss.logging.Logger with @Inject annotation in my code causes NullPointerException in my unit test annotated with @ExtendWith(MockitoExtension.class), if I define it as a org.mockito.@Mock. It's fine if it's used in @QuarkusTest as @Inject Logger, as Quarkus will inject it.

I don't want to change my unit test to @QuarkusTest only for this reason. How can I avoid this NPE caused by logger not initialized by Mockito?

Is this question related? Mock Quarkus provided logger

WesternGun
  • 11,303
  • 6
  • 88
  • 157

1 Answers1

1

I have a workaround now:

  • set logger in src to be package visibility, so it can be accessed from test
  • org.mockito.@Mock it in JUnit test
  • in @BeforeEach, set the mock to the class to test, like someInstance.logger = mockLogger;

It has no impact on the original code base, as Quarkus always requires the injected field to be package-private.

WesternGun
  • 11,303
  • 6
  • 88
  • 157