How to mock a final class to return nothing when a function from a final class is called?
in Test Method:
@InjectMocks
CustomerService customerService;
@Mock
AddCustomerProfile addCustomerProfile;
@Test
public void saveCustomer(){
CustomerDefinition customerDefinition = new CustomerDefinition();
customerDefinition.setName("Chris");
customerService.saveCustomer(addCustomerProfile);
}
in CustomerService class,
saveCustomer(AddCustomerProfile addCustomerProfile){
Message message = new Message();
message.setName("Messager");
Webber.addMessageToResponse(message);
}
in Webber class,
public final class Webber{
public static void addMessageToResponse(Message message){
.
.
.
}
When customerService.saveCustomer() function is called on the test, I have to mock the behavior of Webber.addMessageToResponse(message) so as to return nothing. I should mock as it should not go inside Webber.addMessageToResponse() method as it is calling another Final method inside that method.
I added mockito-inline in pom.xml but it doesnt actually mock the behavior.
John K Jose is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.