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 the TestContext in 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)
    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 the TestContext and returns them as Stream in 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)
    static java.util.stream.Stream<java.lang.reflect.AnnotatedElement> getAnnotatedElementsInnermostFirst​(TestContext context)
    Returns a Stream of the test method (if applicable) and all classes enclosing the test class of the TestContext, innermost first.
    static java.util.stream.Stream<java.lang.Class<?>> getClassNestingInnermostFirst​(TestContext context)
    Returns a Stream of all classes enclosing the test class of the TestContext, innermost first.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 the TestContext in 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 - the TestContext to search in
      annotation - the annotation to look for
      Returns:
      the first occurrence of A in 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 the TestContext and returns them as Stream in 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 - the TestContext to search in
      annotation - the annotation to look for
      Returns:
      all occurrences of A in 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 a Stream of all classes enclosing the test class of the TestContext, innermost first.
      Parameters:
      context - the TestContext to 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 a Stream of the test method (if applicable) and all classes enclosing the test class of the TestContext, innermost first.
      Parameters:
      context - the TestContext to search in
      Returns:
      a stream containing all AnnotatedElements in order, or an empty stream if no test method/class is available