'Mock Quarkus Template interface using Mockito

I am using Quarkus Template for a base email HTML template like this:

@Location("MailTemplate")
Template template;

... code ...

public void sendEmail(final SendEmailRequest sendEmailRequest) {
        final String html = template.data("sendEmailRequest", sendEmailRequest).render();
}

When I try to mock the interface using @Mock it gives me an error and the property comes as null instead of mocked. Im mocking like this:

@ExtendWith(MockitoExtension.class)
public class EmailServiceTest {

    @Spy
    @InjectMocks
    EmailService emailService;

    @Mock
    Template templateMock;

    @Test
    void sendEmail() {
        // Given
        SendEmailRequest sendEmailRequest = EmailDataProvider.createSendEmailRequest();

        // When
        emailService.sendEmail(sendEmailRequest);

    }
}

The error: java.lang.NullPointerException: Cannot invoke "io.quarkus.qute.Template.data(String, Object)" because "<local3>.template" is null

I usually mock other services/repositories like this, but it seems like that for this interface this doesnt work :/ Any idea why?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source