Issue
I am trying to build an integration test method in Java, but there are some service methods that have no returning value (void). So, in this scene, normally I would create a record and then retrieve this record using the id of created record. However, as there is no returned value, how can I write integration test for example such a kind of service method? Is that possible?
public void saveProperties(final Request request, final UUID productUuid) {
repository.saveProduct(request, productUuid);
}
Solution
You can actually verify the service method was called or not using Mockito.verify.
Sample usage:
Mockito.verify(mockedObject, Mockito.times(1)).saveProduct(any(Request.class), any(UUID.class));
This will validate that the saveProduct was called on your mocked object.
Answered By - Mahima
Answer Checked By - Timothy Miller (JavaFixing Admin)