Package org.junit.runners.model
Class TestClass
- java.lang.Object
-
- org.junit.runners.model.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classTestClass.FieldComparatorCompares two fields by its name.private static classTestClass.MethodComparatorCompares two methods by its name.
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Class<?>clazzprivate static TestClass.FieldComparatorFIELD_COMPARATORprivate java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,java.util.List<FrameworkField>>fieldsForAnnotationsprivate static TestClass.MethodComparatorMETHOD_COMPARATORprivate java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,java.util.List<FrameworkMethod>>methodsForAnnotations
-
Constructor Summary
Constructors Constructor Description TestClass(java.lang.Class<?> clazz)Creates aTestClasswrappingclazz.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static <T extends FrameworkMember<T>>
voidaddToAnnotationLists(T member, java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,java.util.List<T>> map)<T> voidcollectAnnotatedFieldValues(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> voidcollectAnnotatedMethodValues(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.private <T> java.util.List<T>collectValues(java.util.Map<?,java.util.List<T>> map)booleanequals(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 withannotationClass.<T> java.util.List<T>getAnnotatedFieldValues(java.lang.Object test, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass, java.lang.Class<T> valueClass)private static <T> java.util.List<T>getAnnotatedMembers(java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,java.util.List<T>> map, java.lang.Class<? extends java.lang.annotation.Annotation> type, boolean fillIfAbsent)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 withannotationClass.<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>
TgetAnnotation(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 classjava.lang.Class<?>getJavaClass()Returns the underlying Java class.java.lang.StringgetName()Returns the class's name.java.lang.reflect.Constructor<?>getOnlyConstructor()Returns the only public constructor in the class, or throws anAssertionErrorif there are more or less than one.private static java.lang.reflect.Field[]getSortedDeclaredFields(java.lang.Class<?> clazz)private static java.util.List<java.lang.Class<?>>getSuperClasses(java.lang.Class<?> testClass)inthashCode()booleanisANonStaticInnerClass()booleanisPublic()private static <T extends FrameworkMember<T>>
java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,java.util.List<T>>makeDeeplyUnmodifiable(java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,java.util.List<T>> source)private static booleanrunsTopToBottom(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)protected voidscanAnnotatedMembers(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)
-
-
-
Field Detail
-
FIELD_COMPARATOR
private static final TestClass.FieldComparator FIELD_COMPARATOR
-
METHOD_COMPARATOR
private static final TestClass.MethodComparator METHOD_COMPARATOR
-
clazz
private final java.lang.Class<?> clazz
-
methodsForAnnotations
private final java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,java.util.List<FrameworkMethod>> methodsForAnnotations
-
fieldsForAnnotations
private final java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,java.util.List<FrameworkField>> fieldsForAnnotations
-
-
Constructor Detail
-
TestClass
public TestClass(java.lang.Class<?> clazz)
Creates aTestClasswrappingclazz. 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 ofTestClasswhere 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)
-
getSortedDeclaredFields
private static java.lang.reflect.Field[] getSortedDeclaredFields(java.lang.Class<?> clazz)
-
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)
-
makeDeeplyUnmodifiable
private static <T extends FrameworkMember<T>> java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,java.util.List<T>> makeDeeplyUnmodifiable(java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,java.util.List<T>> source)
-
getAnnotatedMethods
public java.util.List<FrameworkMethod> getAnnotatedMethods()
Returns, efficiently, all the non-overridden methods in this class and its superclasses that are annotated}.- Since:
- 4.12
-
getAnnotatedMethods
public 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 withannotationClass.
-
getAnnotatedFields
public java.util.List<FrameworkField> getAnnotatedFields()
Returns, efficiently, all the non-overridden fields in this class and its superclasses that are annotated.- Since:
- 4.12
-
getAnnotatedFields
public 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 withannotationClass.
-
collectValues
private <T> java.util.List<T> collectValues(java.util.Map<?,java.util.List<T>> map)
-
getAnnotatedMembers
private static <T> java.util.List<T> getAnnotatedMembers(java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,java.util.List<T>> map, java.lang.Class<? extends java.lang.annotation.Annotation> type, boolean fillIfAbsent)
-
runsTopToBottom
private static boolean runsTopToBottom(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
-
getSuperClasses
private static java.util.List<java.lang.Class<?>> getSuperClasses(java.lang.Class<?> testClass)
-
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 anAssertionErrorif there are more or less than one.
-
getAnnotations
public java.lang.annotation.Annotation[] getAnnotations()
Returns the annotations on this class- Specified by:
getAnnotationsin interfaceAnnotatable
-
getAnnotation
public <T extends java.lang.annotation.Annotation> T getAnnotation(java.lang.Class<T> annotationType)
Description copied from interface:AnnotatableReturns the annotation on the model element of the given type, or @code{null}- Specified by:
getAnnotationin interfaceAnnotatable
-
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
-
isPublic
public boolean isPublic()
-
isANonStaticInnerClass
public boolean isANonStaticInnerClass()
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
-