|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectnl.ivonet.beanunit.Asserter
nl.ivonet.beanunit.SimplePojoContractAsserter
public final class SimplePojoContractAsserter
Test utility class that makes easy work of testing default behavior pojos (beans).
The assertBasicGetterSetterBehavior methods will try to assert that the normal Bean (POJO) specifications and rules are upheld. Getters should exactly return what setters set. Write methods should have read methods and vice versa. The assertEqualsHashCode method will try to assert that the rules around these methods are upheld. If equals has been overridden the hashCode method must also be overridden and vise versa. If an object is equal the hashcode must also be the same for both objects, etc.
| Method Summary | ||
|---|---|---|
static
|
assertBasicGetterSetterBehavior(java.lang.Class<T> classUnderTest)
|
|
static
|
assertBasicGetterSetterBehavior(java.lang.Class<T> classUnderTest,
java.util.Map<java.lang.String,java.lang.Object> properties)
|
|
static
|
assertBasicGetterSetterBehavior(java.lang.Class<T> classUnderTest,
java.lang.String property)
Tests that the getter and setter methods for property work in a basic fashion, which is that the
getter returns the exact same object as set by the setter method. |
|
static
|
assertBasicGetterSetterBehavior(java.lang.Class<T> classUnderTest,
java.lang.String property,
java.lang.Object argument)
The method that does the actual assertion work. |
|
static
|
assertBasicGetterSetterBehaviorWithBlacklist(java.lang.Class<T> classUnderTest,
java.lang.String... propertyNames)
|
|
static
|
assertEqualsHashCode(java.lang.Class<T> classUnderTest,
java.lang.String... excludedProperties)
Tests all the flows of the overridden equals and hashCode methods of a class. |
|
| Methods inherited from class nl.ivonet.beanunit.Asserter |
|---|
deregisterType, registerTypeAndDefaultArgument, resetToDefaultTypes |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static <T> void assertBasicGetterSetterBehavior(java.lang.Class<T> classUnderTest,
java.lang.String property)
property work in a basic fashion, which is that the
getter returns the exact same object as set by the setter method.
FindBugz says this is not correct but I don't see the bad in it :-)
Uses a default argument for basic collection types, primitive types, Dates, java.sql.Dates, and Timestamps.
See Asserter.TYPE_ARGUMENTS.
classUnderTest - the object on which to invoke the getter and setterproperty - the property name, e.g. "firstName"
public static <T> void assertBasicGetterSetterBehavior(java.lang.Class<T> classUnderTest,
java.lang.String property,
java.lang.Object argument)
classUnderTest - the object on which to invoke the getter and setterproperty - the property name, e.g. "firstName"argument - the property value, i.e. the value the setter will be invoked with
public static <T> void assertBasicGetterSetterBehavior(java.lang.Class<T> classUnderTest,
java.util.Map<java.lang.String,java.lang.Object> properties)
classUnderTest - the object on which to invoke the getter and setterproperties - map of property names to argument valuesSimplePojoContractAsserter#assertBasicGetterSetterBehavior(Class, String, Object)} method. Only difference is that here we accept a map
containing property name/value pairs. Use this to test a bunch of property accessors at once. Note that the
values in the map can be null, and in that case we'll try to supply a default argument.public static <T> void assertBasicGetterSetterBehavior(java.lang.Class<T> classUnderTest)
classUnderTest - the object on which to invoke the getter and setterSimplePojoContractAsserter#assertBasicGetterSetterBehavior(Class, String, Object)} method. No items are blacklisted.
public static <T> void assertBasicGetterSetterBehaviorWithBlacklist(java.lang.Class<T> classUnderTest,
java.lang.String... propertyNames)
classUnderTest - the object on which to invoke the getter and setterpropertyNames - the list of property names that should not be testedSimplePojoContractAsserter#assertBasicGetterSetterBehavior(Class, String, Object)} method. Big difference here is that we try to
automatically introspect the target object, finding read/write properties, and automatically testing the getter
and setter. Note specifically that read-only properties are ignored, as there is no way for us to know how to set
the value (since there isn't a public setter).
Any property names contained in the blacklist will be skipped.
public static <T> void assertEqualsHashCode(java.lang.Class<T> classUnderTest,
java.lang.String... excludedProperties)
T - the type of the class to testclassUnderTest - the implementation.classexcludedProperties - string representation of all the properties excluded from the equals test , e.g. "firstName"
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||