junitx.framework
Class TestProxy

java.lang.Object
  |
  +--junitx.framework.TestProxy

public abstract class TestProxy
extends java.lang.Object

The TestProxyImpl is beeing used to create a TestProxy in each package which contains testcases of package private classes which should be tested. A TestProxy stores information gathered by reflection on a class which should be tested and to access classes which are defined package private.


Constructor Summary
TestProxy()
           
 
Method Summary
 void dumpKeys()
          dumps constructor and method keys of proxied class.
 java.lang.Object get(java.lang.Object anObject, java.lang.String aFieldName)
          gets the value of a field.
 boolean getBoolean(java.lang.Object anObject, java.lang.String aFieldName)
          gets the boolean value of a field.
 byte getByte(java.lang.Object anObject, java.lang.String aFieldName)
          gets the byte value of a field.
 char getChar(java.lang.Object anObject, java.lang.String aFieldName)
          gets the char value of a field.
 double getDouble(java.lang.Object anObject, java.lang.String aFieldName)
          gets the double value of a field.
 float getFloat(java.lang.Object anObject, java.lang.String aFieldName)
          gets the float value of a field.
 int getInt(java.lang.Object anObject, java.lang.String aFieldName)
          gets the int value of a field.
 long getLong(java.lang.Object anObject, java.lang.String aFieldName)
          gets the long value of a field.
 TestedClass getProxiedClass()
          gets the proxied class
 short getShort(java.lang.Object anObject, java.lang.String aFieldName)
          gets the short value of a field.
 java.lang.String getTestedClassName()
          gets the real tested class name
 void init(TestedClass aTestedClass)
          initializes a proxy.
 java.lang.Object invoke(java.lang.Object anObject, java.lang.String aMethodName, java.lang.Object[] anArgArray)
          invokes a method of a tested class.
 java.lang.Object invokeWithKey(java.lang.Object anObject, java.lang.String aMethodKey, java.lang.Object[] anArgArray)
          invokes a method of a class receiving simple data type arguments.
abstract  java.lang.Object newInstance(java.lang.Object[] anArgArray)
          invokes a constructor of a tested class.
abstract  java.lang.Object newInstanceWithKey(java.lang.String aConstructorKey, java.lang.Object[] anArgArray)
          invokes a constructor of a class receiving simple data type arguments.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TestProxy

public TestProxy()
Method Detail

init

public void init(TestedClass aTestedClass)
initializes a proxy. There is no constructor including the functionality of this method since the TestProxyFactory class uses the newInstance method of the reflection API to create an instance of this class.
Parameters:
aTestedClass - an instance of TestedClass

getProxiedClass

public TestedClass getProxiedClass()
gets the proxied class
Returns:
a TestedClass

getTestedClassName

public java.lang.String getTestedClassName()
gets the real tested class name
Returns:
a class name as String

invoke

public java.lang.Object invoke(java.lang.Object anObject,
                               java.lang.String aMethodName,
                               java.lang.Object[] anArgArray)
                        throws TestAccessException
invokes a method of a tested class. See documentation of Class.invoke () for a more detailed description. This method cannot be used for methods containing simple datatypes as arguments since getDeclaredMethod() is not able to take the necessary arguments. Use one of the other invoke methods to cover that other cases. This method should always be applied to the proxy for the tested class.
Parameters:
anObject - an object to process
aMethodName - a String method name
anArgArray - a list of arguments to the method to be invoked
Returns:
an object, a wrapped primitive type or null
Throws:
TestAccessException - if the invocation fails

newInstance

public abstract java.lang.Object newInstance(java.lang.Object[] anArgArray)
                                      throws TestAccessException
invokes a constructor of a tested class. See documentation of Constructor.newInstance() for a more detailed description. This method cannot be used for constructors containing simple datatypes as arguments since getDeclaredConstructors() is not able to take the necessary arguments. Use one of the other invoke methods to cover that other cases. This method should always be applied to the proxy for the tested class.
Parameters:
anArgArray - a list of arguments to the constructor to be invoked
Returns:
an object or null
Throws:
TestAccessException - if the invocation fails

invokeWithKey

public java.lang.Object invokeWithKey(java.lang.Object anObject,
                                      java.lang.String aMethodKey,
                                      java.lang.Object[] anArgArray)
                               throws TestAccessException
