org.jwalk.core
Class EnumTestCase

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

public class EnumTestCase
extends TestCase

EnumTestCase is a kind of test case that selects an enumerated constant. Rather than having to construct an object, or invoke a method, this kind of TestCase has to select one of the unique constants listed for its enumerated type. A unique constant is selected when this EnumTestCase is constructed. Executing this test case has no further effect, other than to encode the state represented by the value.

Version:
1.0
Author:
Anthony Simons

Field Summary
 
Fields inherited from class org.jwalk.core.TestCase
inspector, state
 
Constructor Summary
EnumTestCase(java.lang.Enum<?> value)
          Creates an EnumTestCase for an enumerated value.
 
Method Summary
 java.lang.Object execute(ObjectGenerator generator, java.lang.Object target)
          Executes this EnumTestCase, returning the result.
 java.lang.String getKey(ObjectGenerator generator)
          Returns a unique indexing key for this EnumTestCase.
 java.lang.reflect.Member getOperation()
          Returns the tested operation for this EnumTestCase.
 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 EnumTestCase.
 
Methods inherited from class org.jwalk.core.TestCase
clone, getState, setInspector
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EnumTestCase

public EnumTestCase(java.lang.Enum<?> value)
Creates an EnumTestCase for an enumerated value. Stores this value as the enumerated constant, and its type as the enumerated type.

Parameters:
value - the enumerated value.
Method Detail

execute

public java.lang.Object execute(ObjectGenerator generator,
                                java.lang.Object target)
Executes this EnumTestCase, returning the result. Returns a unique enumerated constant from the enumerated type as the result. Since this is an initial test case, the target is ignored (and is null).

Specified by:
execute in class TestCase
Parameters:
generator - the ObjectGenerator for synthesising test inputs.
target - the target object, initially null.
Returns:
the result of this EnumTestCase, an enumerated constant.

getKey

public java.lang.String getKey(ObjectGenerator generator)
Returns a unique indexing key for this EnumTestCase. This key is part of the indexing key for a TestSequence in an Oracle. Returns the String representation of the enumerated constant. The ObjectGenerator is technically redundant, as it need not be consulted; however it is generally required by the contract of getKey().

Specified by:
getKey in class TestCase
Parameters:
generator - the ObjectGenerator which synthesised the constant.
Returns:
a unique indexing key.

getOperation

public java.lang.reflect.Member getOperation()
Returns the tested operation for this EnumTestCase. Returns the public Field corresponding to the enumerated value. This is a constant, rather than an operation.

Specified by:
getOperation in class TestCase
Returns:
a constant Field denoting the value.

getReturnType

public java.lang.Class<?> getReturnType()
Returns the result type of the tested operation. This is the type of the enumerated constant selected by this test case.

Specified by:
getReturnType in class TestCase
Returns:
the enumerated type.

toString

public java.lang.String toString(ObjectGenerator generator)
Returns a pretty-printed representation of this EnumTestCase. This consists of the test class name used as a declaring type, the initial expression "target = ", followed by an enumerated constant, selected as a static member from its type, terminating with a semicolon to indicate the end of the statement. The result looks like this:

TestEnum target = TestEnum.value_i;

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