public final class TestUtils extends Object
Modifier and Type | Class and Description |
---|---|
static class |
TestUtils.TestUtilsException
Exception that can be thrown if problems are encountered while executing
the utility method.
|
Modifier and Type | Method and Description |
---|---|
static <T> T |
callConstructor(Constructor<T> constructor)
Triggers an allocation of an object of type T and forces a call to
the private constructor.
|
static <T,U> U |
callMethod(T subject,
String methodName,
Class<?>[] paramTypes,
Object... args)
Calls the method, bypassing scope restriction.
|
static <T,U> U |
callMethod(T subject,
String methodName,
Class<?> paramType,
Object arg)
Calls the method, bypassing scope restriction.
|
static <T,U> U |
getField(T subject,
String fieldName)
Gets the field, bypassing scope restriction.
|
static <T,U> void |
setField(T subject,
String fieldName,
U value)
Sets the field, bypassing scope restriction.
|
public static <T,U> void setField(T subject, String fieldName, U value) throws TestUtils.TestUtilsException
T
- subject typeU
- value typesubject
- Object where the field belongsfieldName
- name of the field to setvalue
- value to set to the field.TestUtils.TestUtilsException
- if there are reflection errors while setting
the fieldpublic static <T,U> U getField(T subject, String fieldName) throws TestUtils.TestUtilsException
T
- subject typeU
- fieldO value typesubject
- Object where the field belongsfieldName
- name of the field to getTestUtils.TestUtilsException
- if there are reflection errors while getting
the fieldpublic static <T,U> U callMethod(T subject, String methodName, Class<?>[] paramTypes, Object... args) throws TestUtils.TestUtilsException
T
- subject typeU
- return value typesubject
- Object where the method belongsmethodName
- name of the method to callparamTypes
- formal parameter type arrayargs
- argumentsTestUtils.TestUtilsException
- if there are reflection errors while calling
the methodpublic static <T,U> U callMethod(T subject, String methodName, Class<?> paramType, Object arg) throws TestUtils.TestUtilsException
T
- subject typeU
- return value typesubject
- Object where the method belongsmethodName
- name of the method to callparamType
- formal parameter typearg
- argumentTestUtils.TestUtilsException
- if there are reflection errors while calling
the methodpublic static <T> T callConstructor(Constructor<T> constructor) throws TestUtils.TestUtilsException
T
- type of the object to createconstructor
- Constructor to callTestUtils.TestUtilsException
- if there are reflection errors while calling
the constructor