Package dk.netarkivet.testutils
Class ReflectUtils
- java.lang.Object
-
- dk.netarkivet.testutils.ReflectUtils
-
public class ReflectUtils extends Object
Methods that help in doing common reflection tasks.
-
-
Constructor Summary
Constructors Constructor Description ReflectUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Constructor<T>
getPrivateConstructor(Class<T> c, Class<?>... args)
Look up a private constructor and make it accessible for testing.static <T> Field
getPrivateField(Class<?> c, String fieldName)
Look up a private field and make it accessible for testing.static Method
getPrivateMethod(Class<?> c, String name, Class<?>... args)
Look up a private method and make it accessible for testing.static void
testUtilityConstructor(Class c)
Method for testing the constructor of a utility class (the constructor should be private).
-
-
-
Method Detail
-
getPrivateMethod
public static Method getPrivateMethod(Class<?> c, String name, Class<?>... args) throws NoSuchMethodException
Look up a private method and make it accessible for testing.- Parameters:
c
- Class to look in.name
- Name of the method.args
- Arguments for the method. Note that primitive types are found using XXX.TYPE.- Returns:
- Method object, accessible for calling.
- Throws:
NoSuchMethodException
-
getPrivateField
public static <T> Field getPrivateField(Class<?> c, String fieldName) throws NoSuchFieldException
Look up a private field and make it accessible for testing.- Parameters:
c
- The class that declares the field.fieldName
- The name of the field.- Returns:
- The field, which can now be set.
- Throws:
NoSuchFieldException
- If there is no such field declared in the class.
-
getPrivateConstructor
public static <T> Constructor<T> getPrivateConstructor(Class<T> c, Class<?>... args) throws NoSuchMethodException
Look up a private constructor and make it accessible for testing.- Parameters:
c
- Class to look in.args
- Arguments for the constructor. Note that primitive types are found using XXX.TYPE.- Returns:
- Constructor object, accessible for calling.
- Throws:
NoSuchMethodException
-
testUtilityConstructor
public static void testUtilityConstructor(Class c)
Method for testing the constructor of a utility class (the constructor should be private).
-
-