Class TestFieldUtils
- java.lang.Object
-
- ru.vyarus.dropwizard.guice.test.jupiter.env.field.TestFieldUtils
-
public final class TestFieldUtils extends java.lang.ObjectHelper 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.StringtoString(java.lang.reflect.Field field)
-
-
-
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 typeT- field (base) type- Parameters:
testClass- test classann- field annotationrequiredType- 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 typeT- 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 typeT- 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 typeT- field type- Parameters:
fields- fields to get values frominstance- 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).
-
-