Class SerializableTester
- java.lang.Object
-
- com.google.common.testing.SerializableTester
-
@GwtCompatible public final class SerializableTester extends Object
Tests serialization and deserialization of an object, optionally asserting that the resulting object is equal to the original.GWT warning: Under GWT, both methods simply returns their input, as proper GWT serialization tests require more setup. This no-op behavior allows test authors to intersperse
SerializableTester
calls with other, GWT-compatible tests.- Since:
- 10.0
- Author:
- Mike Bostock
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> T
reserialize(T object)
Serializes and deserializes the specified object.static <T> T
reserializeAndAssert(T object)
Serializes and deserializes the specified object and verifies that the re-serialized object is equal to the provided object, that the hashcodes are identical, and that the class of the re-serialized object is identical to that of the original.
-
-
-
Method Detail
-
reserialize
public static <T> T reserialize(T object)
Serializes and deserializes the specified object.GWT warning: Under GWT, this method simply returns its input, as proper GWT serialization tests require more setup. This no-op behavior allows test authors to intersperse
SerializableTester
calls with other, GWT-compatible tests.Note that the specified object may not be known by the compiler to be a
Serializable
instance, and is thus declared anObject
. For example, it might be declared as aList
.- Returns:
- the re-serialized object
- Throws:
RuntimeException
- if the specified object was not successfully serialized or deserialized
-
reserializeAndAssert
public static <T> T reserializeAndAssert(T object)
Serializes and deserializes the specified object and verifies that the re-serialized object is equal to the provided object, that the hashcodes are identical, and that the class of the re-serialized object is identical to that of the original.GWT warning: Under GWT, this method simply returns its input, as proper GWT serialization tests require more setup. This no-op behavior allows test authors to intersperse
SerializableTester
calls with other, GWT-compatible tests.Note that the specified object may not be known by the compiler to be a
Serializable
instance, and is thus declared anObject
. For example, it might be declared as aList
.Note also that serialization is not in general required to return an object that is equal to the original, nor is it required to return even an object of the same class. For example, if sublists of
MyList
instances were serializable, those sublists might implement a privateMySubList
type but serialize as a plainMyList
to save space. So long asMyList
has all the public supertypes ofMySubList
, this is safe. For these cases, for whichreserializeAndAssert
is too strict, usereserialize(T)
.- Returns:
- the re-serialized object
- Throws:
RuntimeException
- if the specified object was not successfully serialized or deserializedjunit.framework.AssertionFailedError
- if the re-serialized object is not equal to the original object, or if the hashcodes are different.
-
-