I am using the Maven (2) Cobertura plug-in to create reports on code coverage, and I have the following stub I am using in a method:
try { System.exit(0); } catch (final SecurityException exception) { exception.printStackTrace(); } System.err.println('The program never exited!');
I know that I need to log the exception, etc, but that’s not the point right now…Cobertura is refusing to acknowledge that the line after the stack trace is printed is covered. That is, the line with the ‘}’ before the System.err.println statement is not being shown as covered. Before, the ending curly brace of the method was not being shown as covered, hence the System.err statement. Any idea how I can convince cobertura’s maven plugin that, since the System.err.println statement is covered, that ending brace has to have been covered?
Oh yeah, and I use a mock security manager to throw the security exception, since that’s the easiest way I have found of making the test continue executing after the System.exit call.
I haven’t used Cobertura in a while (2005?), and saw this behavior back then. A similar problem exists with NCover for C# and curly braces following catch/finally blocks.
My suggestion would be to add to this Cobertura bug report detailing a similar issue. Also, follow @tvanfosson’s advice and realize not having coverage on a curly brace, which doesn’t actually become anything in the JVM, is something you can ignore as ‘noise’.