|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectuk.co.jemos.podam.api.PodamFactory
public class PodamFactory
Field Summary | |
---|---|
private static org.apache.log4j.Logger |
LOG
Application logger |
Constructor Summary | |
---|---|
PodamFactory()
|
Method Summary | ||
---|---|---|
private static Object |
createNewInstanceForClassWithoutSetters(DataProviderStrategy strategy,
Class<?> clazz)
It attempts to create an instance of the given class |
|
private static Byte |
getByteValueWithinRange(DataProviderStrategy strategy,
List<Annotation> annotations)
It returns a random byte if the attribute was annotated with PodamByteValue or null otherwise |
|
private static Character |
getCharacterValueWithinRange(DataProviderStrategy strategy,
List<Annotation> annotations)
It creates and returns a random Character value |
|
private static Double |
getDoubleValueWithinRange(DataProviderStrategy strategy,
List<Annotation> annotations)
It creates and returns a random Double value |
|
private static Float |
getFloatValueWithinRange(DataProviderStrategy strategy,
List<Annotation> annotations)
Returns either a customised float value if a PodamFloatValue
annotation was provided or a random float if this was not the case |
|
private static Integer |
getIntValueWithinRange(DataProviderStrategy strategy,
List<Annotation> annotations)
Returns either a customised int value if a PodamIntValue
annotation was provided or a random integer if this was not the case |
|
private static Long |
getLongValueWithinRange(DataProviderStrategy strategy,
List<Annotation> annotations)
Returns either a customised long value if a PodamLongValue
annotation was provided or a random long if this was not the case |
|
private static Short |
getShortValueWithinRange(DataProviderStrategy strategy,
List<Annotation> annotations)
It returns a random short if the attribute was annotated with PodamShortValue or null otherwise |
|
private static boolean |
isWrapper(Class<?> candidateWrapperClass)
It returns true if this class is a wrapper class, false
otherwise |
|
private static Object |
manufactureAttributeValue(DataProviderStrategy strategy,
Class<?> pojoClass,
Class<?> attributeType,
List<Annotation> annotations,
String attributeName)
It manufactures and returns the value for a POJO attribute. |
|
static
|
manufacturePojo(Class<T> pojoClass)
Generic method which returns an instance of the given class filled with dummy values, using the default data provider strategy. |
|
static
|
manufacturePojo(Class<T> pojoClass,
DataProviderStrategy strategy)
Generic method which returns an instance of the given class filled with dummy values |
|
private static
|
manufacturePojoInternal(DataProviderStrategy strategy,
Class<T> pojoClass,
int depth)
Generic method which returns an instance of the given class filled with dummy values |
|
private static Object |
resolveArrayElementValue(DataProviderStrategy strategy,
Class<?> attributeType,
List<Annotation> annotations,
Class<?> pojoClass,
String attributeName)
It returns an Array with the first element set |
|
private static int |
resolveCollectionNbrElementsFromAnnotations(List<Annotation> annotations)
Given a list of annotations, it scans whether there is one to customise the number of elements in a collection |
|
private static Collection<? super Object> |
resolveCollectionType(Class<?> collectionType)
Given a collection type it returns an instance |
|
private static Collection<? super Object> |
resolveCollectionValueWhenCollectionIsPojoAttribute(DataProviderStrategy strategy,
Class<?> pojoClass,
Class<?> collectionType,
String attributeName,
List<Annotation> annotations)
It returns a collection of some sort with some data in it. |
|
private static Map<? super Object,? super Object> |
resolveMapType(Class<?> attributeType)
It manufactures and returns a default instance for each map type |
|
private static Map<? super Object,? super Object> |
resolveMapValueWhenMapIsPojoAttribute(DataProviderStrategy strategy,
Class<?> pojoClass,
Class<?> attributeType,
String attributeName,
List<Annotation> annotations)
It manufactures and returns a Map with at least one element in it |
|
private static
|
resolvePojoWithoutDefaultConstructor(DataProviderStrategy strategy,
Class<T> pojoClass,
int depth)
It creates and returns an instance of the given class if at least one of its constructors has been annotated with PodamConstructor |
|
private static Object |
resolvePrimitiveValue(DataProviderStrategy strategy,
Class<?> primitiveClass,
List<Annotation> annotations)
It resolves and returns the primitive value depending on the type |
|
private static String |
resolveStringValue(DataProviderStrategy strategy,
List<Annotation> annotations)
It creates and returns a String value, eventually customised by annotations |
|
private static Object |
resolveWrapperValue(DataProviderStrategy strategy,
Class<?> candidateWrapperClass,
List<Annotation> annotations)
It attempts to resolve the given class as a wrapper class and if this is the case it assigns a random value |
|
private static Class<?> |
retrieveClassFromCollectionTypeInConstructor(String typeStr)
Given a String representing a type for a collection or map in a constructor, it returns the class of that collection or map |
|
private static Class<?>[] |
retrieveClassFromMapTypeInConstructor(String typeStr)
Given a string representing a Map in a constructor, it returns an array identifying the classes for the key and value in the map |
|
private static List<Annotation> |
retrieveFieldAnnotations(Class<?> clazz,
Method setter)
Given the original class and the setter method, it returns all annotations for the field or an empty collection if no custom annotations were found on the field |
|
private static void |
validateAttributeName(String attributeName)
It validates that the attribute name is not null or empty |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final org.apache.log4j.Logger LOG
Constructor Detail |
---|
public PodamFactory()
Method Detail |
---|
public static <T> T manufacturePojo(Class<T> pojoClass)
This method uses RandomDataProviderStrategy
as the default
implementation.
T
- The type for which a filled instance is requiredpojoClass
- The name of the class for which an instance filled with values
is required
PodamMockeryException
- if a problem occurred while creating a POJO instance or while
setting its statepublic static <T> T manufacturePojo(Class<T> pojoClass, DataProviderStrategy strategy)
T
- The type for which a filled instance is requiredpojoClass
- The name of the class for which an instance filled with values
is requiredstrategy
- The DataProviderStrategy
that PODAM will use to fill
data
PodamMockeryException
- if a problem occurred while creating a POJO instance or while
setting its stateprivate static Object createNewInstanceForClassWithoutSetters(DataProviderStrategy strategy, Class<?> clazz) throws IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException
This method attempts to create an instance of the given argument for classes without setters. These may be either immutable classes (e.g. with final attributes and no setters) or Java classes (e.g. belonging to the java / javax namespace). In case the class does not provide a public, no-arg constructor (e.g. Calendar), this method attempts to find a static, no-args, factory method (e.g. getInstance()) and it invokes it
clazz
- The class for which a new instance is requiredstrategy
- The DataProviderStrategy
that PODAM will use to fill
data
IllegalArgumentException
- If an illegal argument was passed to the constructor
InstantiationException
- If an exception occurred during instantiation
IllegalAccessException
- If security was violated while creating the object
InvocationTargetException
- If an exception occurred while invoking the constructor or
static factory method
ClassNotFoundException
- If it was not possible to create a class from a stringprivate static Object resolvePrimitiveValue(DataProviderStrategy strategy, Class<?> primitiveClass, List<Annotation> annotations)
strategy
- The DataProviderStrategy
that PODAM will use to fill
dataprimitiveClass
- The primitive type classannotations
- The annotations to consider for this attribute
private static Byte getByteValueWithinRange(DataProviderStrategy strategy, List<Annotation> annotations)
PodamByteValue
or null
otherwise
annotations
- The list of annotations for this attributestrategy
- The DataProviderStrategy
to use to retrieve the data.
private static Short getShortValueWithinRange(DataProviderStrategy strategy, List<Annotation> annotations)
PodamShortValue
or null
otherwise
annotations
- The annotations with which the attribute was annotatedstrategy
- The DataProviderStrategy
to use to retrieve the data.
PodamShortValue
or null
otherwiseprivate static Character getCharacterValueWithinRange(DataProviderStrategy strategy, List<Annotation> annotations)
Character
value
annotations
- The list of annotations which might customise the return valuestrategy
- The DataProviderStrategy
to use to retrieve the data.
Character
valueprivate static Integer getIntValueWithinRange(DataProviderStrategy strategy, List<Annotation> annotations)
PodamIntValue
annotation was provided or a random integer if this was not the case
annotations
- The list of annotations for the int attributestrategy
- The DataProviderStrategy
to use to retrieve the data.
PodamIntValue
annotation was provided or a random integer if this was not the
caseprivate static Float getFloatValueWithinRange(DataProviderStrategy strategy, List<Annotation> annotations)
PodamFloatValue
annotation was provided or a random float if this was not the case
annotations
- The list of annotations for the int attributestrategy
- The DataProviderStrategy
to use to retrieve the data.
PodamFloatValue
annotation was provided or a random float if this was not the
caseprivate static Double getDoubleValueWithinRange(DataProviderStrategy strategy, List<Annotation> annotations)
Double
value
annotations
- The list of annotations which might customise the return valuestrategy
- The DataProviderStrategy
to use to retrieve the data.
Double
valueprivate static Long getLongValueWithinRange(DataProviderStrategy strategy, List<Annotation> annotations)
PodamLongValue
annotation was provided or a random long if this was not the case
annotations
- The list of annotations for the int attributestrategy
- The DataProviderStrategy
to use to retrieve the data.
PodamLongValue
annotation was provided or a random long if this was not the caseprivate static Object resolveWrapperValue(DataProviderStrategy strategy, Class<?> candidateWrapperClass, List<Annotation> annotations)
strategy
- The DataProviderStrategy
that PODAM will use to fill
datacandidateWrapperClass
- The class which might be a wrapper class
null
if this is not a wrapper class, otherwise an Object
with the value for the wrapper classprivate static <T> T resolvePojoWithoutDefaultConstructor(DataProviderStrategy strategy, Class<T> pojoClass, int depth) throws IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException
PodamConstructor
T
- The type of the instance to returnstrategy
- The DataProviderStrategy
that PODAM will use to fill
datapojoClass
- The class of which an instance is requireddepth
- How many instances of the same class have been created so far
PodamConstructor
IllegalArgumentException
- If an illegal argument was passed to the constructor
InstantiationException
- If an exception occurred during instantiation
IllegalAccessException
- If security was violated while creating the object
InvocationTargetException
- If an exception occurred while invoking the constructor or
static factory method
ClassNotFoundException
- If it was not possible to create a class from a stringprivate static Class<?> retrieveClassFromCollectionTypeInConstructor(String typeStr)
typeStr
- The String identifying the collection type
IllegalStateException
- If the class identified by typeStr
was not foundprivate static Class<?>[] retrieveClassFromMapTypeInConstructor(String typeStr)
typeStr
- The type of the Map. It can be non-generic
IllegalStateException
- If either the key or value classes could not be loaded
because not foundprivate static <T> T manufacturePojoInternal(DataProviderStrategy strategy, Class<T> pojoClass, int depth)
T
- The type for which a filled instance is requiredstrategy
- The DataProviderStrategy
that PODAM will use to fill
datapojoClass
- The name of the class for which an instance filled with values
is requireddepth
- How many times dtoClass
has been found
PodamMockeryException
- if a problem occurred while creating a POJO instance or while
setting its stateprivate static Object manufactureAttributeValue(DataProviderStrategy strategy, Class<?> pojoClass, Class<?> attributeType, List<Annotation> annotations, String attributeName) throws InstantiationException, IllegalAccessException, InvocationTargetException, IllegalArgumentException, ClassNotFoundException
strategy
- The DataProviderStrategy
that PODAM will use to fill
datapojoClass
- The POJO class being filled with valuesattributeType
- The type of the attribute for which a value is being
manufacturedannotations
- The annotations for the attribute being consideredattributeName
- The attribute name
InstantiationException
- If an exception occurred during instantiation
IllegalAccessException
- If security was violated while creating the object
InvocationTargetException
- If an exception occurred while invoking the constructor or
static factory method
ClassNotFoundException
- If it was not possible to create a class from a string
IllegalArgumentException
- If an illegal argument was passedprivate static String resolveStringValue(DataProviderStrategy strategy, List<Annotation> annotations)
strategy
- The DataProviderStrategy
that PODAM will use to fill
dataannotations
- The list of annotations used to customise the String value, if
any
private static boolean isWrapper(Class<?> candidateWrapperClass)
true
if this class is a wrapper class, false
otherwise
candidateWrapperClass
- The class to check
true
if this class is a wrapper class, false
otherwiseprivate static List<Annotation> retrieveFieldAnnotations(Class<?> clazz, Method setter)
clazz
- The class containing the annotated attributesetter
- The setter method
NoSuchFieldException
- If the field could not be found
SecurityException
- if a security exception occurredprivate static Collection<? super Object> resolveCollectionValueWhenCollectionIsPojoAttribute(DataProviderStrategy strategy, Class<?> pojoClass, Class<?> collectionType, String attributeName, List<Annotation> annotations)
strategy
- The DataProviderStrategy
that PODAM will use to fill
datapojoClass
- The POJO being analysedcollectionType
- The type of the attribute being evaluatedannotations
- The set of annotations for the annotated attribute. It might
be emptyattributeName
- The name of the field being set
PodamMockeryException
- An exception occurred while resolving the collection
IllegalArgumentException
- If the field name is null or emptyprivate static Map<? super Object,? super Object> resolveMapValueWhenMapIsPojoAttribute(DataProviderStrategy strategy, Class<?> pojoClass, Class<?> attributeType, String attributeName, List<Annotation> annotations)
strategy
- The DataProviderStrategy
that PODAM will use to fill
datapojoClass
- The POJO being initialisedattributeType
- The type of the POJO map attributeattributeName
- The POJO attribute nameannotations
- The annotations specified for this attribute
IllegalArgumentException
- PodamMockeryException
- If an error occurred while creating the Map objectprivate static Object resolveArrayElementValue(DataProviderStrategy strategy, Class<?> attributeType, List<Annotation> annotations, Class<?> pojoClass, String attributeName) throws IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException
strategy
- The DataProviderStrategy
that PODAM will use to fill
dataattributeType
- The array typeannotations
- The annotations to be consideredpojoClass
- attributeName
-
IllegalArgumentException
- If an illegal argument was passed to the constructor
InstantiationException
- If an exception occurred during instantiation
IllegalAccessException
- If security was violated while creating the object
InvocationTargetException
- If an exception occurred while invoking the constructor or
static factory method
ClassNotFoundException
- If it was not possible to create a class from a stringprivate static Collection<? super Object> resolveCollectionType(Class<?> collectionType)
List
is an ArrayList
Queue
is a LinkedList
Set
is a HashSet
collectionType
- The collection type *
private static Map<? super Object,? super Object> resolveMapType(Class<?> attributeType)
The default implementation for a ConcurrentMap
is
ConcurrentHashMap
The default implementation for a SortedMap
is a TreeMap
The default Map is none of the above was recognised is a HashMap
attributeType
- The attribute type
private static void validateAttributeName(String attributeName)
attributeName
- The attribute to be validated
IllegalArgumentException
- If the attribute name is null or emptyprivate static int resolveCollectionNbrElementsFromAnnotations(List<Annotation> annotations)
The number of elements defaults to
PodamConstants.ANNOTATION_COLLECTION_DEFAULT_NBR_ELEMENTS
annotations
- The list of annotations to scan for PodamCollection
|
Jemos 2002 - 2011: All Rights Reserved. Podam runs under the MIT license | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |