net.sourceforge.groboutils.junit.v1.parser
Class JUnitOrigCreator

java.lang.Object
  extended bynet.sourceforge.groboutils.junit.v1.parser.JUnitOrigCreator
All Implemented Interfaces:
ITestCreator

public class JUnitOrigCreator
extends java.lang.Object
implements ITestCreator

Emulates the construction mechanism for all JUnit versions.

Since:
November 3, 2002
Version:
$Date: 2003/02/10 22:52:21 $
Author:
Matt Albrecht groboclown@users.sourceforge.net

Constructor Summary
JUnitOrigCreator()
           
 
Method Summary
 boolean canCreate(java.lang.Class theClass)
          Checks if the creator can be used on the given class.
 junit.framework.Test createTest(java.lang.Class theClass, java.lang.reflect.Method method)
          Creates a new test, based on the given class and method of the class.
protected  junit.framework.Test createTest(java.lang.Class theClass, java.lang.Object[] constructorArgs)
          Creates a new test class instance.
protected  java.lang.Object[] createTestArguments(java.lang.Class theClass, java.lang.reflect.Method method)
           
protected  java.lang.reflect.Constructor getConstructor(java.lang.Class theClass)
          Discovers the constructor for the test class which will be used in the instantiation of a new instance of the class.
protected  java.lang.Class[] getConstructorArgTypes(java.lang.Class theClass)
          Allows for pluggable constructor types.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JUnitOrigCreator

public JUnitOrigCreator()
Method Detail

createTest

public junit.framework.Test createTest(java.lang.Class theClass,
                                       java.lang.reflect.Method method)
                                throws java.lang.InstantiationException,
                                       java.lang.NoSuchMethodException,
                                       java.lang.reflect.InvocationTargetException,
                                       java.lang.IllegalAccessException,
                                       java.lang.ClassCastException
Creates a new test, based on the given class and method of the class. This calls createTest( Class, Object[] ) to create the new class, which itself calls getConstructorArgTypes( Class ) to determine which constructor to get. Also, createTestArguments( Class, Method ) is called to generate the constructor's arguments.

Specified by:
createTest in interface ITestCreator
Parameters:
theClass - the class to parse for testing.
Returns:
the generated test, or null if the test could not be created.
Throws:
java.lang.InstantiationException - if there was a problem creating the class.
java.lang.NoSuchMethodException - if the method does not exist in the class.
java.lang.reflect.InvocationTargetException
java.lang.IllegalAccessException
java.lang.ClassCastException
See Also:
createTest( Class, Object[] )

canCreate

public boolean canCreate(java.lang.Class theClass)
Checks if the creator can be used on the given class.

Specified by:
canCreate in interface ITestCreator
Parameters:
theClass - the class to check if parsing is acceptable.
Returns:
whether the creator can generate a test based on theClass.

getConstructor

protected java.lang.reflect.Constructor getConstructor(java.lang.Class theClass)
                                                throws java.lang.NoSuchMethodException
Discovers the constructor for the test class which will be used in the instantiation of a new instance of the class. This constructor will be discovered through a call to getConstructorArgTypes. The returned constructor must be callable through createTestArguments.

Parameters:
theClass - the class to parse for testing.
Returns:
the constructor to create a new test instance with.
Throws:
java.lang.NoSuchMethodException - if the class does not have a constructor with the arguments returned by getConstructorArgTypes.
See Also:
getConstructorArgTypes( Class ), createTest( Class, Method ), createTestArguments( Class, Method )

getConstructorArgTypes

protected java.lang.Class[] getConstructorArgTypes(java.lang.Class theClass)
Allows for pluggable constructor types. The default action is to return java.lang.String.

Parameters:
theClass - the class to parse for testing.
Returns:
the set of classes which define the constructor to extract.

createTestArguments

protected java.lang.Object[] createTestArguments(java.lang.Class theClass,
                                                 java.lang.reflect.Method method)
Parameters:
theClass - the class to parse for testing.

createTest

protected junit.framework.Test createTest(java.lang.Class theClass,
                                          java.lang.Object[] constructorArgs)
                                   throws java.lang.InstantiationException,
                                          java.lang.NoSuchMethodException,
                                          java.lang.reflect.InvocationTargetException,
                                          java.lang.IllegalAccessException,
                                          java.lang.ClassCastException
Creates a new test class instance.

Parameters:
theClass - the class to parse for testing.
constructorArgs - arguments for the constructor retrieved through getConstructor().
Returns:
the new Test.
Throws:
java.lang.InstantiationException - if a new instance could not be made of the test class.
java.lang.NoSuchMethodException - if the constructor could not be found.
java.lang.reflect.InvocationTargetException
java.lang.IllegalAccessException
java.lang.ClassCastException
See Also:
getConstructor( Class )


Copyright © 2001-2003 by The GroboUtils Project