Package org.apache.groovy.contracts
Class ThrowsIfViolation
java.lang.Object
java.lang.Throwable
java.lang.Error
java.lang.AssertionError
org.apache.groovy.contracts.AssertionViolation
org.apache.groovy.contracts.ThrowsIfViolation
- All Implemented Interfaces:
Serializable
Thrown whenever a
@ThrowsIf exceptional-contract violation is detected
by a checked arm-set: the method returned normally although a
must-throw condition held, or threw a matching exception although no arm's
condition held (the latter checked only for exhaustive arm-sets).
Deliberately not the arm's declared exception: the declared exception is defined behaviour delivered at method entry, whereas this violation reports a broken implementation of the contract — late-throwing the declared exception would masquerade the bug as defined behaviour.
- Since:
- 6.0.0
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a throws-if violation without an explicit detail message.ThrowsIfViolation(boolean b) Creates a throws-if violation with a boolean detail.ThrowsIfViolation(char c) Creates a throws-if violation with a char detail.ThrowsIfViolation(double d) Creates a throws-if violation with a double detail.ThrowsIfViolation(float f) Creates a throws-if violation with a float detail.ThrowsIfViolation(int i) Creates a throws-if violation with an int detail.ThrowsIfViolation(long l) Creates a throws-if violation with a long detail.Creates a throws-if violation with an object-valued detail. -
Method Summary
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
ThrowsIfViolation
public ThrowsIfViolation()Creates a throws-if violation without an explicit detail message. -
ThrowsIfViolation
Creates a throws-if violation with an object-valued detail.- Parameters:
o- the detail object
-
ThrowsIfViolation
public ThrowsIfViolation(boolean b) Creates a throws-if violation with a boolean detail.- Parameters:
b- the detail value
-
ThrowsIfViolation
public ThrowsIfViolation(char c) Creates a throws-if violation with a char detail.- Parameters:
c- the detail value
-
ThrowsIfViolation
public ThrowsIfViolation(int i) Creates a throws-if violation with an int detail.- Parameters:
i- the detail value
-
ThrowsIfViolation
public ThrowsIfViolation(long l) Creates a throws-if violation with a long detail.- Parameters:
l- the detail value
-
ThrowsIfViolation
public ThrowsIfViolation(float f) Creates a throws-if violation with a float detail.- Parameters:
f- the detail value
-
ThrowsIfViolation
public ThrowsIfViolation(double d) Creates a throws-if violation with a double detail.- Parameters:
d- the detail value
-