Find uninitialized Mockito annotated fields

Proprietary

Marks a class that declares a @Mock, @Spy, @Captor or @InjectMocks field when nothing in the class initializes those fields, so they stay null unless the test assigns them by hand. A class is not marked when it, or a class enclosing it, declares a variable of type MockitoRule, MockitoSession or MockitoExtension, calls MockitoAnnotations.openMocks or initMocks, MockitoJUnit.rule or testRule, or Mockito.mockitoSession, or carries @ExtendWith on a method or field, anywhere in its own body outside nested classes. Nor is it marked when it, or a class enclosing it, carries an annotation from a package other than java.lang, org.junit and org.junit.jupiter.api, since such an annotation may register a runner or extension, as @RunWith, @ExtendWith, @MockitoSettings and @SpringBootTest do. The same holds for a class that implements an interface carrying such an annotation, has a superclass, which may initialize the fields, or is abstract.

io.moderne.staticanalysis.FindUninitializedMockitoAnnotations
mod run . --recipe=io.moderne.staticanalysis.FindUninitializedMockitoAnnotations

Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.