0

I am trying to reach high % coverage using EclEmma on a piece of code and I am having problem covering the following:

public class foo() {

    ReadWriteLock compositeLock;

    @VisibleForTesting
    @Guardedby("compositeLock")
    public class String far() {
        compositeLock.getLock().unlock();
        try {
            //code..
            return answer;
        } finally { 
            compositeLock.getLock().lock();
        }
    }
}

I am missing coverage on the finally part, should I use mockito and mock the ReadWriteLock? Or is mocking not needed?

cheffe
  • 9,345
  • 2
  • 46
  • 57
PhoonOne
  • 2,678
  • 12
  • 48
  • 76
  • Have you written unit test for ReadWriteLock? BTW, the purpose of unit testing is not just to improve the coverage! – Nilesh Apr 22 '14 at 04:36
  • I just reformatted your code, but reading it: You **un**-lock before doing things and then lock within finally? – cheffe Apr 22 '14 at 08:14
  • Sounds like a bug in your coverage tool. If you're testing this method at all, then the `finally` clause is being run. It seems odd to me that a coverage tool would claim that you haven't covered it. – Dawood ibn Kareem Apr 22 '14 at 19:05

0 Answers0