Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
1.7.0
-
None
-
None
Description
So we upgraded from 1.6.3 to Groovy 1.7.0 and realized that one of our tests started failing... it seems that in 1.7.0 unchecked exceptions are simply rethrown (groovy.lang.Closure#throwRuntimeException(Throwable) called from #call(Object[])). Which in groovy.util.GroovyTestCase#shouldFailWithCause(Class,Closure), the exception falls to the catch Throwable branch and the cause is not attempted to be determined beyond that, which causes the test to fail.
Example test showing a successful checked and unsuccessful unchecked exception:
package dummy; import groovy.util.GroovyTestCase; import java.io.IOException; import org.junit.Test; /** * Demonstrates cases of should fail with cause. * @author Charlie Huggard-Lee */ class DummyTest extends GroovyTestCase { public static void failChecked() throws Exception { throw new Exception(new IOException()); } public static void failUnchecked() { throw new RuntimeException(new IOException()); } @Test public void testcheckedFailure() { //Hurray! shouldFailWithCause(IOException.class, {DummyTest.failChecked()}) } @Test public void testuncheckedFailure() { //BOO!!! shouldFailWithCause(IOException.class, {DummyTest.failUnchecked()}) } }