org.apache.commons.test
Class PrivateTestCase

java.lang.Object
  extended byjunit.framework.Assert
      extended byjunit.framework.TestCase
          extended byorg.apache.commons.test.PrivateTestCase
All Implemented Interfaces:
junit.framework.Test

public class PrivateTestCase
extends junit.framework.TestCase

A test case with utility methods used to access private members and test private methods. Bill Venners discusses the technique of unit testing private code without basturdizing your code in the following artical: Testing Private Methods with JUnit and SuiteRunner. We have created this class to follow his recommendation for unit testing private methods using Reflection.

Version:
$Revision: 155470 $

Constructor Summary
PrivateTestCase()
           
PrivateTestCase(java.lang.String s)
           
 
Method Summary
static java.lang.Object getMember(java.lang.String name, java.lang.Object obj)
          Gets a member regardless of its visibility.
static java.lang.Object invoke(java.lang.Class targetClass, java.lang.String methodName, java.lang.Class[] argClasses, java.lang.Object[] argObjects)
          Invokes a static method on a class regardless of the method's visibility.
static java.lang.Object invoke(java.lang.Object obj, java.lang.Class targetClass, java.lang.String methodName, java.lang.Class[] argClasses, java.lang.Object[] argObjects)
          Invokes a method on an object regardless of the method's visibility.
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, setUp, tearDown, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PrivateTestCase

public PrivateTestCase()

PrivateTestCase

public PrivateTestCase(java.lang.String s)
Method Detail

getMember

public static java.lang.Object getMember(java.lang.String name,
                                         java.lang.Object obj)
Gets a member regardless of its visibility.

Parameters:
name - the name of the member
obj - the Object whose member we access
Returns:
the member Object

invoke

public static java.lang.Object invoke(java.lang.Object obj,
                                      java.lang.Class targetClass,
                                      java.lang.String methodName,
                                      java.lang.Class[] argClasses,
                                      java.lang.Object[] argObjects)
Invokes a method on an object regardless of the method's visibility.

Parameters:
obj - the object whose method is called
targetClass - the class of the object (don't need it)
methodName - the name of the method to invoke
argClasses - the classes of the args
argObjects - the arguments of the call
Returns:
the result or null if the return value is void

invoke

public static java.lang.Object invoke(java.lang.Class targetClass,
                                      java.lang.String methodName,
                                      java.lang.Class[] argClasses,
                                      java.lang.Object[] argObjects)
Invokes a static method on a class regardless of the method's visibility.

Parameters:
targetClass - the class of the object (don't need it)
methodName - the name of the method to invoke
argClasses - the classes of the args
argObjects - the arguments of the call
Returns:
the result or null if the return value is void


Copyright © 2004-2006 . All Rights Reserved.