|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.google.common.testing.SerializableTester
@Beta @GwtCompatible public final class SerializableTester
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.
Method Summary | ||
---|---|---|
static
|
reserialize(T object)
Serializes and deserializes the specified object. |
|
static
|
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static <T> T reserialize(T 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 an
Object
. For example, it might be declared as a List
.
RuntimeException
- if the specified object was not successfully
serialized or deserializedpublic static <T> T reserializeAndAssert(T 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 an
Object
. For example, it might be declared as a List
.
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 private MySubList
type but serialize as a plain
MyList
to save space. So long as MyList
has all the public
supertypes of MySubList
, this is safe. For these cases, for which
reserializeAndAssert
is too strict, use reserialize(T)
.
RuntimeException
- if the specified object was not successfully
serialized or deserialized
junit.framework.AssertionFailedError
- if the re-serialized object is not equal to
the original object, or if the hashcodes are different.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |