I’m making some test but my mocking is not working.
This is my test class.
@UnitTest
@RunWith(MockitoJUnitRunner.class)
public class ResendMailingStrategyUnitTest {
@Test
public void sendTest() throws ResendException {
Resend resendClient = Mockito.mock(Resend.class);
Emails mockedEmails = Mockito.mock(Emails.class);
ResendMailingStrategy resendMailingStrategy = new ResendMailingStrategy();
ReflectionTestUtils.setField(resendMailingStrategy, "resendClient", resendClient);
Mockito.when(resendClient.emails()).thenReturn(mockedEmails);
Mockito.when(mockedEmails.send(Mockito.any(CreateEmailOptions.class))).thenReturn(null);
resendMailingStrategy.send(StubProvider.getEmailMessageModelStub());
Mockito.verify(resendClient).emails().send(Mockito.any(CreateEmailOptions.class));
}
}
But my when(resendClient… is not working because method is not returning the mock, I’m getting this error then;
Cannot invoke “com.resend.services.emails.Emails.send(com.resend.services.emails.model.CreateEmailOptions)” because the return value of “com.resend.Resend.emails()” is null