パッケージ org.thinkit.test.util

クラス ReflectionTestHelper<T,​R>

java.lang.Object
org.thinkit.test.util.ReflectionTestHelper<T,​R>
すべての実装されたインタフェース:
Serializable

public final class ReflectionTestHelper<T,​R>
extends Object
implements Serializable
The class that defines a function that makes it easier to use the reflection process when calling methods with private access modifiers. The functionality of this class was created specifically for external calls to private methods when testing a particular class.

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
関連項目:
直列化された形式
  • メソッドの詳細

    • from

      public static <T,​ R> ReflectionTestHelper<T,​R> from​(@NonNull @NonNull Class<?> clazz)
      Returns the new instance of ReflectionTestHelper based on the argument.
      型パラメータ:
      T - The type of SUT
      R - 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 - If null is passed as an argument
    • setFieldValue

      public ReflectionTestHelper<T,​R> setFieldValue​(@NonNull @NonNull String fieldName, Object fieldValue)
      Set fieldValue to the field associated with fieldName specified as an argument.
      パラメータ:
      fieldName - The field name to be processed for reflection
      fieldValue - The value to be set to the field by reflection
      戻り値:
      This instance
      例外:
      IllegalStateException - If an error occurs in the reflection process
    • getFieldValue

      public Object getFieldValue​(@NonNull @NonNull String fieldName)
      Returns the value from the field associated with fieldName specified 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

      public R invokeMethod​(String methodName)
      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 argument methodName is null or empty
      IllegalStateException - 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 be null , but argument values are allowed to be null .
      パラメータ:
      argumentType - The type of argument
      argumentValue - The value of argument
      戻り値:
      this instance
      例外:
      NullPointerException - If the argument argumentType is null
    • toString

      public String toString()
      オーバーライド:
      toString クラス内 Object
    • equals

      public boolean equals​(Object o)
      オーバーライド:
      equals クラス内 Object
    • hashCode

      public int hashCode()
      オーバーライド:
      hashCode クラス内 Object