I have the following method and I wrote a unit test in Java for this method. It is coveraged except from the if
statement and I also need to test this part.
@InjectMocks
private ProductServiceImpl productService;
public void demoMethod(final List<UUID> productUuidList) {
if (productUuidList.isEmpty()) {
return;
}
final Map<ProductRequest, PriceOverride> requestMap = getPriceRequests(uuidList);
productService.updateByPriceList(priceRequestMap, companyUuid);
}
However, as the method execution is finalized and does not return anything when uuidList
is empty, I cannot test this if
block.
So:
How can I test this
if
block?Should I create a new Unit Test method for testing this
if
block? Or should I add related assert lines to the current test method?
Update: Here is my test method:
@Test
public void testDemoMethod() {
final UUID uuid = UUID.randomUUID();
final List<Price> priceList = new ArrayList<>();
final Price price = new Price();
price.setUuid(uuid);
priceList.add(price);
productService.demoMethod(Collections.singletonList(uuid));
}