Class TestClass

  • All Implemented Interfaces:
    Annotatable

    public class TestClass
    extends java.lang.Object
    implements Annotatable
    Wraps a class to be run, providing method validation and annotation searching
    Since:
    4.5
    • Constructor Summary

      Constructors 
      Constructor Description
      TestClass​(java.lang.Class<?> clazz)
      Creates a TestClass wrapping clazz.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected static <T extends FrameworkMember<T>>
      void
      addToAnnotationLists​(T member, java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,​java.util.List<T>> map)  
      <T> void collectAnnotatedFieldValues​(java.lang.Object test, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass, java.lang.Class<T> valueClass, MemberValueConsumer<T> consumer)
      Finds the fields annotated with the specified annotation and having the specified type, retrieves the values and passes those to the specified consumer.
      <T> void collectAnnotatedMethodValues​(java.lang.Object test, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass, java.lang.Class<T> valueClass, MemberValueConsumer<T> consumer)
      Finds the methods annotated with the specified annotation and returning the specified type, invokes it and pass the return value to the specified consumer.
      boolean equals​(java.lang.Object obj)  
      java.util.List<FrameworkField> getAnnotatedFields()
      Returns, efficiently, all the non-overridden fields in this class and its superclasses that are annotated.
      java.util.List<FrameworkField> getAnnotatedFields​(java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
      Returns, efficiently, all the non-overridden fields in this class and its superclasses that are annotated with annotationClass.
      <T> java.util.List<T> getAnnotatedFieldValues​(java.lang.Object test, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass, java.lang.Class<T> valueClass)  
      java.util.List<FrameworkMethod> getAnnotatedMethods()
      Returns, efficiently, all the non-overridden methods in this class and its superclasses that are annotated}.
      java.util.List<FrameworkMethod> getAnnotatedMethods​(java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
      Returns, efficiently, all the non-overridden methods in this class and its superclasses that are annotated with annotationClass.
      <T> java.util.List<T> getAnnotatedMethodValues​(java.lang.Object test, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass, java.lang.Class<T> valueClass)  
      <T extends java.lang.annotation.Annotation>
      T
      getAnnotation​(java.lang.Class<T> annotationType)
      Returns the annotation on the model element of the given type, or @code{null}
      java.lang.annotation.Annotation[] getAnnotations()
      Returns the annotations on this class
      java.lang.Class<?> getJavaClass()
      Returns the underlying Java class.
      java.lang.String getName()
      Returns the class's name.
      java.lang.reflect.Constructor<?> getOnlyConstructor()
      Returns the only public constructor in the class, or throws an AssertionError if there are more or less than one.
      int hashCode()  
      boolean isANonStaticInnerClass()  
      boolean isPublic()  
      protected void scanAnnotatedMembers​(java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,​java.util.List<FrameworkMethod>> methodsForAnnotations, java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,​java.util.List<FrameworkField>> fieldsForAnnotations)  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • TestClass

        public TestClass​(java.lang.Class<?> clazz)
        Creates a TestClass wrapping clazz. Each time this constructor executes, the class is scanned for annotations, which can be an expensive process (we hope in future JDK's it will not be.) Therefore, try to share instances of TestClass where possible.
    • Method Detail

      • scanAnnotatedMembers

        protected void scanAnnotatedMembers​(java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,​java.util.List<FrameworkMethod>> methodsForAnnotations,
                                            java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,​java.util.List<FrameworkField>> fieldsForAnnotations)
      • addToAnnotationLists

        protected static <T extends FrameworkMember<T>> void addToAnnotationLists​(T member,
                                                                                  java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,​java.util.List<T>> map)
      • getAnnotatedMethods

        public java.util.List<FrameworkMethodgetAnnotatedMethods()
        Returns, efficiently, all the non-overridden methods in this class and its superclasses that are annotated}.
        Since:
        4.12
      • getAnnotatedMethods

        public java.util.List<FrameworkMethodgetAnnotatedMethods​(java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
        Returns, efficiently, all the non-overridden methods in this class and its superclasses that are annotated with annotationClass.
      • getAnnotatedFields

        public java.util.List<FrameworkFieldgetAnnotatedFields()
        Returns, efficiently, all the non-overridden fields in this class and its superclasses that are annotated.
        Since:
        4.12
      • getAnnotatedFields

        public java.util.List<FrameworkFieldgetAnnotatedFields​(java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
        Returns, efficiently, all the non-overridden fields in this class and its superclasses that are annotated with annotationClass.
      • getJavaClass

        public java.lang.Class<?> getJavaClass()
        Returns the underlying Java class.
      • getName

        public java.lang.String getName()
        Returns the class's name.
      • getOnlyConstructor

        public java.lang.reflect.Constructor<?> getOnlyConstructor()
        Returns the only public constructor in the class, or throws an AssertionError if there are more or less than one.
      • getAnnotation

        public <T extends java.lang.annotation.Annotation> T getAnnotation​(java.lang.Class<T> annotationType)
        Description copied from interface: Annotatable
        Returns the annotation on the model element of the given type, or @code{null}
        Specified by:
        getAnnotation in interface Annotatable
      • getAnnotatedFieldValues

        public <T> java.util.List<T> getAnnotatedFieldValues​(java.lang.Object test,
                                                             java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass,
                                                             java.lang.Class<T> valueClass)
      • collectAnnotatedFieldValues

        public <T> void collectAnnotatedFieldValues​(java.lang.Object test,
                                                    java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass,
                                                    java.lang.Class<T> valueClass,
                                                    MemberValueConsumer<T> consumer)
        Finds the fields annotated with the specified annotation and having the specified type, retrieves the values and passes those to the specified consumer.
        Since:
        4.13
      • getAnnotatedMethodValues

        public <T> java.util.List<T> getAnnotatedMethodValues​(java.lang.Object test,
                                                              java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass,
                                                              java.lang.Class<T> valueClass)
      • collectAnnotatedMethodValues

        public <T> void collectAnnotatedMethodValues​(java.lang.Object test,
                                                     java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass,
                                                     java.lang.Class<T> valueClass,
                                                     MemberValueConsumer<T> consumer)
        Finds the methods annotated with the specified annotation and returning the specified type, invokes it and pass the return value to the specified consumer.
        Since:
        4.13
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object