|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||

java.lang.Objectpatterntesting.runtime.junit.ObjectTester
public final class ObjectTester
This is a utility class to check some important methods of a class like the.
Object.equals(Object) or Object.hashCode() method.
Before v1.1 the methods are named "checkEquals" or "checkCompareTo".
Since 1.1 these methods will have now an "assert" prefix ("assertEquals"
or "assertCompareTo").
| Method Summary | |
|---|---|
static void |
assertAll(Class<?> clazz)
Starts all known checks like checkEquals(..), checks from the SerializableTester (if the given class is serializable) or from other classes. |
static void |
assertAll(Collection<Class<?>> classes)
Check all. |
static void |
assertAll(Package pkg)
Starts all known checks for all classes of the given package. |
static void |
assertAll(Package pkg,
Class<?>... excluded)
Starts all known checks for all classes of the given package except for the "excluded" classes. |
static void |
assertAllOfPackage(String packageName)
Starts all known checks for all classes of the given package. |
static void |
assertAllOfPackage(String packageName,
Class<?>... excluded)
Starts all known checks for all classes of the given package but not for the "excluded" classes. |
static void |
assertAllOfPackage(String packageName,
List<Class<?>> excluded)
Starts all known checks for all classes of the given package but not for the "excluded" classes. |
static void |
assertCompareTo(Object o1,
Object o2)
Check equality of the given objects by using the compareTo() method. |
static void |
assertEquals(Class<?> clazz)
This method will create two objects of the given class using the default constructor. |
static void |
assertEquals(Cloneable obj)
The given object will be cloned to get a copy of that object. |
static void |
assertEquals(Collection<Class<?>> classes)
Check for each class in the given collection if the equals() method is implemented correct. |
static void |
assertEquals(Object o1,
Object o2)
Check equality of the given objects. |
static void |
assertEquals(Package pkg)
Check for each class in the given package if the equals() method is implemented correct. |
static void |
assertEquals(Package pkg,
Class<?>... excluded)
Check for each class in the given package if the equals() method is implemented correct. |
static void |
assertEquals(Serializable obj)
The given object will be serialized and deserialized to get a copy of that object. |
static void |
assertEqualsOfPackage(Package pkg,
List<Class<?>> excluded)
Check for each class in the given package if the equals() method is implemented correct. |
static void |
assertEqualsOfPackage(String packageName)
Check for each class in the given package if the equals() method is implemented correct. |
static void |
assertEqualsOfPackage(String packageName,
Class<?>... excluded)
Check for each class in the given package if the equals() method is implemented correct. |
static void |
assertEqualsOfPackage(String packageName,
List<Class<?>> excluded)
Check for each class in the given package if the equals() method is implemented correct. |
static void |
assertEqualsWithClone(Class<?> clazz)
This method will create two objects of the given class by trying to clone them in different ways. |
static void |
assertToString(Object obj)
If a object is only partially initalized it sometimes can happen, that calling the toString() method will result in a NullPointerException. |
static boolean |
hasEqualsDeclared(Class<?> clazz)
If you want to know if a class (or one of its super classes, except object) has overwritten the equals method you can use this method here. |
static boolean |
hasToStringDefaultImpl(Class<?> clazz)
Normally you should overwrite the toString() method for better logging and debugging. |
static boolean |
hasToStringDefaultImpl(Object obj)
Normally you should overwrite the toString() method for better logging and debugging. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static void assertEquals(Object o1,
Object o2)
throws AssertionError
If two objects are equals they must have also the same hash code (but not the other way around). This condition is also checked here.
Often programmers forget that the Object.equals(Object) method
can be called with null as argument and should return
false as result. So this case is also tested here.
o1 - the 1st objecto2 - the 2nd object
AssertionError - if the check fails
public static void assertEquals(Serializable obj)
throws AssertionError,
NotSerializableException
obj - the object
AssertionError - if the check fails
NotSerializableException - if obj is not serializable
public static void assertEquals(Cloneable obj)
throws AssertionError
obj - the obj
AssertionError - the assertion error
public static void assertEquals(Class<?> clazz)
throws AssertionError
clazz - the clazz
AssertionError - if the check fails
public static void assertEqualsWithClone(Class<?> clazz)
throws AssertionError
clazz - the clazz
AssertionError - if the check fails
public static void assertEquals(Collection<Class<?>> classes)
throws Failures
classes - the classes
Failures - the collected assertion errorspublic static void assertEquals(Package pkg)
Package.getPackage(String).
But be sure that you can't get null as result. In this case
use assertEqualsOfPackage(String).
pkg - the package e.g. "patterntesting.runtime"assertEqualsOfPackage(String)
public static void assertEquals(Package pkg,
Class<?>... excluded)
Package.getPackage(String).
But be sure that you can't get null as result. In this case
use assertEqualsOfPackage(String, Class...).
pkg - the package e.g. "patterntesting.runtime"excluded - classes which are excluded from the checkassertEqualsOfPackage(String, Class...)
public static void assertEqualsOfPackage(Package pkg,
List<Class<?>> excluded)
Package.getPackage(String).
But be sure that you can't get null as result. In this case
use assertEqualsOfPackage(String, List).
pkg - the package e.g. "patterntesting.runtime"excluded - classes which should be excluded from the checkassertEqualsOfPackage(String, List)public static void assertEqualsOfPackage(String packageName)
assertEquals(Package) but was
introduced by Package.getPackage(String) sometimes return null
if no class of this package is loaded.
packageName - the package name e.g. "patterntesting.runtime"assertEquals(Package)
public static void assertEqualsOfPackage(String packageName,
Class<?>... excluded)
packageName - the package name e.g. "patterntesting.runtime"excluded - classes which should be excluded from the checkassertEqualsOfPackage(String)
public static void assertEqualsOfPackage(String packageName,
List<Class<?>> excluded)
packageName - the package name e.g. "patterntesting.runtime"excluded - classes which should be excluded from the checkassertEqualsOfPackage(String)public static boolean hasEqualsDeclared(Class<?> clazz)
clazz - the clazz
public static void assertCompareTo(Object o1,
Object o2)
throws AssertionError
o1 - the first object (must be of type Comparable)o2 - the second object (must be of type Comparable)
AssertionError - if the check failsComparableTester.assertCompareTo(Comparable, Comparable)public static void assertToString(Object obj)
obj - the object to be checkedpublic static boolean hasToStringDefaultImpl(Object obj)
obj - the object to be checked
public static boolean hasToStringDefaultImpl(Class<?> clazz)
clazz - the clazz
public static void assertAll(Class<?> clazz)
clazz - the clazz to be checked.public static void assertAll(Collection<Class<?>> classes)
classes - the classes to be checkedpublic static void assertAll(Package pkg)
Package.getPackage(String).
But be sure that you can't get null as result. In this case
use assertAllOfPackage(String).
pkg - the package e.g. "patterntesting.runtime"
public static void assertAll(Package pkg,
Class<?>... excluded)
Package.getPackage(String).
But be sure that you can't get null as result. In this case
use assertEqualsOfPackage(String, Class...).
pkg - the package e.g. "patterntesting.runtime"excluded - classes which are excluded from the checkassertAllOfPackage(String, Class...)public static void assertAllOfPackage(String packageName)
packageName - the package e.g. "patterntesting.runtime"
public static void assertAllOfPackage(String packageName,
Class<?>... excluded)
packageName - the package name e.g. "patterntesting.runtime"excluded - classes which should be excluded from the checkassertAllOfPackage(String)
public static void assertAllOfPackage(String packageName,
List<Class<?>> excluded)
packageName - the package name e.g. "patterntesting.runtime"excluded - classes which should be excluded from the checkassertEqualsOfPackage(String)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||