org.callbackparams.combine.reflect
Class CallbackRecordsFactory

java.lang.Object
  extended by org.callbackparams.combine.reflect.CallbackRecordsFactory
Direct Known Subclasses:
AnnotationAwareCallbackRecordsFactory

public abstract class CallbackRecordsFactory
extends Object

Factory-class whose main purpose is to create callback-records from reflectively looked-up callback-values factory classes. The default recipe for a callback-values factory is a nested class that has a static array-returning method with the signature 'values()', e.g. a nested enum.

Author:
Henrik Kaipe

Constructor Summary
CallbackRecordsFactory()
           
 
Method Summary
static Combined[] asCombinedArray(Object record)
          Utility method that is used by subclasses and the JUnit-3.x utilities.
 Collection collectCallbackRecordsReflectively(Class testClass)
          This is the method that integration harnesses (such as the CallbackParamsRunner) should use for retrieving their callback-records in a test-developer friendly way.
protected  Map collectValueInjections(Class testClass)
          Collects values for the parameterized fields that are to be value-injected.
protected  Set findCallbackValuesFactoryClasses(Class testClass)
          Searches the specified class, its super-classes and all implemented interfaces for nested classes that provide callback-values, as defined by isCallbackValuesFactoryClass(java.lang.Class).
static CallbackRecordsFactory getInstance()
          Factory method that returns the implementation suitable for the java-version in use.
protected  boolean isCallbackValuesFactoryClass(Class factoryProspect)
          The default implementation returns true if the specified class has a static method "values()" that returns an array.
protected  boolean isValueAlsoAvailableAsCallback(Field f)
          Decides on whether the parameter value will also be available as callback when it is injected to the specified field.
 Combined[] retrieveCombinedArray(Class valuesClass)
          The returned array (supposedly containing callback-values) is determined from the specified class.
 CombineStrategy retrieveCombineStrategy(Class testClass)
          The default combine strategy is CombineAllPossible2Combinations but any other strategy could be used by overriding this class or by using the @CombineConfig annotation (if using JDK-1.5+).
static Method valuesMethodFor(Class valuesClass)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CallbackRecordsFactory

public CallbackRecordsFactory()
Method Detail

getInstance

public static CallbackRecordsFactory getInstance()
Factory method that returns the implementation suitable for the java-version in use. I.e. a pretty simple implementation for JDK-1.4, which basicly only supports a default behaviour, and a more feature-rich implementation for JDK-1.5+, which makes it possible tweak the default behaviour through annotations.


findCallbackValuesFactoryClasses

protected Set findCallbackValuesFactoryClasses(Class testClass)
Searches the specified class, its super-classes and all implemented interfaces for nested classes that provide callback-values, as defined by isCallbackValuesFactoryClass(java.lang.Class).


isCallbackValuesFactoryClass

protected boolean isCallbackValuesFactoryClass(Class factoryProspect)
The default implementation returns true if the specified class has a static method "values()" that returns an array.


valuesMethodFor

public static Method valuesMethodFor(Class valuesClass)
                              throws NoSuchMethodException
Throws:
NoSuchMethodException

retrieveCombinedArray

public Combined[] retrieveCombinedArray(Class valuesClass)
The returned array (supposedly containing callback-values) is determined from the specified class. The default procedure to determine this array is simply to invoke the static method values() and assume it returns an array of callback-values. The reason is that the static values()-method is the method that returns an array of all enum-constants for a java.lang.Enum implementation.
However, it is not necessary that the argument class is an Enum, as long as it has its static values()-method returning an array of callback-values.


retrieveCombineStrategy

public CombineStrategy retrieveCombineStrategy(Class testClass)
The default combine strategy is CombineAllPossible2Combinations but any other strategy could be used by overriding this class or by using the @CombineConfig annotation (if using JDK-1.5+).


collectCallbackRecordsReflectively

public Collection collectCallbackRecordsReflectively(Class testClass)
This is the method that integration harnesses (such as the CallbackParamsRunner) should use for retrieving their callback-records in a test-developer friendly way.

Parameters:
testClass - the test class
Returns:
the collection of combined and ready-to-use callback-records retrieved from testClass

collectValueInjections

protected Map collectValueInjections(Class testClass)
Collects values for the parameterized fields that are to be value-injected. This default implementation returns an empty map but the JDK-1.5+ implementation overrides this and makes sure that @ParameterizedValue annotated fields are value-injected.

Returns:
a map that maps instances of Field to the class, in which to find the values() method that will provide the values for this field

isValueAlsoAvailableAsCallback

protected boolean isValueAlsoAvailableAsCallback(Field f)
Decides on whether the parameter value will also be available as callback when it is injected to the specified field. This defualt implementation will return true unless the field type is either boolean or Boolean. The default behaviour can be overridden by overriding this class or by using the annotation-attribute org.callbackparams.annotation.ValueField#alsoAvailableAsCallback() (when using JDK -1.5+).


asCombinedArray

public static Combined[] asCombinedArray(Object record)
Utility method that is used by subclasses and the JUnit-3.x utilities.



Copyright © 2010-2013 Henrik Kaipe. All Rights Reserved.