java.lang.Object
ru.vyarus.dropwizard.guice.test.jupiter.env.field.TestFieldUtils

public final class TestFieldUtils extends Object
Helper utility for search and processing annotated test fields (for test extensions implementation).
Since:
07.02.2025
  • Method Details

    • findAnnotatedFields

      public static <A extends Annotation, T> List<AnnotatedField<A,T>> findAnnotatedFields(Class<?> testClass, Class<A> ann, Class<T> requiredType)
      Search for annotated fields in test clas (including base test hierarchy). In the returned list static fields go first (sort applied).
      Type Parameters:
      A - annotation type
      T - field (base) type
      Parameters:
      testClass - test class
      ann - field annotation
      requiredType - required field type (if field is not a supertype of declared - error thrown)
      Returns:
      detected fields
    • getInheritedFields

      public static <A extends Annotation, T> List<AnnotatedField<A,T>> getInheritedFields(List<AnnotatedField<A,T>> fields)
      Filter fields, declared in base test classes (not own fields).
      Type Parameters:
      A - annotation type
      T - field type
      Parameters:
      fields - fields to filter
      Returns:
      fields not directly declared in test class
    • getTestOwnFields

      public static <A extends Annotation, T> List<AnnotatedField<A,T>> getTestOwnFields(List<AnnotatedField<A,T>> fields)
      Filter fields, declared directly in test classes (own fields).
      Type Parameters:
      A - annotation type
      T - field type
      Parameters:
      fields - fields to filter
      Returns:
      fields directly declared in test class
    • getValues

      public static <A extends Annotation, T> List<T> getValues(List<AnnotatedField<A,T>> fields, Object instance)
      Get multiple fields value at once.
      Type Parameters:
      A - annotation type
      T - field type
      Parameters:
      fields - fields to get values from
      instance - test instance (could by null for static fields)
      Returns:
      field values
    • toString

      public static String toString(Field field)
      Parameters:
      field - field
      Returns:
      string field representation with class and reduced package (for reports and logs).