title: How to mock @injected object in class using Mockito?
body: <p>I have the following Java code:</p>
  <hr />
  <p>Filename: <code>MyClass.java</code></p>
  <pre><code>
  import javax.inject.Inject;
  ...
  
  public class MyClass {
    @inject
    private MyDatabaseDao myDatabaseDao;
  
    public MyResponse process() {
      ...
      String value = myPrivateMethod(x, y, z);
      ...
    }
  
    private String myPrivateMethod(String x, String y, String z) {
      value = myDatabaseDao.operation(x, y, x); // Line Number 86
      ...
    }  
  }
  </code></pre>
  <hr />
  <p>Filename: <code>MyClassTest.java</code></p>
  <pre><code>@ExtendWith(MockitoExtension.class)
  public class MyClassTest {
    @InjectMocks
    MyClass myClass;
  
    @Mock
    MyDatabaseDao myDatabaseDao;
  
    @Test
    void testProcess() {
      ...
  
      Mockito.when(myDatabaseDao.operation(any(), any(), any()))
                  .thenReturn(someValue);
      ...
      assertEquals(testResponse, myClass.process());    
    }
  }
  </code></pre>
  <p>I get a <code>nullPointerException</code> in line number 86 of <code>MyClass.java</code>, i.e., the <code>myDatabaseDao</code> object in that line is null. How can I properly mock and pass that object?</p>
  <p>I am using JUnit 5 and Mockito v4.2.0</p>