I simply try to test the following part of my service method:
if (isDeleted) {
LoggingUtils.info("Deleted. ingredientUuuid: {}", ingredient.getUuid());
}
I try to use the following approach in order to catch the values passed to the static method:
// @RunWith(MockitoJUnitRunner.class)
@RunWith(PowerMockRunner.class)
public class DemoTest {
@Test
public void test() {
// code omitted
Page<IngredientDTO> result = ingredientService.findAll(request,sort);
PowerMockito.mockStatic(LoggingUtils.class);
ArgumentCaptor<String> arg1 = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<UUID> arg2 = ArgumentCaptor.forClass(UUID.class);
PowerMockito.verifyStatic(LoggingUtils.class, times(1));
LoggingUtils.info(arg1.capture(), arg2.capture());
// ...
}
}
When debugging the test, it throws "The class com.company.common.LoggingUtils not prepared for test." pointing the following line:
PowerMockito.mockStatic(LoggingUtils.class);
So, how can I fix this problem?