patterntesting.runtime.junit
Class CloneableTester

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

public final class CloneableTester
extends Object

This tester checks class which implements Clonable and has therefore the clone method implemented. According Object.clone() the following conditions should be true:

 x.clone() != x
will be true, and that the expression:
 x.clone().getClass() == x.getClass()
will be true, but these are not absolute requirements. While it is typically the case that:
 x.clone().equals(x)
will be true, this is not an absolute requirement.

So the equals method will be only checked if it is overwritten.
NOTE: In the future this class will be perhaps part of the ObjectTester class.
Before v1.1 the methods are named "checkCloning". Since 1.1 these methods will have now an "assert" prefix ("assertCloning").

Since:
1.0.2 (06.08.2010)
Author:
oliver

Method Summary
static void assertCloning(Class<? extends Cloneable> clazz)
          Check cloning.
static void assertCloning(Cloneable orig)
          We call the clone method of the given orig paramter.Because the clone method is normally "protected" we use reflection to call it.
static void assertCloning(Collection<Class<Cloneable>> classes)
          Check for each class in the given collection if it can be cloned correct.
static void assertCloning(Package pkg)
          Check for each class in the given package if it can be cloned correct.
static void assertCloningOfPackage(String packageName)
          Check for each class in the given package if it can be cloned correct.
static void assertCloningOfPackage(String packageName, Class<? extends Cloneable>... excluded)
          Check for each class in the given package if the clone method is implemented correct.
static void assertCloningOfPackage(String packageName, List<Class<Cloneable>> excluded)
          Check for each class in the given package if the clone method is implemented correct.
static Cloneable getCloneOf(Cloneable orig)
          Gets the clone of the given Cloneable object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

assertCloning

public static void assertCloning(Class<? extends Cloneable> clazz)
Check cloning.

Parameters:
clazz - the clazz
Since:
1.1

assertCloning

public static void assertCloning(Cloneable orig)
We call the clone method of the given orig paramter.Because the clone method is normally "protected" we use reflection to call it. Then we compare the orig and cloned object which should be equals.

Parameters:
orig - the original object
Since:
1.1

getCloneOf

public static Cloneable getCloneOf(Cloneable orig)
                            throws AssertionError
Gets the clone of the given Cloneable object.

Parameters:
orig - the orig
Returns:
the clone of
Throws:
AssertionError - the assertion error

assertCloning

public static void assertCloning(Collection<Class<Cloneable>> classes)
Check for each class in the given collection if it can be cloned correct.

Parameters:
classes - a collection of classes to be checked
Since:
1.1

assertCloning

public static void assertCloning(Package pkg)
Check for each class in the given package if it can be cloned correct.
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 assertCloningOfPackage(String).

Parameters:
pkg - the package e.g. "patterntesting.runtime"
Since:
1.1
See Also:
assertCloningOfPackage(String)

assertCloningOfPackage

public static void assertCloningOfPackage(String packageName)
Check for each class in the given package if it can be cloned correct.

Parameters:
packageName - the package name e.g. "patterntesting.runtime"
Since:
1.1

assertCloningOfPackage

public static void assertCloningOfPackage(String packageName,
                                          Class<? extends Cloneable>... excluded)
Check for each class in the given package if the clone method is implemented correct.

Parameters:
packageName - the package name e.g. "patterntesting.runtime"
excluded - classes which should be excluded from the check
Since:
1.1
See Also:
assertCloningOfPackage(String)

assertCloningOfPackage

public static void assertCloningOfPackage(String packageName,
                                          List<Class<Cloneable>> excluded)
Check for each class in the given package if the clone method is implemented correct.

Parameters:
packageName - the package name e.g. "patterntesting.runtime"
excluded - classes which should be excluded from the check
Since:
1.1
See Also:
assertCloningOfPackage(String)


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