MyDev2020
MyDev2020

Reputation: 9

Method not covered during JUnit code coverage (Eclemma code coverage testing); It says "All 2 branches missed"

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

Answers (0)

Related Questions