I use SonarQube that link to my project and the result is I have some condition that not covered by the test. That condition doesn't have any return or throws some exception. I tried to search in Google but I still don't know how to testing some condition that doesn't have any return or throws exception to catch. Here is my code:
List<ResGetProductVO> responses = new ArrayList<>();
if (category.equals("0") && name.equals("0")) {
Page<ProductPriceOTR> listProduct = productPriceOTRRepository.fetchByLocation(min, max, location, pageable);
for (ProductPriceOTR list : listProduct.getContent()) {
responses.add(listProductMapper.domainToResponse(list));
}
totalElements = (int) listProduct.getTotalElements();
totalPages = listProduct.getTotalPages();
} else if (!category.equals("0") && name.equals("0")) {
Page<ProductPriceOTR> listProduct = productPriceOTRRepository.fetchByLocationAndCategory(min, max,
location, category, pageable);
for (ProductPriceOTR list : listProduct.getContent()) {
responses.add(listProductMapper.domainToResponse(list));
}
totalElements = (int) listProduct.getTotalElements();
totalPages = listProduct.getTotalPages();
}
What should I do to covered that condition? Or any sugestions?
Aucun commentaire:
Enregistrer un commentaire