Skip to content

Instantly share code, notes, and snippets.

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