Reputation: 9
I was wondering if anyone could help me, my method is not covered during code coverage testing even though I mocked it in the test class.
This is my method in the main class DeviceService.java
which I am trying to mock in test class:
public List<String> getDeviceList(String device) {
if (StringUtils.hasText(device)) {
List <String> deviceList = Stream.of(device.split("[, ]")).collect(Collectors.toList());
return deviceList ;
}
return null;
}
This is my test class method in DeviceServiceTest.java
. I mocked thegetDeviceList
in test class like this, in two separate test methods:
@Mock
private DeviceService parameters;
when(parameters.getDeviceList(Mockito.any())).thenReturn(Arrays.asList("Smartphone"));
when(parameters.getDeviceList(Mockito.any())).thenReturn(new ArrayList<>());
Upvotes: 0
Views: 1300