org.jwalk.core
Class CreateTestCase

java.lang.Object
  extended by org.jwalk.core.TestCase
      extended by org.jwalk.core.ParamTestCase
          extended by org.jwalk.core.CreateTestCase
All Implemented Interfaces:
java.lang.Cloneable

public class CreateTestCase
extends ParamTestCase

CreateTestCase is a kind of test case that constructs a single object. This kind of TestCase encapsulates a single Constructor under test. Before the Constructor is executed, a set of input values is synthesised as arguments for the input parameters of the Constructor, if it has any. The Constructor is invoked to create the target, an instance of the test class, which is returned as the result.

Version:
1.0
Author:
Anthony Simons

Field Summary
 
Fields inherited from class org.jwalk.core.ParamTestCase
isBinary, paramTypes, paramValues
 
Fields inherited from class org.jwalk.core.TestCase
inspector, state
 
Constructor Summary
CreateTestCase(java.lang.reflect.Constructor<?> constructor)
          Creates a CreateTestCase for a Constructor.
 
Method Summary
 java.lang.Object execute(ObjectGenerator generator, java.lang.Object target)
          Executes this CreateTestCase, returning the constructor's result.
 java.lang.String getKey(ObjectGenerator generator)
          Returns a unique indexing key for this CreateTestCase.
 java.lang.reflect.Constructor<?> getOperation()
          Returns the tested operation for this CreateTestCase.
 java.lang.Class<?> getReturnType()
          Returns the result type of the tested operation.
 java.lang.String toString(ObjectGenerator generator)
          Returns a pretty-printed representation of this CreateTestCase.
 
Methods inherited from class org.jwalk.core.ParamTestCase
clone
 
Methods inherited from class org.jwalk.core.TestCase
getState, setInspector
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CreateTestCase

public CreateTestCase(java.lang.reflect.Constructor<?> constructor)
Creates a CreateTestCase for a Constructor. Extracts the input parameter types of the Constructor and stores the Constructor as the operation under test.

Parameters:
constructor - the Constructor under test.
Method Detail

getOperation

public java.lang.reflect.Constructor<?> getOperation()
Returns the tested operation for this CreateTestCase. This is the Constructor under test. The result has the specific type Constructor, but is compatible with the interface-type Member specified in the contract for getOperation. It is possible to access the name of a Member using getName().

Specified by:
getOperation in class TestCase
Returns:
the tested operation.

getReturnType

public java.lang.Class<?> getReturnType()
Returns the result type of the tested operation. This is the type of object created by the Constructor under test, which is the same as the class owning this Constructor. Accesses the owning type directly from the Constructor.

Specified by:
getReturnType in class TestCase
Returns:
the type of object created by the Constructor under test.

execute

public java.lang.Object execute(ObjectGenerator generator,
                                java.lang.Object target)
                         throws java.lang.reflect.InvocationTargetException,
                                GeneratorException,
                                ExecutionException
Executes this CreateTestCase, returning the constructor's result. Uses the super-method in ParamTestCase to supply the input parameters to the Constructor under test, then executes the Constructor to return the target, an instance of the test class. The result can be an object, or an exception. If the Constructor under test raises an InvocationTargetException, this is handled by TestSequence.

Overrides:
execute in class ParamTestCase
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 CreateTestCase. The key is made up of "new", and the parameter values supplied to the Constructor, surrounded by parentheses. Parameter values appear in their oracle value format, as encoded by the generator which synthesised them. Uses the super-method to create part of the key from the parameter list.

Overrides:
getKey in class ParamTestCase
Parameters:
generator - the ObjectGenerator which synthesised the parameters.
Returns:
a unique indexing key for this constructor invocation.

toString

public java.lang.String toString(ObjectGenerator generator)
Returns a pretty-printed representation of this CreateTestCase. This consists of the test class name, used as a declaring type, the initial expression "target = new ", followed by the name of the constructor, then the types and values supplied to the constructor, enclosed in parentheses, terminating in a semicolon to indicate the end of the statement. Parameter values appear in their oracle value format, as encoded by the generator which synthesised them. Uses the super-method to create part of the pretty-printed result from the parameter list. The result looks like this:

TestClass target = new TestClass(type_i value_i, ...);

Overrides:
toString in class ParamTestCase
Parameters:
generator - the ObjectGenerator which synthesised the parameters.
Returns:
a pretty-printed representation of this constructor invocation.