Package org.junit.runners.model
Class TestClass
java.lang.Object
org.junit.runners.model.TestClass
- All Implemented Interfaces:
Annotatable
Wraps a class to be run, providing method validation and annotation searching
- Since:
- 4.5
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
Compares two fields by its name.private static class
Compares two methods by its name. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Class<?>
private static final TestClass.FieldComparator
private final Map<Class<? extends Annotation>,
List<FrameworkField>> private static final TestClass.MethodComparator
private final Map<Class<? extends Annotation>,
List<FrameworkMethod>> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static <T extends FrameworkMember<T>>
voidaddToAnnotationLists
(T member, Map<Class<? extends Annotation>, List<T>> map) <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.<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.private <T> List<T>
collectValues
(Map<?, List<T>> map) boolean
Returns, efficiently, all the non-overridden fields in this class and its superclasses that are annotated.getAnnotatedFields
(Class<? extends Annotation> annotationClass) Returns, efficiently, all the non-overridden fields in this class and its superclasses that are annotated withannotationClass
.<T> List<T>
getAnnotatedFieldValues
(Object test, Class<? extends Annotation> annotationClass, Class<T> valueClass) private static <T> List<T>
getAnnotatedMembers
(Map<Class<? extends Annotation>, List<T>> map, Class<? extends Annotation> type, boolean fillIfAbsent) Returns, efficiently, all the non-overridden methods in this class and its superclasses that are annotated}.getAnnotatedMethods
(Class<? extends Annotation> annotationClass) Returns, efficiently, all the non-overridden methods in this class and its superclasses that are annotated withannotationClass
.<T> List<T>
getAnnotatedMethodValues
(Object test, Class<? extends Annotation> annotationClass, Class<T> valueClass) <T extends Annotation>
TgetAnnotation
(Class<T> annotationType) Returns the annotation on the model element of the given type, or @code{null}Returns the annotations on this classClass<?>
Returns the underlying Java class.getName()
Returns the class's name.Constructor<?>
Returns the only public constructor in the class, or throws anAssertionError
if there are more or less than one.private static Field[]
getSortedDeclaredFields
(Class<?> clazz) getSuperClasses
(Class<?> testClass) int
hashCode()
boolean
boolean
isPublic()
private static <T extends FrameworkMember<T>>
Map<Class<? extends Annotation>,List<T>> makeDeeplyUnmodifiable
(Map<Class<? extends Annotation>, List<T>> source) private static boolean
runsTopToBottom
(Class<? extends Annotation> annotation) protected void
scanAnnotatedMembers
(Map<Class<? extends Annotation>, List<FrameworkMethod>> methodsForAnnotations, Map<Class<? extends Annotation>, List<FrameworkField>> fieldsForAnnotations)
-
Field Details
-
FIELD_COMPARATOR
-
METHOD_COMPARATOR
-
clazz
-
methodsForAnnotations
-
fieldsForAnnotations
-
-
Constructor Details
-
TestClass
Creates aTestClass
wrappingclazz
. 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 ofTestClass
where possible.
-
-
Method Details
-
scanAnnotatedMembers
protected void scanAnnotatedMembers(Map<Class<? extends Annotation>, List<FrameworkMethod>> methodsForAnnotations, Map<Class<? extends Annotation>, List<FrameworkField>> fieldsForAnnotations) -
getSortedDeclaredFields
-
addToAnnotationLists
protected static <T extends FrameworkMember<T>> void addToAnnotationLists(T member, Map<Class<? extends Annotation>, List<T>> map) -
makeDeeplyUnmodifiable
private static <T extends FrameworkMember<T>> Map<Class<? extends Annotation>,List<T>> makeDeeplyUnmodifiable(Map<Class<? extends Annotation>, List<T>> source) -
getAnnotatedMethods
Returns, efficiently, all the non-overridden methods in this class and its superclasses that are annotated}.- Since:
- 4.12
-
getAnnotatedMethods
Returns, efficiently, all the non-overridden methods in this class and its superclasses that are annotated withannotationClass
. -
getAnnotatedFields
Returns, efficiently, all the non-overridden fields in this class and its superclasses that are annotated.- Since:
- 4.12
-
getAnnotatedFields
Returns, efficiently, all the non-overridden fields in this class and its superclasses that are annotated withannotationClass
. -
collectValues
-
getAnnotatedMembers
private static <T> List<T> getAnnotatedMembers(Map<Class<? extends Annotation>, List<T>> map, Class<? extends Annotation> type, boolean fillIfAbsent) -
runsTopToBottom
-
getSuperClasses
-
getJavaClass
Returns the underlying Java class. -
getName
Returns the class's name. -
getOnlyConstructor
Returns the only public constructor in the class, or throws anAssertionError
if there are more or less than one. -
getAnnotations
Returns the annotations on this class- Specified by:
getAnnotations
in interfaceAnnotatable
-
getAnnotation
Description copied from interface:Annotatable
Returns the annotation on the model element of the given type, or @code{null}- Specified by:
getAnnotation
in interfaceAnnotatable
-
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() -
equals
-