Class FluentObjectAssertion<T,R> 
- Type Parameters:
- T- The object type.
- R- The return type.
- Direct Known Subclasses:
- FluentAnyAssertion,- FluentArrayAssertion,- FluentBeanAssertion,- FluentCollectionAssertion,- FluentComparableAssertion,- FluentMapAssertion,- FluentPrimitiveArrayAssertion,- FluentProtocolVersionAssertion,- FluentRequestContentAssertion,- FluentRequestLineAssertion,- FluentResponseBodyAssertion,- FluentResponseStatusLineAssertion,- FluentStringAssertion,- FluentThrowableAssertion,- ObjectAssertion
Test Methods:
Transform Methods:
Configuration Methods:
See Also:
- 
Constructor SummaryConstructorsConstructorDescriptionFluentObjectAssertion(Assertion creator, T value, R returns) Chained constructor.FluentObjectAssertion(T value, R returns) Constructor.
- 
Method SummaryModifier and TypeMethodDescriptionasAny()Converts this assertion into anFluentAnyAssertionso that it can be converted to other assertion types.asJson()Converts this object to simplified JSON and returns it as a new assertion.Converts this object to sorted simplified JSON and returns it as a new assertion.asString()Converts this object to a string usingObject.toString()and returns it as a new assertion.Converts this object to a string using the specified function and returns it as a new assertion.Converts this object to text using the specified serializer and returns it as a new assertion.asTransformed(Function<T, T> function) Applies a transform on the inner object and returns a new inner object.<T2> FluentObjectAssertion<T2,R> asTransformedTo(Function<T, T2> function) Applies a transform on the inner object and returns a new inner object.protected booleanChecks two objects for equality.protected StringgetFailureMessage(Predicate<?> p, Object value) Returns the predicate failure message.Asserts that the value passes the specified predicate test.Asserts that the value equals the specified value.final RAsserts that the value is one of the specified values.isExactType(Class<?> type) Asserts that the object is an instance of the specified class.isExists()Asserts that the object is not null.Converts this object to simplified JSON and runs theFluentStringAssertion.is(String)on the result.Asserts that the value does not equal the specified value.final RAsserts that the value is not one of the specified values.Asserts that the object is not null.isNull()Asserts that the object i null.Asserts that the specified object is the same object as this object.Verifies that two objects are equivalent after converting them both to JSON.isSameSerializedAs(Object o, WriterSerializer serializer) Asserts that the specified object is the same as this object after converting both to strings using the specified serializer.Verifies that two objects are equivalent after converting them both to sorted JSON.Asserts that the value converted to a string equals the specified value.Asserts that the object is an instance of the specified class.protected <T2> Optional<T2>Returns the result of running the specified function against the value and returns the result.opt()Returns the value wrapped in anOptional.protected TReturns the inner value or the other value if the value isnull .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.toString()Returns the string form of the inner object.protected Tvalue()Returns the inner value after asserting it is notnull .protected StringReturns the inner value as a string.protected booleanReturnstrue if the inner value is not null.protected booleanReturnstrue if the inner value is null.Methods inherited from class org.apache.juneau.assertions.FluentAssertionreturnsMethods inherited from class org.apache.juneau.assertions.AssertionarrayClass, className, error, error
- 
Constructor Details- 
FluentObjectAssertionConstructor.- Parameters:
- value- The object being tested.
 Can be- null .
- returns- The object to return after a test method is called.
 If- null , the test method returns this object allowing multiple test method calls to be used on the same assertion.
 
- 
FluentObjectAssertionChained 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 be- null if this is the top-level assertion.
- value- The object being tested.
 Can be- null .
- returns- The object to return after a test method is called.
 If- null , the test method returns this object allowing multiple test method calls to be used on the same assertion.
 
 
- 
- 
Method Details- 
asStringConverts this object to a string usingObject.toString()and returns it as a new assertion.Example:// Validates that the specified object is "foobar" after converting to a string. assertObject (myPojo ) .asString() .is("foobar" );- Returns:
- A new fluent string assertion.
 
- 
asStringConverts this object to text using the specified serializer and returns it as a new assertion.Example:// Validates that the specified object is an instance of MyBean. assertObject (myPojo ) .asString(XmlSerializer.DEFAULT ) .is("<object><foo>bar</foo><baz>qux</baz></object>" );- Parameters:
- ws- The serializer to use to convert the object to text.
- Returns:
- A new fluent string assertion.
 
- 
asStringConverts this object to a string using the specified function and returns it as a new assertion.Example:// Validates that the specified object is "foobar" after converting to a string. assertObject (myPojo ) .asString(x ->x .toString()) .is("foobar" );- Parameters:
- function- The conversion function.
- Returns:
- A new fluent string assertion.
 
- 
asJsonConverts this object to simplified JSON and returns it as a new assertion.Example:// Validates that the specified object is an instance of MyBean. assertObject (myPojo ) .asJson() .is("{foo:'bar',baz:'qux'}" );- Returns:
- A new fluent string assertion.
 
- 
asJsonSortedConverts this object to sorted simplified JSON and returns it as a new assertion.Example:// Validates that the specified object is an instance of MyBean. assertObject (myPojo ) .asJsonSorted() .is("{baz:'qux',foo:'bar'}" );- Returns:
- A new fluent string assertion.
 
- 
asTransformedApplies a transform on the inner object and returns a new inner object.- Parameters:
- function- The function to apply.
- Returns:
- This object.
 
- 
asTransformedToApplies a transform on the inner object and returns a new inner object.- Type Parameters:
- T2- The transform-to type.
- Parameters:
- function- The function to apply.
- Returns:
- This object.
 
- 
asAnyConverts this assertion into anFluentAnyAssertionso that it can be converted to other assertion types.- Returns:
- This object.
 
- 
isExistsAsserts that the object is not null.Equivalent to isNotNull().- Returns:
- The fluent return object.
- Throws:
- AssertionError- If assertion failed.
 
- 
isNullAsserts that the object i null.Equivalent to isNotNull().- Returns:
- The fluent return object.
- Throws:
- AssertionError- If assertion failed.
 
- 
isNotNullAsserts that the object is not null.Equivalent to isNotNull().- Returns:
- The fluent return object.
- Throws:
- AssertionError- If assertion failed.
 
- 
isAsserts that the value equals the specified value.- Parameters:
- value- The value to check against.
- Returns:
- The fluent return object.
- Throws:
- AssertionError- If assertion failed.
 
- 
isStringAsserts that the value converted to a string equals the specified value.- Parameters:
- value- The value to check against.
- Returns:
- The fluent return object.
- Throws:
- AssertionError- If assertion failed.
 
- 
isNotAsserts that the value does not equal the specified value.- Parameters:
- value- The value to check against.
- Returns:
- The fluent return object.
- Throws:
- AssertionError- If assertion failed.
 
- 
isAnyAsserts that the value is one of the specified values.- Parameters:
- values- The values to check against.
- Returns:
- The fluent return object.
- Throws:
- AssertionError- If assertion failed.
 
- 
isNotAnyAsserts that the value is not one of the specified values.- Parameters:
- values- The values to check against.
- Returns:
- The fluent return object.
- Throws:
- AssertionError- If assertion failed.
 
- 
isSameAsserts that the specified object is the same object as this object.- Parameters:
- value- The value to check against.
- Returns:
- The fluent return object.
- Throws:
- AssertionError- If assertion failed.
 
- 
isSameJsonAsVerifies that two objects are equivalent after converting them both to JSON.- Parameters:
- o- The object to compare against.
- Returns:
- The fluent return object.
- Throws:
- AssertionError- If assertion failed.
 
- 
isSameSortedJsonAsVerifies that two objects are equivalent after converting them both to sorted JSON.Properties, maps, and collections are all sorted on both objects before comparison. - Parameters:
- o- The object to compare against.
- Returns:
- The fluent return object.
- Throws:
- AssertionError- If assertion failed.
 
- 
isSameSerializedAsAsserts that the specified object is the same as this object after converting both to strings using the specified serializer.- Parameters:
- o- The object to compare against.
- serializer- The serializer to use to serialize this object.
- Returns:
- The fluent return object.
- Throws:
- AssertionError- If assertion failed.
 
- 
isTypeAsserts that the object is an instance of the specified class.Example:// Validates that the specified object is an instance of MyBean. assertObject (myPojo ).isType(MyBean.class );- Parameters:
- parent- The value to check against.
- Returns:
- The fluent return object.
- Throws:
- AssertionError- If assertion failed.
 
- 
isExactTypeAsserts that the object is an instance of the specified class.Example:// Validates that the specified object is an instance of MyBean. assertObject (myPojo ).isExactType(MyBean.class );- Parameters:
- type- The value to check against.
- Returns:
- The fluent return object.
- Throws:
- AssertionError- If assertion failed.
 
- 
isAsserts that the value passes the specified predicate test.- Parameters:
- test- The predicate to use to test the value.
- Returns:
- The fluent return object.
- Throws:
- AssertionError- If assertion failed.
 
- 
isJsonConverts this object to simplified JSON and runs theFluentStringAssertion.is(String)on the result.Example:// Validates that the specified object is an instance of MyBean. assertObject (myPojo ) .asJson() .is("{foo:'bar',baz:'qux'}" );- Parameters:
- value- The expected string value.
- Returns:
- The fluent return object.
 
- 
setMsgDescription copied from class:AssertionAllows 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:
- setMsgin class- FluentAssertion<R>
- Parameters:
- msg- The assertion failure message.
- args- Optional message arguments.
- Returns:
- This object.
 
- 
setOutDescription copied from class:AssertionIf an error occurs, send the error message to the specified stream instead of STDERR.- Overrides:
- setOutin class- FluentAssertion<R>
- Parameters:
- value- The output stream. Can be- null to suppress output.
- Returns:
- This object.
 
- 
setSilentDescription copied from class:AssertionSuppresses output to STDERR.This is the equivalent to calling out( .null )- Overrides:
- setSilentin class- FluentAssertion<R>
- Returns:
- This object.
 
- 
setStdOutDescription copied from class:AssertionIf an error occurs, send the error message to STDOUT instead of STDERR.- Overrides:
- setStdOutin class- FluentAssertion<R>
- Returns:
- This object.
 
- 
setThrowableDescription copied from class:AssertionIf 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 RuntimeExceptionis 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:
- setThrowablein class- FluentAssertion<R>
- Parameters:
- value- The new value for this setting.
- Returns:
- This object.
 
- 
valueReturns the inner value after asserting it is notnull .- Returns:
- The inner value.
- Throws:
- AssertionError- If inner value was- null .
 
- 
valueAsStringReturns the inner value as a string.- Returns:
- The inner value as a string, or null if the value was null.
 
- 
orElseReturns the inner value or the other value if the value isnull .- Parameters:
- other- The other value.
- Returns:
- The inner value.
 
- 
valueIsNullReturnstrue if the inner value is null.- Returns:
- true if the inner value is null.
 
- 
valueIsNotNullReturnstrue if the inner value is not null.- Returns:
- true if the inner value is not null.
 
- 
optReturns the value wrapped in anOptional.- Returns:
- The value wrapped in an Optional.
 
- 
mapReturns the result of running the specified function against the value and returns the result.- Type Parameters:
- T2- The mapper-to type.
- Parameters:
- mapper- The function to run against the value.
- Returns:
- The result, never null .
 
- 
getFailureMessageReturns the predicate failure message.If the predicate extends from AssertionPredicate, then the message comes fromAssertionPredicate.getFailureMessage(). Otherwise, returns a generic"Unexpected value: x" message.- Parameters:
- p- The function to run against the value.
- value- The value that failed the test.
- Returns:
- The result, never null .
 
- 
equalsChecks two objects for equality.- Parameters:
- o1- The first object.
- o2- The second object.
- Returns:
- true if the objects are equal.
 
- 
toStringReturns the string form of the inner object. Subclasses can override this method to affect theasString()method (and related).
 
-