|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object de.smartics.util.test.io.SerialTestUtils
public final class SerialTestUtils
Provides utility functions to help on tests dealing with serialization.
The example shows the typical usage of runSerialization(Object)
:
Example Usage Error
final MyClass uut = new MyClass(); ... SerialTestUtils.runSerialization(uut); assertTrue("Serialization successful.", true);
If the serialization is not successful, an exception is thrown. If you do not want an error to be reported by JUnit you have catch the exception and fail.
Example Usage Failure
final MyClass uut = new MyClass(); ... SerialTestUtils.runSerializationQuietly(uut); assertTrue("Serialization successful.", true);
Method Summary | ||
---|---|---|
static
|
readObject(byte[] data) Reads the object from the given byte array. |
|
static
|
runSerialization(T uut) Test the serialization and deserialization of the unit under test. |
|
static
|
runSerializationQuietly(T uut) Runs the serialization test and signals a fail to the JUnit runtime. |
|
static
|
writeObject(T uut) Writes the given object to an byte array. |
|
static
|
writeObject(T uut, int bufferSize) Writes the given object to an byte array. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static <T> T runSerializationQuietly(T uut)
T
- the type of the instance to read and write.
uut
- the unit under test to serialize and deserialized.
public static <T> T runSerialization(T uut) throws IOException, ClassNotFoundException
T
- the type of the instance to read and write.
uut
- the unit under test to serialize and deserialized.
IOException
- if the object cannot be serialized or deserialized.
ClassNotFoundException
- if the class for the deserialized object cannot be found.
public static <T> T readObject(byte[] data) throws IOException, ClassNotFoundException
T
- the type of the instance to read.
data
- the serialized object to deserialize.
IOException
- if the object cannot be deserialized.
ClassNotFoundException
- if the class for the deserialized object cannot be found.
public static <T> byte[] writeObject(T uut, int bufferSize) throws IOException
T
- the type of the instance to write.
uut
- the unit under test to serialize.
bufferSize
- the size of the in-memory buffer to write to.
IOException
- if the object cannot be serialized.
public static <T> byte[] writeObject(T uut) throws IOException
T
- the type of the instance to write.
uut
- the unit under test to serialize.
IOException
- if the object cannot be serialized.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |