junitx.framework
Class PrivateTestCase

java.lang.Object
  |
  +--junit.framework.Assert
        |
        +--junit.framework.TestCase
              |
              +--junitx.framework.PrivateTestCase
All Implemented Interfaces:
Test

public abstract class PrivateTestCase
extends TestCase

PrivateTestCase is the parent class of all test cases you supply in order to test private code.


Constructor Summary
PrivateTestCase(java.lang.String aName)
          constructor
 
Method Summary
 boolean asBoolean(java.lang.Object aBoolean)
          converts a Boolean into a boolean.
 byte asByte(java.lang.Object aByte)
          converts a Byte into a byte.
 char asChar(java.lang.Object aCharacter)
          converts a Character into a char.
 double asDouble(java.lang.Object aDouble)
          converts a Double into a double.
 float asFloat(java.lang.Object aFloat)
          converts a Float into a float.
 int asInt(java.lang.Object aInteger)
          converts a Integer into a int.
 long asLong(java.lang.Object aLong)
          converts a Long longo a long.
 short asShort(java.lang.Object aShort)
          converts a Short shorto a short.
 void dumpKeys(java.lang.String aFQClassName)
          dumps constructor and method keys for a proxied class.
 java.lang.Object get(java.lang.Object anObject, java.lang.String aFieldName)
          gets a field value object.
 java.lang.Object get(java.lang.String aFQClassName, java.lang.String aFieldName)
          gets a field value object of a non-instantiated class.
 boolean getBoolean(java.lang.Object anObject, java.lang.String aFieldName)
          gets a boolean field value.
 byte getByte(java.lang.Object anObject, java.lang.String aFieldName)
          gets a byte field value.
 char getChar(java.lang.Object anObject, java.lang.String aFieldName)
          gets a char field value.
 double getDouble(java.lang.Object anObject, java.lang.String aFieldName)
          gets a double field value.
 float getFloat(java.lang.Object anObject, java.lang.String aFieldName)
          gets a float field value.
 int getInt(java.lang.Object anObject, java.lang.String aFieldName)
          gets an integer field value.
 long getLong(java.lang.Object anObject, java.lang.String aFieldName)
          gets a long field value.
 short getShort(java.lang.Object anObject, java.lang.String aFieldName)
          gets a short field value.
 java.lang.Object invoke(java.lang.Object anObject, java.lang.String aMethodName, java.lang.Object[] anArgArray)
          invokes a method on a proxied class.
 java.lang.Object invokeWithKey(java.lang.Object anObject, java.lang.String aMethodKey, java.lang.Object[] anArgArray)
          invokes a method on a proxied class using a method key.
 java.lang.Object newInstance(java.lang.String aClassName, java.lang.Object[] anArgArray)
          invokes a constructor of a tested class.
 java.lang.Object newInstanceWithKey(java.lang.String aClassName, java.lang.String aConstructorKey, java.lang.Object[] anArgArray)
          invokes a constructor of a class receiving simple data type arguments.
 
Methods inherited from class junit.framework.TestCase
countTestCases, getName, name, run, run, runBare, setName, toString
 
Methods inherited from class junit.framework.Assert
assert, assert, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertNotNull, assertNotNull, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PrivateTestCase

public PrivateTestCase(java.lang.String aName)
constructor
Parameters:
aName - name of the test case
Method Detail

invoke

public java.lang.Object invoke(java.lang.Object anObject,
                               java.lang.String aMethodName,
                               java.lang.Object[] anArgArray)
                        throws TestAccessException
invokes a method on a proxied class. First a proxy for the tested class is fetched, than the requested method is invoked. This method cannot only be used for methods which do not take simple data types as their arguments. Use the other invoke methods to cover the other cases.
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 field cannot be accessed

newInstance

