Class TestFieldUtils


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

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <A extends java.lang.annotation.Annotation,​T>
      java.util.List<AnnotatedField<A,​T>>
      findAnnotatedFields​(java.lang.Class<?> testClass, java.lang.Class<A> ann, java.lang.Class<T> requiredType)
      Search for annotated fields in test clas (including base test hierarchy).
      static <A extends java.lang.annotation.Annotation,​T>
      java.util.List<AnnotatedField<A,​T>>
      getInheritedFields​(java.util.List<AnnotatedField<A,​T>> fields)
      Filter fields, declared in base test classes (not own fields).
      static <A extends java.lang.annotation.Annotation,​T>
      java.util.List<AnnotatedField<A,​T>>
      getTestOwnFields​(java.util.List<AnnotatedField<A,​T>> fields)
      Filter fields, declared directly in test classes (own fields).
      static <A extends java.lang.annotation.Annotation,​T>
      java.util.List<T>
      getValues​(java.util.List<AnnotatedField<A,​T>> fields, java.lang.Object instance)
      Get multiple fields value at once.
      static java.lang.String toString​(java.lang.reflect.Field field)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • findAnnotatedFields

        public static <A extends java.lang.annotation.Annotation,​T> java.util.List<AnnotatedField<A,​T>> findAnnotatedFields​(java.lang.Class<?> testClass,
                                                                                                                                        java.lang.Class<A> ann,
                                                                                                                                        java.lang.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 java.lang.annotation.Annotation,​T> java.util.List<AnnotatedField<A,​T>> getInheritedFields​(java.util.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 java.lang.annotation.Annotation,​T> java.util.List<AnnotatedField<A,​T>> getTestOwnFields​(java.util.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 java.lang.annotation.Annotation,​T> java.util.List<T> getValues​(java.util.List<AnnotatedField<A,​T>> fields,
                                                                                                      java.lang.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 java.lang.String toString​(java.lang.reflect.Field field)
        Parameters:
        field - field
        Returns:
        string field representation with class and reduced package (for reports and logs).