Class FluentAnyAssertion<T,R>
- Type Parameters:
T
- The object type.R
- The return type.
- Direct Known Subclasses:
AnyAssertion
Extends from FluentObjectAssertion
allowing you to perform basic assertions, but adds several transform
methods to convert to more-specific assertion types.
Example:
Test Methods:
Transform Methods:
FluentAnyAssertion
asArray(Class)
asIntArray()
asLongArray()
asShortArray()
asFloatArray()
asDoubleArray()
asCharArray()
asByteArray()
asBooleanArray()
asBoolean()
asBytes()
asCollection()
asCollection(Class)
asStringList()
asComparable()
asDate()
asInteger()
asLong()
asList()
asList(Class)
asMap()
asMap(Class,Class)
asBean()
asBean(Class)
asBeanList(Class)
asZonedDateTime()
FluentObjectAssertion
Configuration Methods:
See Also:
-
Constructor Summary
ConstructorDescriptionFluentAnyAssertion
(Assertion creator, T value, R returns) Chained constructor.FluentAnyAssertion
(T value, R returns) Constructor. -
Method Summary
Modifier and TypeMethodDescription<E> FluentArrayAssertion<E,
R> Converts this object assertion into an array assertion.asBean()
Converts this object assertion into a bean assertion.<T2> FluentBeanAssertion<T2,
R> Converts this object assertion into a bean assertion.<T2> FluentBeanListAssertion<T2,
R> asBeanList
(Class<T2> beanType) Converts this object assertion into a list-of-beans assertion.Converts this object assertion into a boolean assertion.FluentPrimitiveArrayAssertion<Boolean,
boolean[], R> Converts this object assertion into a primitive boolean array assertion.FluentPrimitiveArrayAssertion<Byte,
byte[], R> Converts this object assertion into a primitive byte array assertion.asBytes()
Converts this object assertion into a byte array assertion.FluentPrimitiveArrayAssertion<Character,
char[], R> Converts this object assertion into a primitive char array assertion.Converts this object assertion into a collection assertion.<E> FluentCollectionAssertion<E,
R> asCollection
(Class<E> elementType) Converts this object assertion into a collection assertion.<T2 extends Comparable<T2>>
FluentComparableAssertion<T2,R> Converts this object assertion into a comparable object assertion.asDate()
Converts this object assertion into a date assertion.FluentPrimitiveArrayAssertion<Double,
double[], R> Converts this object assertion into a primitive double array assertion.FluentPrimitiveArrayAssertion<Float,
float[], R> Converts this object assertion into a primitive float array assertion.Converts this object assertion into a primitive int array assertion.Converts this object assertion into an integer assertion.asList()
Converts this object assertion into a list assertion.<E> FluentListAssertion<E,
R> Converts this object assertion into a list assertion.asLong()
Converts this object assertion into a long assertion.FluentPrimitiveArrayAssertion<Long,
long[], R> Converts this object assertion into a primitive long array assertion.asMap()
Converts this object assertion into a map assertion.<K,
V> FluentMapAssertion<K, V, R> Converts this object assertion into a map assertion with the specified key and value types.FluentPrimitiveArrayAssertion<Short,
short[], R> Converts this object assertion into a primitive short array assertion.Converts this object assertion into a collection assertion.Converts this object assertion into a zoned-datetime assertion.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
.Methods inherited from class org.apache.juneau.assertions.FluentObjectAssertion
asAny, asJson, asJsonSorted, asString, asString, asString, asTransformed, asTransformedTo, equals, getFailureMessage, is, is, isAny, isExactType, isExists, isJson, isNot, isNotAny, isNotNull, isNull, isSame, isSameJsonAs, isSameSerializedAs, isSameSortedJsonAs, isString, isType, map, opt, orElse, toString, value, valueAsString, valueIsNotNull, valueIsNull
Methods inherited from class org.apache.juneau.assertions.FluentAssertion
returns
Methods inherited from class org.apache.juneau.assertions.Assertion
arrayClass, className, error, error
-
Constructor Details
-
FluentAnyAssertion
Constructor.- Parameters:
value
- The object being tested.
Can benull .returns
- The object to return after a test method is called.
Ifnull , the test method returns this object allowing multiple test method calls to be used on the same assertion.
-
FluentAnyAssertion
Chained constructor.Used when transforming one assertion into another so that the assertion config can be used by the new assertion.
- Parameters:
creator
- The assertion that created this assertion.
Should benull if this is the top-level assertion.value
- The object being tested.
Can benull .returns
- The object to return after a test method is called.
Ifnull , the test method returns this object allowing multiple test method calls to be used on the same assertion.
-
-
Method Details
-
asArray
Converts this object assertion into an array assertion.- Type Parameters:
E
- The element type of the array.- Parameters:
elementType
- The element type of the array.- Returns:
- A new assertion.
- Throws:
AssertionError
- If object is not an array.
-
asIntArray
Converts this object assertion into a primitive int array assertion.- Returns:
- A new assertion.
- Throws:
AssertionError
- If object is not an int array.
-
asLongArray
Converts this object assertion into a primitive long array assertion.- Returns:
- A new assertion.
- Throws:
AssertionError
- If object is not an long array.
-
asShortArray
Converts this object assertion into a primitive short array assertion.- Returns:
- A new assertion.
- Throws:
AssertionError
- If object is not an short array.
-
asFloatArray
Converts this object assertion into a primitive float array assertion.- Returns:
- A new assertion.
- Throws:
AssertionError
- If object is not an float array.
-
asDoubleArray
Converts this object assertion into a primitive double array assertion.- Returns:
- A new assertion.
- Throws:
AssertionError
- If object is not an double array.
-
asCharArray
Converts this object assertion into a primitive char array assertion.- Returns:
- A new assertion.
- Throws:
AssertionError
- If object is not an char array.
-
asByteArray
Converts this object assertion into a primitive byte array assertion.- Returns:
- A new assertion.
- Throws:
AssertionError
- If object is not an byte array.
-
asBooleanArray
Converts this object assertion into a primitive boolean array assertion.- Returns:
- A new assertion.
- Throws:
AssertionError
- If object is not an boolean array.
-
asBoolean
Converts this object assertion into a boolean assertion.- Returns:
- A new assertion.
- Throws:
AssertionError
- If object is not a boolean.
-
asBytes
Converts this object assertion into a byte array assertion.- Returns:
- A new assertion.
- Throws:
AssertionError
- If object is not a byte array.
-
asCollection
Converts this object assertion into a collection assertion.- Returns:
- A new assertion.
- Throws:
AssertionError
- If object is not a collection.
-
asCollection
Converts this object assertion into a collection assertion.- Type Parameters:
E
- The element type of the collection.- Parameters:
elementType
- The element type of the collection.- Returns:
- A new assertion.
- Throws:
AssertionError
- If object is not a collection.
-
asStringList
Converts this object assertion into a collection assertion.- Returns:
- A new assertion.
- Throws:
AssertionError
- If object is not a collection.
-
asComparable
Converts this object assertion into a comparable object assertion.- Type Parameters:
T2
- The comparable type.- Returns:
- A new assertion.
- Throws:
AssertionError
- If object is not an instance ofComparable
.
-
asDate
Converts this object assertion into a date assertion.- Returns:
- A new assertion.
- Throws:
AssertionError
- If object is not a date.
-
asInteger
Converts this object assertion into an integer assertion.- Returns:
- A new assertion.
- Throws:
AssertionError
- If object is not an integer.
-
asLong
Converts this object assertion into a long assertion.- Returns:
- A new assertion.
- Throws:
AssertionError
- If object is not a long.
-
asList
Converts this object assertion into a list assertion.- Returns:
- A new assertion.
- Throws:
AssertionError
- If object is not a list.
-
asList
Converts this object assertion into a list assertion.- Type Parameters:
E
- The element type.- Parameters:
elementType
- The element type.- Returns:
- A new assertion.
- Throws:
AssertionError
- If object is not a list.
-
asMap
Converts this object assertion into a map assertion.- Returns:
- A new assertion.
- Throws:
AssertionError
- If object is not a map.
-
asMap
Converts this object assertion into a map assertion with the specified key and value types.- Type Parameters:
K
- The key type.V
- The value type.- Parameters:
keyType
- The key type.valueType
- The value type.- Returns:
- A new assertion.
- Throws:
AssertionError
- If object is not a map.
-
asBean
Converts this object assertion into a bean assertion.- Type Parameters:
T2
- The bean type.- Parameters:
beanType
- The bean type.- Returns:
- A new assertion.
- Throws:
AssertionError
- If object is not a bean.
-
asBean
Converts this object assertion into a bean assertion.- Returns:
- A new assertion.
- Throws:
AssertionError
- If object is not a bean.
-
asBeanList
Converts this object assertion into a list-of-beans assertion.- Type Parameters:
T2
- The bean type.- Parameters:
beanType
- The bean type.- Returns:
- A new assertion.
- Throws:
AssertionError
- If object is not a bean.
-
asZonedDateTime
Converts this object assertion into a zoned-datetime assertion.- Returns:
- A new assertion.
- Throws:
AssertionError
- If object is not a zoned-datetime.
-
setMsg
Description copied from class:Assertion
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();- Overrides:
setMsg
in classFluentObjectAssertion<T,
R> - Parameters:
msg
- The assertion failure message.args
- Optional message arguments.- Returns:
- This object.
-
setOut
Description copied from class:Assertion
If an error occurs, send the error message to the specified stream instead of STDERR.- Overrides:
setOut
in classFluentObjectAssertion<T,
R> - Parameters:
value
- The output stream. Can benull to suppress output.- Returns:
- This object.
-
setSilent
Description copied from class:Assertion
Suppresses output to STDERR.This is the equivalent to calling
out( .null )- Overrides:
setSilent
in classFluentObjectAssertion<T,
R> - Returns:
- This object.
-
setStdOut
Description copied from class:Assertion
If an error occurs, send the error message to STDOUT instead of STDERR.- Overrides:
setStdOut
in classFluentObjectAssertion<T,
R> - Returns:
- This object.
-
setThrowable
Description copied from class:Assertion
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();- Overrides:
setThrowable
in classFluentObjectAssertion<T,
R> - Parameters:
value
- The new value for this setting.- Returns:
- This object.
-