|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.outsideMyBox.testUtils.BeanLikeTester
public final class BeanLikeTester
This class provides methods to easily and quickly test and improve the test coverage of 'bean like' objects (i.e. objects with setters and getters but that not necessarily implement the Serializable interface and can have non default constructors). The beanLike objects:
All the initial values, setters, getters, non default constructors, hashCode(), equals(), toString() can be automatic tested from a map of default and non default property/value.
| Nested Class Summary | |
|---|---|
static class |
BeanLikeTester.ConstructorSignatureAndPropertiesMapping
Convenient class to define a list of constructor signatures with their corresponding property name. |
static class |
BeanLikeTester.PropertiesAndValues
Convenient class to define a list of property names with their corresponding value. |
| Constructor Summary | |
|---|---|
BeanLikeTester(Class<?> beanClass)
Create a BeanLikeTester with a specific bean to test. |
|
BeanLikeTester(Class<?> beanLikeClass,
BeanLikeTester.ConstructorSignatureAndPropertiesMapping constructorsSignaturesAndProperties)
Create a BeanLikeTester with a specific beanLike to test. |
|
| Method Summary | |
|---|---|
void |
testBeanLike(BeanLikeTester.PropertiesAndValues propsWithDefaultValue,
BeanLikeTester.PropertiesAndValues propsWithOtherValue)
Run all the tests: testDefaultValues(PropertiesAndValues)
testMutatorsAndAccessors(PropertiesAndValues, PropertiesAndValues)
testEqualsAndHash(PropertiesAndValues, PropertiesAndValues)
testToString(PropertiesAndValues, PropertiesAndValues)
|
void |
testDefaultValues(BeanLikeTester.PropertiesAndValues expectedDefaultValues)
Test that the default value of the properties (returned by the accessors) are the same as the one defined by the parameter. The properties are also tested for objects created with all the possible constructors. |
void |
testEqualsAndHash(BeanLikeTester.PropertiesAndValues propsWithDefaultValue,
BeanLikeTester.PropertiesAndValues propsWithOtherValue)
Test that equals() and hashCode() take into account all the properties and return the correct values. |
void |
testMutatorsAndAccessors(BeanLikeTester.PropertiesAndValues propsWithValue,
BeanLikeTester.PropertiesAndValues otherPropsWithValue)
Test that all the mutators (setters, and constructors with arguments) can change their property and that the accessors reflect the change. |
void |
testToString(BeanLikeTester.PropertiesAndValues propsWithDefaultValue,
BeanLikeTester.PropertiesAndValues propsWithOtherValue)
Test that the method toString() returns a different String if one of the settable properties has changed. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public BeanLikeTester(Class<?> beanLikeClass,
BeanLikeTester.ConstructorSignatureAndPropertiesMapping constructorsSignaturesAndProperties)
beanLikeClass - The 'beanLike' to test.constructorsSignaturesAndProperties - The signature of all the possible constructors
(The parameters of the constructors must only set properties).BeanLikeTesterException - if at least one of the signatures doesn't correspond to a constructor or
the constructors doesn't only define properties or setters or accessors are invalid.public BeanLikeTester(Class<?> beanClass)
beanClass - The bean class to test.
BeanLikeTesterException - See BeanLikeTester(Class, ConstructorSignatureAndPropertiesMapping)| Method Detail |
|---|
public void testDefaultValues(BeanLikeTester.PropertiesAndValues expectedDefaultValues)
expectedDefaultValues - Property names and their expected default value.
BeanLikeTesterException - if the test fails.
public void testMutatorsAndAccessors(BeanLikeTester.PropertiesAndValues propsWithValue,
BeanLikeTester.PropertiesAndValues otherPropsWithValue)
propsWithValue - Property names (keys) and their value.otherPropsWithValue - Property names (keys) and their value different from 'propsWithValue'.
It must at least contain all the settable properties.
BeanLikeTesterException - if the test fails.
public void testEqualsAndHash(BeanLikeTester.PropertiesAndValues propsWithDefaultValue,
BeanLikeTester.PropertiesAndValues propsWithOtherValue)
propsWithDefaultValue - Property names (keys) and their value.propsWithOtherValue - Property names (keys) and their value different from 'propsWithValue'.
It must at least contain all the settable properties.
BeanLikeTesterException - if the test fails.
public void testToString(BeanLikeTester.PropertiesAndValues propsWithDefaultValue,
BeanLikeTester.PropertiesAndValues propsWithOtherValue)
propsWithDefaultValue - Property names (keys) and their value.propsWithOtherValue - Property names (keys) and their value different from 'propsWithDefaultValue'.
It must at least contain all the settable properties.
BeanLikeTesterException - if the test fails.
public void testBeanLike(BeanLikeTester.PropertiesAndValues propsWithDefaultValue,
BeanLikeTester.PropertiesAndValues propsWithOtherValue)
testDefaultValues(PropertiesAndValues)testMutatorsAndAccessors(PropertiesAndValues, PropertiesAndValues)testEqualsAndHash(PropertiesAndValues, PropertiesAndValues)testToString(PropertiesAndValues, PropertiesAndValues)
propsWithDefaultValue - Property names (keys) and their value.propsWithOtherValue - Property names (keys) and their value different from 'propsWithValue'.
It must at least contain all the settable properties.
BeanLikeTesterException - if the test fails.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||