Cobertura check and cobertura:cobertura fail when the current thread is 
interrupted
-----------------------------------------------------------------------------------

                 Key: MCOBERTURA-134
                 URL: http://jira.codehaus.org/browse/MCOBERTURA-134
             Project: Maven 2.x Cobertura Plugin
          Issue Type: Bug
    Affects Versions: 2.4
            Reporter: Petter Måhlén


Given the following method:

    @Override
    public void run()  {
        while (!exit.shouldExit()) {
            try {
                TestRun run = queue.poll(100, TimeUnit.SECONDS);

                if (run == null) {
                    LOG.info("Timed out waiting for a run, this is fine, I've 
got all the time in the world");
                }
                else {
                    run.setCurrentStatus(TestRunStatus.RUNNING);
                    ProgressReporter progressReporter = new 
TestRunProgressReporter(run);

                    URL resultUrl = service.runTest(run.getTestParameters(), 
new DateTime(), progressReporter);

                    run.setCurrentStatus(TestRunStatus.DONE);
                    run.setResultUrl(resultUrl);
                }
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                exit.doExit();
            }
        }
    }

And the following unit test (using Mockito and JUnit 4):

    @SuppressWarnings({"ThrowableInstanceNeverThrown"})
    @Test
    public void testInterruption() throws Exception {
        when(queue.poll(anyLong(), any(TimeUnit.class))).thenThrow(new 
InterruptedException("expected"));
        when(exit.shouldExit()).thenReturn(false, true);

        runner.run();

        assertTrue(Thread.currentThread().isInterrupted());
        verify(exit).doExit();
    }

I would expect the 'catch' section of the method to be covered. Stepping 
through with the debugger in IntelliJ IDEA and checking coverage using the 
plugins avaible in IDEA, all of them report that the catch statement is 
executed. However, the cobertura-maven-plugin doesn't even though the test case 
completes successfully. I believe that is a bug due to the usage of 
Thread.currentThread().interrupt() or isInterrupted(), but I can't be sure. I 
also don't know if it is a bug in Cobertura itself or the plugin.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to