クラス ReflectionTestHelper<T,R>
- すべての実装されたインタフェース:
Serializable
public final class ReflectionTestHelper<T,R> extends Object implements Serializable
When creating a new instance of the ReflectionTestHelper class, pass
the class information of the class in which the method to be invoked is
defined to the from(Class) method. The generic type of the
ReflectionTestHelper class should be the type of SUT and the type
returned by the method to be invoked.
Then you can execute the target method by creating a new instance of
ReflectionTestHelper and then invoking the
invokeMethod(String) method with the name of the method to be
invoked as the argument.
If the method to be invoked requires the specification of arguments, call the
addArgument(Class, Object) method and add the argument types and
values that need to be set.
More details are at https://github.com/myConsciousness/reflection-test-helper/blob/main/README.md
- 導入されたバージョン:
- 1.0.0
- 関連項目:
- 直列化された形式
-
メソッドの概要
修飾子とタイプ メソッド 説明 ReflectionTestHelper<T,R>addArgument(@NonNull Class<?> argumentType, Object argumentValue)Adds the argument types and values defined for the target method to be invoked in reflection.booleanequals(Object o)static <T, R> ReflectionTestHelper<T,R>from(@NonNull Class<?> clazz)Returns the new instance ofReflectionTestHelperbased on the argument.ObjectgetFieldValue(@NonNull String fieldName)Returns the value from the field associated withfieldNamespecified as an argument.inthashCode()RinvokeMethod(String methodName)Invokes the indicated method by reflection.ReflectionTestHelper<T,R>setFieldValue(@NonNull String fieldName, Object fieldValue)SetfieldValueto the field associated withfieldNamespecified as an argument.StringtoString()
-
メソッドの詳細
-
from
Returns the new instance ofReflectionTestHelperbased on the argument.- 型パラメータ:
T- The type of SUTR- The type returned by the method to be invoked- パラメータ:
clazz- The class in which the method to be invoked is defined- 戻り値:
- The new instance of
ReflectionTestHelper - 例外:
NullPointerException- Ifnullis passed as an argument
-
setFieldValue
public ReflectionTestHelper<T,R> setFieldValue(@NonNull @NonNull String fieldName, Object fieldValue)SetfieldValueto the field associated withfieldNamespecified as an argument.- パラメータ:
fieldName- The field name to be processed for reflectionfieldValue- The value to be set to the field by reflection- 戻り値:
- This instance
- 例外:
IllegalStateException- If an error occurs in the reflection process
-
getFieldValue
Returns the value from the field associated withfieldNamespecified as an argument.- パラメータ:
fieldName- The field name to be processed for reflection- 戻り値:
- The value retrieved from the field by reflection
- 例外:
IllegalStateException- If an error occurs in the reflection process
-
invokeMethod
Invokes the indicated method by reflection. The value defined in the target method to be called in the reflection will be returned.- パラメータ:
methodName- The method name to invoked by reflection- 戻り値:
- The value returned from the method name executed in the reflection process
- 例外:
IllegalArgumentException- If the argumentmethodNameisnullor emptyIllegalStateException- If an error occurs in the reflection process
-
addArgument
public ReflectionTestHelper<T,R> addArgument(@NonNull @NonNull Class<?> argumentType, Object argumentValue)Adds the argument types and values defined for the target method to be invoked in reflection. Argument types are not allowed to benull, but argument values are allowed to benull.- パラメータ:
argumentType- The type of argumentargumentValue- The value of argument- 戻り値:
- this instance
- 例外:
NullPointerException- If the argumentargumentTypeis null
-
toString
-
equals
-
hashCode
public int hashCode()
-