org.jwalk.core
Class ParamTestCase

java.lang.Object
  extended by org.jwalk.core.TestCase
      extended by org.jwalk.core.ParamTestCase
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
CreateTestCase, InvokeTestCase

public abstract class ParamTestCase
extends TestCase

ParamTestCase is a kind of test case that accepts input parameters. ParamTestCase is the abstract parent of InvokeTestCase (for methods) and CreateTestCase (for constructors), which may require input parameters.

Version:
1.0
Author:
Anthony Simons

Field Summary
protected  boolean isBinary
          A flag to indicate that the tested operation is a binary method.
protected  java.lang.Class<?>[] paramTypes
          The parameter types of the tested operation.
protected  java.lang.Object[] paramValues
          The parameter values for the tested operation.
 
Fields inherited from class org.jwalk.core.TestCase
inspector, state
 
Constructor Summary
protected ParamTestCase(java.lang.reflect.Constructor<?> constructor)
          Creates a ParamTestCase for a Constructor.
protected ParamTestCase(java.lang.reflect.Method method)
          Creates a ParamTestCase for a Method.
 
Method Summary
 ParamTestCase clone()
          Clones a shallow copy of this ParamTestCase.
 java.lang.Object execute(ObjectGenerator generator, java.lang.Object target)
          Executes this ParamTestCase, returning null.
 java.lang.String getKey(ObjectGenerator generator)
          Returns a unique indexing key for this ParamTestCase.
 java.lang.String toString(ObjectGenerator generator)
          Returns a pretty-printed representation of this ParamTestCase.
 
Methods inherited from class org.jwalk.core.TestCase
getOperation, getReturnType, getState, setInspector
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

isBinary

protected boolean isBinary
A flag to indicate that the tested operation is a binary method.


paramTypes

protected java.lang.Class<?>[] paramTypes
The parameter types of the tested operation. This is an array of parameter types, extracted directly from the Constructor or Method under test, when this ParamTestCase is constructed.


paramValues

protected java.lang.Object[] paramValues
The parameter values for the tested operation. This is a corresponding array of Object values, which is first created when this ParamTestCase is executed. The values must match the expected types.

Constructor Detail

ParamTestCase

protected ParamTestCase(java.lang.reflect.Constructor<?> constructor)
Creates a ParamTestCase for a Constructor. Extracts the input parameter types of the Constructor.


ParamTestCase

protected ParamTestCase(java.lang.reflect.Method method)
Creates a ParamTestCase for a Method. Extracts the input parameter types of the Method. If the Method is known to be a binary method, such as "equals" or "compareTo", sets an internal flag, which affects how argument values will be synthesised.

Method Detail

clone

public ParamTestCase clone()
Clones a shallow copy of this ParamTestCase. The clone shares the paramTypes array and the isBinary field value, but its state is reset to zero and its paramValues array is set to null, to guarantee a completely separate execution.

Overrides:
clone in class TestCase

execute

public java.lang.Object execute(ObjectGenerator generator,
                                java.lang.Object target)
                         throws java.lang.reflect.InvocationTargetException,
                                GeneratorException,
                                ExecutionException
Executes this ParamTestCase, returning null. In ParamTestCase, this method is a partial algorithm only, to be shared by CreateTestCase and InvokeTestCase. It creates the paramValues array and attempts to populate the array with values for each type in the paramTypes array. This is done using the supplied ObjectGenerator, which may raise a GeneratorException if it cannot provide the requested inputs.

Specified by:
execute in class TestCase
Parameters:
generator - the ObjectGenerator for synthesising test inputs.
target - the target object, initially null.
Returns:
null, since this is only a partial algorithm.
Throws:
java.lang.reflect.InvocationTargetException - if the tested operation raises an exception internally. This is later handled by TestSequence, which reports the exception as the result of the test.
GeneratorException - if any constructor or method argument value could not be synthesised. A CustomGenerator must be provided that is capable of synthesising values of the argument type.
ExecutionException - if any constructor or method could not be invoked, or if it exhibited unpredictable random behaviour.

getKey

public java.lang.String getKey(ObjectGenerator generator)
Returns a unique indexing key for this ParamTestCase. This is a partial algorithm only, to be shared by CreateTestCase and InvokeTestCase, which converts the parameter types and values of this ParamTestCase into a unique string representation, to be used as part of a unique key for descendants of this ParamTestCase.

Specified by:
getKey in class TestCase
Parameters:
generator - the ObjectGenerator which synthesised the parameters.
Returns:
a unique string based on the parameter types and values.

toString

public java.lang.String toString(ObjectGenerator generator)
Returns a pretty-printed representation of this ParamTestCase. This is a partial algorithm only, to be shared by CreateTestCase and InvokeTestCase, which converts the parameter types and values of this ParamTestCase into a pretty-printed format.

Specified by:
toString in class TestCase
Parameters:
generator - the ObjectGenerator which synthesised the parameters.
Returns:
a pretty-printed representation of the parameter list.