patterntesting.runtime.junit
Class SerializableTester

Package class diagram package SerializableTester
java.lang.Object
  extended by patterntesting.runtime.junit.SerializableTester

public final class SerializableTester
extends Object

This is a utility class to check the serializable nature of classes.
NOTE: In the future this class will be perhaps part of the ObjectTester class.
Before v1.1 the methods are named "checkSerialization". Since 1.1 these methods will have now an "assert" prefix ("assertSerialization").

Since:
1.0.3 (21.07.2010)
Author:
oliver (oliver.boehm@agentes.de)

Method Summary
static void assertSerialization(Class<? extends Serializable> clazz)
          This method will create an object of the given class using the default constructor.
static void assertSerialization(Collection<Class<Serializable>> classes)
          Check for each class in the given collection if it can be serialized and deserialized.
static void assertSerialization(Package pkg)
          Check for each class in the given package if it can be serialized and deserialized.
static void assertSerialization(Serializable object)
          Check serialization and deserialization of an object.
static void assertSerializationOfPackage(String packageName)
          Check for each class in the given package if it can be serialized and deserialized.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

assertSerialization

public static void assertSerialization(Serializable object)
                                throws NotSerializableException
Check serialization and deserialization of an object. Because not all classes has a (correct) overwritten equals method we do not compare the deserialized object with the equals() method. But if it implements Comparable we verify the equality of the two objects with the compareTo() method.

Parameters:
object - the object
Throws:
NotSerializableException - if object can't serialized
Since:
1.1

assertSerialization

public static void assertSerialization(Class<? extends Serializable> clazz)
                                throws NotSerializableException
This method will create an object of the given class using the default constructor. So three preconditions must be true:
  1. the class must not be abstract
  2. there must be a (public) default constructor
  3. it must be Serializable

Parameters:
clazz - the clazz
Throws:
NotSerializableException - if the check fails
Since:
1.1

assertSerialization

public static void assertSerialization(Collection<Class<Serializable>> classes)
                                throws NotSerializableException
Check for each class in the given collection if it can be serialized and deserialized.

Parameters:
classes - a collection of classes to be checked
Throws:
NotSerializableException - if one of the classes can't be serialized
Since:
1.1

assertSerialization

public static void assertSerialization(Package pkg)
                                throws NotSerializableException
Check for each class in the given package if it can be serialized and deserialized.
To get a name of a package call Package.getPackage(String). But be sure that you can't get null as result. In this case use assertSerializationOfPackage(String).

Parameters:
pkg - the package e.g. "patterntesting.runtime"
Throws:
NotSerializableException - if one of the class can't be serialized
Since:
1.1
See Also:
assertSerializationOfPackage(String)

assertSerializationOfPackage

public static void assertSerializationOfPackage(String packageName)
                                         throws NotSerializableException
Check for each class in the given package if it can be serialized and deserialized.

Parameters:
packageName - the package name e.g. "patterntesting.runtime"
Throws:
NotSerializableException - if one of the class can't be serialized
Since:
1.1


Copyright © 2002–2014 PatternTesting Team. All rights reserved.