[Java] Class GroovyAssert

  • groovy.util.GroovyAssert
deprecated:
Use the GroovyAssert class instead

Methods Summary

Methods
Type Params Return Type Name and description
static Throwable shouldFail(Closure code)
Asserts that the given code closure fails when it is evaluated
static Throwable shouldFail(Class clazz, Closure code)
Asserts that the given code closure fails when it is evaluated and that a particular exception is thrown.
static Throwable shouldFailWithCause(Class clazz, Closure code)
Asserts that the given code closure fails when it is evaluated and that a particular exception can be attributed to the cause.

Inherited Methods Summary

Inherited Methods
Methods inherited from class Name
class Object wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll

Method Detail

public static Throwable shouldFail(Closure code)

Asserts that the given code closure fails when it is evaluated

Parameters:
code - the code expected to throw the exception
Returns:
the message of the thrown Throwable

public static Throwable shouldFail(Class clazz, Closure code)

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

Parameters:
clazz - the class of the expected exception
code - the closure that should fail
Returns:
the message of the expected Throwable

public static Throwable shouldFailWithCause(Class clazz, Closure code)

Asserts that the given code closure fails when it is evaluated and that a particular exception 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 error message associated with the matching exception is returned. If no match was found the method will fail.

Parameters:
clazz - the class of the expected exception
code - the closure that should fail
Returns:
the message of the expected Throwable

© 2003-2020 The Apache Software Foundation
Licensed under the Apache license.
https://docs.groovy-lang.org/2.4.21/html/gapi/groovy/util/GroovyAssert.html