Class ValueWrapper
- java.lang.Object
-
- org.opentest4j.ValueWrapper
-
- All Implemented Interfaces:
java.io.Serializable
public final class ValueWrapper extends java.lang.Object implements java.io.SerializableSerializable 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 viaString.valueOf(Object). If the invocation ofString.valueOf(Object)throws anException, 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.- Since:
- 1.0
- See Also:
System.identityHashCode(java.lang.Object), Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.ObjectephemeralValueprivate intidentityHashCodeprivate static ValueWrappernullValueWrapperprivate static longserialVersionUIDprivate java.lang.StringstringRepresentationprivate java.lang.Class<?>typeprivate java.io.Serializablevalue
-
Constructor Summary
Constructors Modifier Constructor Description privateValueWrapper(java.lang.Object value)privateValueWrapper(java.lang.Object value, java.lang.String stringRepresentation)Reads and stores the supplied value's runtime type, string representation, and identity hash code.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ValueWrappercreate(java.lang.Object value)Factory for creating a newValueWrapperfor the suppliedvalue.static ValueWrappercreate(java.lang.Object value, java.lang.String stringRepresentation)Factory for creating a newValueWrapperfor the suppliedvalueusing the supplied customstringRepresentation.java.lang.ObjectgetEphemeralValue()Returns the original value supplied tocreate().intgetIdentityHashCode()Returns the value's identity hash code.java.lang.StringgetStringRepresentation()Returns the value's string representation.java.lang.Class<?>getType()Returns the value's runtime type ornullif the value isnull.java.io.SerializablegetValue()private static java.lang.StringsafeValueToString(java.lang.Object value)java.lang.StringtoString()Returns the value's string representation along with its type and identity hash code.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
nullValueWrapper
private static final ValueWrapper nullValueWrapper
-
value
private final java.io.Serializable value
-
type
private final java.lang.Class<?> type
-
stringRepresentation
private final java.lang.String stringRepresentation
-
identityHashCode
private final int identityHashCode
-
ephemeralValue
private final transient java.lang.Object ephemeralValue
-
-
Method Detail
-
create
public static ValueWrapper create(java.lang.Object value)
Factory for creating a newValueWrapperfor the suppliedvalue.If the supplied
valueisnull, this method will return a cachedValueWrappersuitable for allnullvalues. If the suppliedvalueis already an instance ofValueWrapper, it will be returned as is.- Parameters:
value- the value to wrap; may benull- Returns:
- a wrapper for the supplied value; never
null
-
create
public static ValueWrapper create(java.lang.Object value, java.lang.String stringRepresentation)
Factory for creating a newValueWrapperfor the suppliedvalueusing the supplied customstringRepresentation.You should use this method when you don't want to rely on the result of the value's
toString()method.If the supplied
valueisnull, this method will return a cachedValueWrappersuitable for allnullvalues. If the suppliedvalueis already an instance ofValueWrapper, it will be returned as is if thestringRepresentationmatch, otherwise the original value will be unwrapped and a newValueWrapperwith the newstringRepresentationwill be created.- Parameters:
value- the value to wrap; may benullstringRepresentation- a custom rendering of the value; will fallback to the default behavior ifnull- Returns:
- a wrapper for the supplied value; never
null - Since:
- 1.2
-
safeValueToString
private static java.lang.String safeValueToString(java.lang.Object value)
-
getValue
public java.io.Serializable getValue()
- See Also:
getEphemeralValue()
-
getType
public java.lang.Class<?> getType()
Returns the value's runtime type ornullif the value isnull.
-
getStringRepresentation
public java.lang.String getStringRepresentation()
Returns the value's string representation.The string representation is generated by invoking
String.valueOf(value)for the value supplied tocreate(Object).- See Also:
getValue()
-
getIdentityHashCode
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 tocreate(Object).- See Also:
getValue()
-
getEphemeralValue
public java.lang.Object getEphemeralValue()
Returns the original value supplied tocreate().If this
ValueWrapperwas created by deserialization this method returnsnull.- Since:
- 1.2
- See Also:
getValue()
-
toString
public java.lang.String toString()
Returns the value's string representation along with its type and identity hash code.- Overrides:
toStringin classjava.lang.Object
-
-