Class TestClass

  • All Implemented Interfaces:
    Annotatable

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

      • TestClass

        public TestClass​(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

      • getAnnotatedMethods

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

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

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

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

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

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

        public 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 Annotation> T getAnnotation​(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> List<T> getAnnotatedFieldValues​(Object test,
                                                   Class<? extends Annotation> annotationClass,
                                                   Class<T> valueClass)
      • collectAnnotatedFieldValues

        public <T> void collectAnnotatedFieldValues​(Object test,
                                                    Class<? extends Annotation> annotationClass,
                                                    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> List<T> getAnnotatedMethodValues​(Object test,
                                                    Class<? extends Annotation> annotationClass,
                                                    Class<T> valueClass)
      • collectAnnotatedMethodValues

        public <T> void collectAnnotatedMethodValues​(Object test,
                                                     Class<? extends Annotation> annotationClass,
                                                     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
      • isPublic

        public boolean isPublic()
      • isANonStaticInnerClass

        public boolean isANonStaticInnerClass()
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object