Groovy Documentation

groovy.test
[Java] Class GroovyAssert

java.lang.Object
  groovy.test.GroovyAssert

public class GroovyAssert

Method Summary
static java.lang.Throwable shouldFail(Closure code)

Asserts that the given code closure fails when it is evaluated

static java.lang.Throwable shouldFail(java.lang.Class clazz, Closure code)

Asserts that the given code closure fails when it is evaluated and that a particular type of exception is thrown.

static java.lang.Throwable shouldFailWithCause(java.lang.Class expectedCause, Closure code)

Asserts that the given code closure fails when it is evaluated and that a particular Exception type can be attributed to the cause.

 
Methods inherited from class java.lang.Object
java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Method Detail

shouldFail

public static java.lang.Throwable shouldFail(Closure code)
Asserts that the given code closure fails when it is evaluated
Parameters:
code - the code expected to fail
Returns:
the caught exception


shouldFail

public static java.lang.Throwable shouldFail(java.lang.Class clazz, Closure code)
Asserts that the given code closure fails when it is evaluated and that a particular type of exception is thrown.
Parameters:
clazz - the class of the expected exception
code - the closure that should fail
Returns:
the caught exception


shouldFailWithCause

public static java.lang.Throwable shouldFailWithCause(java.lang.Class expectedCause, Closure code)
Asserts that the given code closure fails when it is evaluated and that a particular Exception type can be attributed to the cause. The expected exception class is compared recursively with any nested exceptions using getCause() until either a match is found or no more nested exceptions exist.

If a match is found, the matching exception is returned otherwise the method will fail.

Parameters:
expectedCause - the class of the expected exception
code - the closure that should fail
Returns:
the cause


 

Groovy Documentation