Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#110 EMMA completely misses coverage for reflection calls

open
Vlad Roubtsov
CORE (51)
5
2009-08-09
2009-08-09
Jim Showalter
No

Except for the catch block, EMMA incorrectly marks every line of code below red.

TestUtils uses reflection to invoke methods, and verifies that expected exceptions are thrown. That's easier

than surrounding each call with a flag, try, catch, set of flag, and test of flag.

Why does EMMA mark these red? Obviously they executed, or the line of code marked green could never have been

reached.

Throwable caughtException = null;

final ClassThatThrows classThatThrows = new ClassThatThrows(false);
final ClassThatDoesNotThrow classThatDoesNotThrow = new ClassThatDoesNotThrow();

TestUtils.assertIsExpectedException(
new IllegalArgumentException(),
IllegalArgumentException.class);

TestUtils.assertIsExpectedException(
new IllegalArgumentException("COVERAGE"),
IllegalArgumentException.class, "COVERAGE");

TestUtils.assertIsExpectedException(
new IllegalArgumentException("COVERAGE"),
IllegalArgumentException.class, null);

TestUtils.assertIsExpectedException(
new IllegalArgumentException(),
IllegalArgumentException.class, null);

try
{
TestUtils.assertIsExpectedException(
new IllegalStateException(), IllegalArgumentException.class);
}
catch (final Throwable e)
{
caughtException = e; <<< THIS IS THE ONLY GREEN LINE
}

Discussion