invokes a method of a class receiving simple data type arguments. See Class.invoke () for a more detailed description. This method is able to accept simple datatypes for invoking a method. Normally this does not work with getDeclaredMethod(). Here a string key is used to identify the desired method. Here are some examples to show how the key is generated: set (int foo) key: set_int setOther (String foo, char bar) key: setOther_java.lang.String_char
Parameters:
anObject - an object to process
aMethodKey - a String method name with argument types
anArgArray - a list of arguments to the method to be invoked
Returns:
an object, a wrapped primitive type or null
Throws:
TestAccessException -  

newInstanceWithKey

public abstract java.lang.Object newInstanceWithKey(java.lang.String aConstructorKey,
                                                    java.lang.Object[] anArgArray)
                                             throws TestAccessException
invokes a constructor of a class receiving simple data type arguments. See Constructor.newInstance() for a more detailed description. This method is able to accept simple datatypes for invoking a method. Normally this does not work with getDeclaredConstructors(). Here a string key is used to identify the desired method. Here are some examples to show how the key is generated: MyClass () key: _ MyClass (int foo) key: _int MyClass (String foo, char bar) key: _java.lang.String_char
Parameters:
aConstructorKey - constructor argument types as key
anArgArray - a list of arguments to the constructor to be invoked
Returns:
an object or null
Throws:
TestAccessException -  

get

public java.lang.Object get(java.lang.Object anObject,
                            java.lang.String aFieldName)
                     throws TestAccessException
gets the value of a field. Primitive types are automatically wrapped.
Parameters:
anObject - object to be processed
aFieldName - a String field name
Returns:
an object or null
Throws:
TestAccessException - if the field cannot be accessed

getBoolean

public boolean getBoolean(java.lang.Object anObject,
                          java.lang.String aFieldName)
                   throws TestAccessException
gets the boolean value of a field.
Parameters:
anObject - object to be processed
aFieldName - a String field name
Returns:
a boolean value
Throws:
TestAccessException - if the field cannot be accessed

getByte

public byte getByte(java.lang.Object anObject,
                    java.lang.String aFieldName)
             throws TestAccessException
gets the byte value of a field.
Parameters:
anObject - object to be processed
aFieldName - a String field name
Returns:
a byte value
Throws:
TestAccessException - if the field cannot be accessed

getChar

public char getChar(java.lang.Object anObject,
                    java.lang.String aFieldName)
             throws TestAccessException
gets the char value of a field.
Parameters:
anObject - object to be processed
aFieldName - a String field name
Returns:
a char value
Throws:
TestAccessException - if the field cannot be accessed

getDouble

public double getDouble(java.lang.Object anObject,
                        java.lang.String aFieldName)
                 throws TestAccessException
gets the double value of a field.
Parameters:
anObject - object to be processed
aFieldName - a String field name
Returns:
a double value
Throws:
TestAccessException - if the field cannot be accessed

getFloat

public float getFloat(java.lang.Object anObject,
                      java.lang.String aFieldName)
               throws TestAccessException
gets the float value of a field.
Parameters:
anObject - object to be processed
aFieldName - a String field name
Returns:
a float value
Throws:
TestAccessException - if the field cannot be accessed

getInt

public int getInt(java.lang.Object anObject,
                  java.lang.String aFieldName)
           throws TestAccessException
gets the int value of a field.
Parameters:
anObject - object to be processed
aFieldName - a String field name
Returns:
an int value
Throws:
TestAccessException - if the field cannot be accessed

getLong

public long getLong(java.lang.Object anObject,
                    java.lang.String aFieldName)
             throws TestAccessException
gets the long value of a field.
Parameters:
anObject - object to be processed
aFieldName - a String field name
Returns:
a long value
Throws:
TestAccessException - if the field cannot be accessed

getShort

public short getShort(java.lang.Object anObject,
                      java.lang.String aFieldName)
               throws TestAccessException
gets the short value of a field.
Parameters:
anObject - object to be processed
aFieldName - a String field name
Returns:
a short value
Throws:
TestAccessException - if the field cannot be accessed

dumpKeys

public void dumpKeys()
dumps constructor and method keys of proxied class.