Skip to content

Instantly share code, notes, and snippets.

@moznion
Created November 23, 2012 06:33
Show Gist options
  • Save moznion/4134247 to your computer and use it in GitHub Desktop.
Save moznion/4134247 to your computer and use it in GitHub Desktop.
Reinventing shouldFail() part2
import groovy.util.GroovyTestCase
public class Test extends GroovyTestCase {
private shouldFailBy(Class expected, Closure c) {
try {
c.call()
assert false // Failure
} catch (Throwable t) {
assert expected.isInstance(t)
}
}
public void test() {
shouldFailBy (NullPointerException) {throw new NullPointerException()}
shouldFailBy (IllegalAccessError) {throw new IllegalAccessError()}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment