Top Description Fields Constructors Methods
org.opentest4j

public final Class ValueWrapper

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.io.Serializable

Serializable representation of a value that was used in an assertion.

This class only stores the value if it implements Serializable. In any case, it stores its runtime type, identity hash code, and string representation determined via String#valueOf(Object). If the invocation of String.valueOf(Object) throws an Exception, the string representation will take the form of "<Exception in toString(): " + e + ">", where "e" is the caught exception.

The toString() method returns the string representation of the value along with its type and identity hash code.

Authors
Marc Philipp, Sam Brannen
Since
1.0
See Also
System#identityHashCode

Field Summary

Modifier and TypeField and Description
private final transient Object
private final int
private static final ValueWrapper
private static final long
private final String
private final Class<?>
private final Serializable

Constructor Summary

AccessConstructor and Description
private
ValueWrapper(Object value, String stringRepresentation)

Reads and stores the supplied value's runtime type, string representation, and identity hash code.

private

Method Summary

Modifier and TypeMethod and Description
public static ValueWrapper

Returns:

a wrapper for the supplied value; never null
create
(Object
the value to wrap; may be null
value
)

Factory for creating a new ValueWrapper for the supplied value.

public static ValueWrapper

Returns:

a wrapper for the supplied value; never null
create
(Object
the value to wrap; may be null
value
,
String
a custom rendering of the value; will fallback to the default behavior if null
stringRepresentation
)

Factory for creating a new ValueWrapper for the supplied value using the supplied custom stringRepresentation.

public Object
getEphemeralValue()

Returns the original value supplied to create().

public int
getIdentityHashCode()

Returns the value's identity hash code.

public String
getStringRepresentation()

Returns the value's string representation.

public Class<?>
getType()

Returns the value's runtime type or null if the value is null.

public Serializable
getValue()

Returns the value supplied to create(Object) if the value implements Serializable; otherwise, null.

private static String
public String
toString()

Overrides java.lang.Object.toString.

Returns the value's string representation along with its type and identity hash code.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

ephemeralValueback to summary
private final transient Object ephemeralValue
identityHashCodeback to summary
private final int identityHashCode
nullValueWrapperback to summary
private static final ValueWrapper nullValueWrapper
serialVersionUIDback to summary
private static final long serialVersionUID
stringRepresentationback to summary
private final String stringRepresentation
typeback to summary
private final Class<?> type
valueback to summary
private final Serializable value

Constructor Detail

ValueWrapperback to summary
private ValueWrapper(Object value, String stringRepresentation)

Reads and stores the supplied value's runtime type, string representation, and identity hash code.

ValueWrapperback to summary
private ValueWrapper(Object value)

Method Detail

createback to summary
public static ValueWrapper create(Object value)

Factory for creating a new ValueWrapper for the supplied value.

If the supplied value is null, this method will return a cached ValueWrapper suitable for all null values. If the supplied value is already an instance of ValueWrapper, it will be returned as is.

Parameters
value:Object

the value to wrap; may be null

Returns:ValueWrapper

a wrapper for the supplied value; never null

createback to summary
public static ValueWrapper create(Object value, String stringRepresentation)

Factory for creating a new ValueWrapper for the supplied value using the supplied custom stringRepresentation.

You should use this method when you don't want to rely on the result of the value's toString() method.

If the supplied value is null, this method will return a cached ValueWrapper suitable for all null values. If the supplied value is already an instance of ValueWrapper, it will be returned as is if the stringRepresentation match, otherwise the original value will be unwrapped and a new ValueWrapper with the new stringRepresentation will be created.

Parameters
value:Object

the value to wrap; may be null

stringRepresentation:String

a custom rendering of the value; will fallback to the default behavior if null

Returns:ValueWrapper

a wrapper for the supplied value; never null

Since
1.2
getEphemeralValueback to summary
public Object getEphemeralValue()

Returns the original value supplied to create().

If this ValueWrapper was created by deserialization this method returns null.

Since
1.2
See Also
getValue()
getIdentityHashCodeback to summary
public int getIdentityHashCode()

Returns the value's identity hash code.

The identity hash code is generated by invoking System.identityHashCode(value) for the value supplied to create(Object).

See Also
getValue()
getStringRepresentationback to summary
public String getStringRepresentation()

Returns the value's string representation.

The string representation is generated by invoking String.valueOf(value) for the value supplied to create(Object).

See Also
getValue()
getTypeback to summary
public Class<?> getType()

Returns the value's runtime type or null if the value is null.

getValueback to summary
public Serializable getValue()

Returns the value supplied to create(Object) if the value implements Serializable; otherwise, null.

See Also
getEphemeralValue()
safeValueToStringback to summary
private static String safeValueToString(Object value)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns the value's string representation along with its type and identity hash code.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object

Annotations
@Override