public java.lang.Object newInstance(java.lang.String aClassName,
                                    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:
aClassName - the name of the class to be instantiated
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 on a proxied class using a method key. First a proxy for the tested class is fetched, than the requested method is invoked. This method supports invocation of methods which also get primitive data types as arguments. A method key consists of the method name, an underscore ('_') and the parameters delimited by underscores. Here are some examples: 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 method key
anArgArray - a list of arguments to the method to be invoked
Returns:
an object, a wrapped primitive type or null
Throws:
TestAccessException - if the field cannot be accessed

newInstanceWithKey

public java.lang.Object newInstanceWithKey(java.lang.String aClassName,
                                           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:
aClassName - the name of the class to be instantiated
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 a field value object. A proxy for the appropriate class is fetched automatically if necessary.
Parameters:
anObject - object to be queried
aFieldName - a field name
Returns:
an object or a wrapped simple data type value.
Throws:
TestAccessException - if the field cannot be accessed

get

public java.lang.Object get(java.lang.String aFQClassName,
                            java.lang.String aFieldName)
                     throws TestAccessException
gets a field value object of a non-instantiated class. A proxy for the appropriate class is fetched automatically if necessary. The convience get*()-Methods for simple data types are not implemented for accessing classes instead of objects to keep the class reasonably "small".
Parameters:
aFQClassName - class to be queried
aFieldName - a field name
Returns:
an object or a wrapped simple data type value.
Throws:
TestAccessException - if the field cannot be accessed

getBoolean

public boolean getBoolean(java.lang.Object anObject,
                          java.lang.String aFieldName)
                   throws TestAccessException
gets a boolean field value. A proxy for the appropriate class is fetched automatically if necessary.
Parameters:
anObject - object to be queried
aFieldName - a 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 a byte field value. A proxy for the appropriate class is fetched automatically if necessary.
Parameters:
anObject - object to be queried
aFieldName - a 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 a char field value. A proxy for the appropriate class is fetched automatically if necessary.
Parameters:
anObject - object to be queried
aFieldName - a 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 a double field value. A proxy for the appropriate class is fetched automatically if necessary.
Parameters:
anObject - object to be queried
aFieldName - a 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 a float field value. A proxy for the appropriate class is fetched automatically if necessary.
Parameters:
anObject - object to be queried
aFieldName - a 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 an integer field value. A proxy for the appropriate class is fetched automatically if necessary.
Parameters:
anObject - object to be queried
aFieldName - a field name
Returns:
an integer value.
Throws:
TestAccessException - if the field cannot be accessed

getLong

public long getLong(java.lang.Object anObject,
                    java.lang.String aFieldName)
             throws TestAccessException
gets a long field value. A proxy for the appropriate class is fetched automatically if necessary.
Parameters:
anObject - object to be queried
aFieldName - a 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 a short field value. A proxy for the appropriate class is fetched automatically if necessary.
Parameters:
anObject - object to be queried
aFieldName - a field name
Returns:
a short value.
Throws:
TestAccessException - if the field cannot be accessed

dumpKeys

public void dumpKeys(java.lang.String aFQClassName)
              throws TestAccessException
dumps constructor and method keys for a proxied class.
Parameters:
aFQClassName - a fully qualified name of the proxied class
Throws:
TestAccessException - if the proxied class cannot be accessed

asBoolean

public boolean asBoolean(java.lang.Object aBoolean)
converts a Boolean into a boolean.
Parameters:
aBoolean - an instance of Boolean
Returns:
a boolean

asByte

public byte asByte(java.lang.Object aByte)
converts a Byte into a byte.
Parameters:
aByte - an instance of Byte
Returns:
a byte

asChar

public char asChar(java.lang.Object aCharacter)
converts a Character into a char.
Parameters:
aCharacter - an instance of Character
Returns:
a char

asDouble

public double asDouble(java.lang.Object aDouble)
converts a Double into a double.
Parameters:
aDouble - an instance of Double
Returns:
a double

asFloat

public float asFloat(java.lang.Object aFloat)
converts a Float into a float.
Parameters:
aFloat - an instance of Float
Returns:
a float

asInt

public int asInt(java.lang.Object aInteger)
converts a Integer into a int.
Parameters:
aInteger - an instance of Integer
Returns:
a int

asLong

public long asLong(java.lang.Object aLong)
converts a Long longo a long.
Parameters:
aLong - an instance of Long
Returns:
a long

asShort

public short asShort(java.lang.Object aShort)
converts a Short shorto a short.
Parameters:
aShort - an instance of Short
Returns:
a short