Package de.tum.in.test.api.internal
Class TestContextUtils
java.lang.Object
de.tum.in.test.api.internal.TestContextUtils
@API(status=INTERNAL)
public final class TestContextUtils
extends java.lang.Object
Static utility methods for analyzing
TestContexts and finding
Annotations.- Author:
- Christian Femers
-
Method Summary
Modifier and Type Method Description static <A extends java.lang.annotation.Annotation>
java.util.Optional<A>findAnnotationIn(TestContext context, java.lang.Class<A> annotation)Finds the first occurrence of A in theTestContextin the following order: test method, if applicable the test class enclosing the method, if applicable (and superclasses, ifInherited) recursively: the classes enclosing the test class, if applicable (and superclasses, ifInherited)static <A extends java.lang.annotation.Annotation>
java.util.stream.Stream<A>findRepeatableAnnotationsIn(TestContext context, java.lang.Class<A> annotation)Finds all occurrences of A in theTestContextand returns them asStreamin the following order: test method, if applicable the test class enclosing the method, if applicable (and superclasses, ifInherited) recursively: the classes enclosing the test class, if applicable (and superclasses, ifInherited)static java.util.stream.Stream<java.lang.reflect.AnnotatedElement>getAnnotatedElementsInnermostFirst(TestContext context)Returns aStreamof the test method (if applicable) and all classes enclosing the test class of theTestContext, innermost first.static java.util.stream.Stream<java.lang.Class<?>>getClassNestingInnermostFirst(TestContext context)Returns aStreamof all classes enclosing the test class of theTestContext, innermost first.
-
Method Details
-
findAnnotationIn
public static <A extends java.lang.annotation.Annotation> java.util.Optional<A> findAnnotationIn(TestContext context, java.lang.Class<A> annotation)Finds the first occurrence of A in theTestContextin the following order:- test method, if applicable
- the test class enclosing the method, if applicable (and superclasses, if
Inherited) - recursively: the classes enclosing the test class, if applicable (and
superclasses, if
Inherited)
- Type Parameters:
A- The type of the annotation- Parameters:
context- theTestContextto search inannotation- the annotation to look for- Returns:
- the first occurrence of
Ain the described order as Optional, never null - See Also:
AnnotationSupport.findAnnotation(AnnotatedElement, Class)
-
findRepeatableAnnotationsIn
public static <A extends java.lang.annotation.Annotation> java.util.stream.Stream<A> findRepeatableAnnotationsIn(TestContext context, java.lang.Class<A> annotation)Finds all occurrences of A in theTestContextand returns them asStreamin the following order:- test method, if applicable
- the test class enclosing the method, if applicable (and superclasses, if
Inherited) - recursively: the classes enclosing the test class, if applicable (and
superclasses, if
Inherited)
- Type Parameters:
A- The type of the annotation- Parameters:
context- theTestContextto search inannotation- the annotation to look for- Returns:
- all occurrences of
Ain the described order as Stream, never null - See Also:
AnnotationSupport.findRepeatableAnnotations(AnnotatedElement, Class)
-
getClassNestingInnermostFirst
public static java.util.stream.Stream<java.lang.Class<?>> getClassNestingInnermostFirst(TestContext context)Returns aStreamof all classes enclosing the test class of theTestContext, innermost first.- Parameters:
context- theTestContextto search in- Returns:
- a stream containing all nested classes in order, or an empty stream if no test class is available
-
getAnnotatedElementsInnermostFirst
public static java.util.stream.Stream<java.lang.reflect.AnnotatedElement> getAnnotatedElementsInnermostFirst(TestContext context)Returns aStreamof the test method (if applicable) and all classes enclosing the test class of theTestContext, innermost first.- Parameters:
context- theTestContextto search in- Returns:
- a stream containing all
AnnotatedElements in order, or an empty stream if no test method/class is available
-