Class Assertion
- Direct Known Subclasses:
FluentAssertion
Test Methods:
- None
Transform Methods:
- None
Configuration Methods:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected static <E> Class<E[]>
arrayClass
(Class<E> c) Convenience method for getting the array class of the specified element type.protected static String
Convenience method for getting the class name for an object.protected BasicAssertionError
Creates a newBasicAssertionError
.protected BasicAssertionError
Creates a newBasicAssertionError
.Allows you to override the assertion failure message.setOut
(PrintStream value) If an error occurs, send the error message to the specified stream instead of STDERR.Suppresses output to STDERR.If an error occurs, send the error message to STDOUT instead of STDERR.setThrowable
(Class<? extends RuntimeException> value) If an error occurs, throw this exception instead of the standardAssertionError
.
-
Constructor Details
-
Assertion
Constructor used when this assertion is being created from within another assertion.- Parameters:
creator
- The creator of this assertion.
-
-
Method Details
-
setMsg
Allows you to override the assertion failure message.String can contain
"{msg}" to represent the original message.Example:
import static org.apache.juneau.assertions.Assertions.*;// Throws an assertion with a custom message instead of the default "Value was null." assertString (myString ) .setMsg("My string was bad: {msg}" ) .isNotNull();- Parameters:
msg
- The assertion failure message.args
- Optional message arguments.- Returns:
- This object.
-
setStdOut
If an error occurs, send the error message to STDOUT instead of STDERR.- Returns:
- This object.
-
setOut
If an error occurs, send the error message to the specified stream instead of STDERR.- Parameters:
value
- The output stream. Can benull to suppress output.- Returns:
- This object.
-
setSilent
Suppresses output to STDERR.This is the equivalent to calling
out( .null )- Returns:
- This object.
-
setThrowable
If an error occurs, throw this exception instead of the standardAssertionError
.The throwable class must have a public constructor that takes in any of the following parameters:
If the throwable cannot be instantiated, a
RuntimeException
is thrown instead.Example:
import static org.apache.juneau.assertions.Assertions.*;// Throws a BadRequest instead of an AssertionError if the string is null. assertString (myString ) .setThrowable(BadRequest.class ) .isNotNull();- Parameters:
value
- The new value for this setting.- Returns:
- This object.
-
error
Creates a newBasicAssertionError
.- Parameters:
msg
- The message.args
- The message arguments.- Returns:
- A new
BasicAssertionError
.
-
error
Creates a newBasicAssertionError
.- Parameters:
cause
- Optional caused-by throwable.msg
- The message.args
- The message arguments.- Returns:
- A new
BasicAssertionError
.
-
className
Convenience method for getting the class name for an object.- Parameters:
o
- The object to get the class name for.- Returns:
- The class name for an object.
-
arrayClass
Convenience method for getting the array class of the specified element type.- Type Parameters:
E
- The element type.- Parameters:
c
- The object to get the class name for.- Returns:
- The class name for an object.
-