简体   繁体   中英

Integration Test for methods with no returning value in Java

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);
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM