org.jwalk.core
Class InvokeTestCase

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

public class InvokeTestCase
extends ParamTestCase

InvokeTestCase is a kind of test case that invokes a single method. This kind of TestCase encapsulates a single Method under test. Before the Method is executed, a set of input values is synthesised as arguments for the input parameters of the method, if it has any. The Method is invoked on a target object, an instance of the test class, and the result is returned.

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
InvokeTestCase(java.lang.reflect.Method method)
          Creates an InvokeTestCase for a Method.
 
Method Summary
 java.lang.Object execute(ObjectGenerator generator, java.lang.Object target)
          Executes this InvokeTestCase, returning the invoked method's result.
 java.lang.String getKey(ObjectGenerator generator)
          Returns a unique indexing key for this InvokeTestCase.
 java.lang.reflect.Method getOperation()
          Returns the tested operation for this InvokeTestCase.
 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 InvokeTestCase.
 
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

InvokeTestCase

public InvokeTestCase(java.lang.reflect.Method method)
Creates an InvokeTestCase for a Method. Extracts the input parameter types of the Method and stores the Method as the operation under test.

Parameters:
method - the Method under test.
Method Detail

getOperation

public java.lang.reflect.Method getOperation()
Returns the tested operation for this InvokeTestCase. This is the Method under test. The result has the specific type Method, 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 return type of the Method under test. Accesses this type directly from the Method.

Specified by:
getReturnType in class TestCase
Returns:
the return type of the Method under test.

execute

public java.lang.Object execute(ObjectGenerator generator,
                                java.lang.Object target)
                         throws java.lang.reflect.InvocationTargetException,
                                GeneratorException,
                                ExecutionException
Executes this InvokeTestCase, returning the invoked method's result. Uses the super-method in ParamTestCase to supply the input parameters to the Method under test, then invokes this method on the target, which is an instance of the test class. The result can be any kind of value, object, exception, null or void. If the Method 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 InvokeTestCase. The key is made up of a dot, the name of the method, and the parameter values supplied to the Method, 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 method invocation.

toString

public java.lang.String toString(ObjectGenerator generator)
Returns a pretty-printed representation of this InvokeTestCase. This consists of "target", a dot, the name of the method, then the types and values supplied to the method, 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:

target.method(type_i value_i, ...);

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