0

I Have a piece of a really simple code.

Something like:

public class Foo {
   public void bar() {
      timer.start();
      try{
        ///
      } finally {
         timer.stop();
      }
   }
}

I have a unit test that runs with Mockito and when I use IntelliJ option for code-coverage it marks the line in the finally as not covered. The thing is that it happens only when I throw an exception inside the try. The even more weird issue is that I have an assert that makes sure the call in the finally block was called:

Mockito.verify(timer).stop(); // timer is mocked here of course

When I run debug, the debugger stops in this line. When I run a test without an exception in the finally block - the coverage marks it as covered.

What am I missing here?

Avi
  • 21,182
  • 26
  • 82
  • 121
  • How are you verifying `bar`? How does `Foo` (or `bar()`) have visibility to `timer`? – Elliott Frisch Sep 02 '14 at 20:37
  • possible duplicate of [Why emma doesn't give full coverage to finally blocks?](http://stackoverflow.com/questions/4841882/why-emma-doesnt-give-full-coverage-to-finally-blocks) –  Sep 02 '14 at 20:39
  • @ElliottFrisch - I didn't write the whole code here but timer is an injected mock object. It's injected in the constructor. In the test I mock it in order to run `verify` on it. – Avi Sep 02 '14 at 20:49

0 Answers0