public final class BeanLikeTester extends Object
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.
Modifier and Type | Class and Description |
---|---|
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 and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
void |
testBeanLike(BeanLikeTester.PropertiesAndValues propsWithDefaultValue,
BeanLikeTester.PropertiesAndValues propsWithOtherValue)
|
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.
|
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)
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)
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.Copyright © 2014. All Rights Reserved.