lundi 2 mai 2016

jacoco shows lines as not covered though the lines get executed while running the code

I have the below lines of code of which are indicated as not "executed" by Jacoco.

enter image description here

But when I debug the test case it does execute those lines. Below are the test cases I wrote.

@PrepareForTest({MessagingAdapterFactory.class, MessagingConfigReaderFactory.class,UpdaterServiceExecutor.class,Files.class})
    @Test
    public void should_shutDown_the_scheduledExecutor_and_close_the_messagingAdapter() throws Exception {
        PowerMockito.mockStatic(Files.class);
        PowerMockito.when(Files.exists(any())).thenReturn(true);

        PowerMockito.mockStatic(MessagingAdapterFactory.class);
        PowerMockito.when(MessagingAdapterFactory.getMessagingAdapter("edgeNode")).thenReturn(messagingAdapterMock);
        PowerMockito.mockStatic(MessagingConfigReaderFactory.class);
        PowerMockito.when(MessagingConfigReaderFactory.getConfigurationReader()).thenReturn(readerMock);

        ScheduledExecutorService scheduledExecutorServiceMock = Mockito.mock(ScheduledExecutorService.class);

        PowerMockito.mockStatic(Executors.class);
        PowerMockito.when(Executors.newSingleThreadScheduledExecutor()).thenReturn(scheduledExecutorServiceMock);

        when(readerMock.getConfigParams()).thenReturn("somePath,somePath,somePath");
        when(decompressUtilMock.decompressZip(Matchers.anyString(),Matchers.anyString())).thenReturn(true);
        when(checkSumUtilMock.check(anyString(), anyString())).thenReturn(true);
        when(commandExecutorMock.executeCommand("somePath verify /pa somePathKubeUpdates/KubePlatformSetup.exe")).thenReturn(false);
        updaterServiceExecutor.execute();
        Thread.sleep(10000);
        updaterServiceExecutor.close();

        verify(scheduledExecutorServiceMock,timeout(10000).times(1)).shutdownNow();
        verify(messagingAdapterMock,timeout(10000).times(1)).close();
    }

    @PrepareForTest({MessagingAdapterFactory.class, MessagingConfigReaderFactory.class,UpdaterServiceExecutor.class,Files.class})
    @Test
    public void should_not_throw_ServiceSDKException_when_occurred_while_closing_the_messagingAdapter() throws Exception {
        PowerMockito.mockStatic(Files.class);
        PowerMockito.when(Files.exists(any())).thenReturn(true);

        PowerMockito.mockStatic(MessagingAdapterFactory.class);
        PowerMockito.when(MessagingAdapterFactory.getMessagingAdapter("edgeNode")).thenReturn(messagingAdapterMock);
        PowerMockito.mockStatic(MessagingConfigReaderFactory.class);
        PowerMockito.when(MessagingConfigReaderFactory.getConfigurationReader()).thenReturn(readerMock);

        ScheduledExecutorService scheduledExecutorServiceMock = Mockito.mock(ScheduledExecutorService.class);

        PowerMockito.mockStatic(Executors.class);
        PowerMockito.when(Executors.newSingleThreadScheduledExecutor()).thenReturn(scheduledExecutorServiceMock);

        when(readerMock.getConfigParams()).thenReturn("somePath,somePath,somePath");
        when(decompressUtilMock.decompressZip(Matchers.anyString(),Matchers.anyString())).thenReturn(true);
        when(checkSumUtilMock.check(anyString(), anyString())).thenReturn(true);
        when(commandExecutorMock.executeCommand("somePath verify /pa somePathKubeUpdates/KubePlatformSetup.exe")).thenReturn(false);
        doThrow(new ServiceSDKException()).when(messagingAdapterMock).close();

        updaterServiceExecutor.execute();
        Thread.sleep(10000);
        updaterServiceExecutor.close();

        verify(scheduledExecutorServiceMock,timeout(10000).times(1)).shutdownNow();
        verify(messagingAdapterMock,timeout(10000).times(1)).close();
    }

What is wrong here? Why is Jacoco showing as the lines have not been executed? Please advice.

Aucun commentaire:

Enregistrer un commentaire