ReflectionSupport provides static utility methods for common
reflection tasks — for example, scanning for classes in the class-path
or module-path, loading classes, finding methods, invoking methods, etc.
TestEngine and extension
authors are encouraged to use these supported methods in order to align with
the behavior of the JUnit Platform.
AnnotationSupport, ClassSupport, ModifierSupport, ResourceSupport
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static List | Returns: an immutable list of all such classes found; nevernull
but potentially emptythe URI for the classpath root in which to scan; never
root, Predicate<Class<?>> nullthe class type filter; never classFilter, Predicate<String> nullthe class name filter; never classNameFilter)nullFind all classes in the supplied classpath |
| public static List | Returns: an immutable list of all such classes found; nevernull
but potentially emptythe name of the module to scan; never moduleName, Predicate<Class<?>> null or
emptythe class type filter; never classFilter, Predicate<String> nullthe class name filter; never classNameFilter)nullFind all classes in the supplied |
| public static List | Returns: an immutable list of all such classes found; nevernull
but potentially emptythe name of the base package in which to start
scanning; must not be basePackageName, Predicate<Class<?>> null and must be valid in terms of Java
syntaxthe class type filter; never classFilter, Predicate<String> nullthe class name filter; never classNameFilter)nullFind all classes in the supplied |
| public static List | Returns: an immutable list of all such resources found; nevernull
but potentially emptythe URI for the classpath root in which to scan; never
root, Predicate<Resource> nullthe resource type filter; never resourceFilter)null
Deprecated
for removal since 1.14. Please use
ResourceSupport#findAllResourcesInClasspathRoot(URI, ResourceFilter) instead
Find all resources in the supplied classpath |
| public static List | Returns: an immutable list of all such resources found; nevernull
but potentially emptythe name of the module to scan; never moduleName, Predicate<Resource> null or
emptythe resource type filter; never resourceFilter)null
Deprecated
for removal since 1.14. Please use
ResourceSupport#findAllResourcesInModule(String, ResourceFilter) instead
Find all resources in the supplied |
| public static List | Returns: an immutable list of all such classes found; nevernull
but potentially emptythe name of the base package in which to start
scanning; must not be basePackageName, Predicate<Resource> null and must be valid in terms of Java
syntaxthe resource type filter; never resourceFilter)null
Deprecated
for removal since 1.14. Please use
ResourceSupport#findAllResourcesInPackage(String, ResourceFilter) instead
Find all resources in the supplied |
| public static List | Returns: an immutable list of all such fields found; nevernull
but potentially emptythe class or interface in which to find the fields; never clazz, Predicate<Field> nullthe field filter; never predicate, HierarchyTraversalMode nullthe hierarchy traversal mode; never traversalMode)nullFind all distinct fields of the supplied class or
interface that match the specified |
| public static Optional | Returns: anOptional containing the method found; never null
but potentially empty if no such method could be foundthe class or interface in which to find the method; never clazz, String nullthe name of the method to find; never methodName, @Nullable String null or emptythe fully qualified names of the types of parameters
accepted by the method, if any, provided as a comma-separated list parameterTypeNames)Find the first |
| public static Optional | Returns: anOptional containing the method found; never null
but potentially empty if no such method could be foundthe class or interface in which to find the method; never clazz, String nullthe name of the method to find; never methodName, Class<?>... null or emptythe types of parameters accepted by the method, if any;
never parameterTypes)nullFind the first |
| public static List | Returns: an immutable list of all such methods found; nevernull
but potentially emptythe class or interface in which to find the methods; never clazz, Predicate<Method> nullthe method filter; never predicate, HierarchyTraversalMode nullthe hierarchy traversal mode; never traversalMode)nullFind all distinct methods of the supplied class or
interface that match the specified |
| public static List | Returns: an immutable list of all such classes found; nevernull
but potentially emptythe class to be searched; never clazz, Predicate<Class<?>> nullthe predicate against which the list of nested classes is
checked; never predicate)nullFind all nested classes within the supplied class, or inherited by the supplied class, that conform to the supplied predicate. |
| public static @Nullable Object | Returns: the value returned by the method invocation ornull
if the return type is voidthe method to invoke; never method, @Nullable Object nullthe object on which to invoke the method; may be
target, @Nullable Object... null if the method is staticthe arguments to pass to the method; never args)nullInvoke the supplied method, making it accessible if necessary and masking any checked exception as an unchecked exception. |
| public static Field | Returns: the supplied fieldthe field to make accessible; never field)nullMake the supplied field accessible via reflection. |
| public static <T> T | Returns: the new instance; nevernullthe class to instantiate; never clazz, Object... nullthe arguments to pass to the constructor, none of which may
be args)nullCreate a new instance of the specified |
| public static Stream | Returns: a stream of all such classes found; nevernull
but potentially emptythe URI for the classpath root in which to scan; never
root, Predicate<Class<?>> nullthe class type filter; never classFilter, Predicate<String> nullthe class name filter; never classNameFilter)nullFind all classes in the supplied classpath |
| public static Stream | Returns: a stream of all such classes found; nevernull
but potentially emptythe name of the module to scan; never moduleName, Predicate<Class<?>> null or
emptythe class type filter; never classFilter, Predicate<String> nullthe class name filter; never classNameFilter)nullFind all classes in the supplied |
| public static Stream | Returns: a stream of all such classes found; nevernull
but potentially emptythe name of the base package in which to start
scanning; must not be basePackageName, Predicate<Class<?>> null and must be valid in terms of Java
syntaxthe class type filter; never classFilter, Predicate<String> nullthe class name filter; never classNameFilter)nullFind all classes in the supplied |
| public static Stream | Returns: a stream of all such classes found; nevernull
but potentially emptythe URI for the classpath root in which to scan; never
root, Predicate<Resource> nullthe resource type filter; never resourceFilter)null
Deprecated
for removal since 1.14. Please use
ResourceSupport#streamAllResourcesInClasspathRoot(URI, ResourceFilter) instead
Find all resources in the supplied classpath |
| public static Stream | Returns: a stream of all such resources found; nevernull
but potentially emptythe name of the module to scan; never moduleName, Predicate<Resource> null or
emptythe resource type filter; never resourceFilter)null
Deprecated
for removal since 1.14. Please use
ResourceSupport#streamAllResourcesInModule(String, ResourceFilter) instead
Find all resources in the supplied |
| public static Stream | Returns: a stream of all such resources found; nevernull
but potentially emptythe name of the base package in which to start
scanning; must not be basePackageName, Predicate<Resource> null and must be valid in terms of Java
syntaxthe resource type filter; never resourceFilter)null
Deprecated
for removal since 1.14. Please use
ResourceSupport#streamAllResourcesInPackage(String, ResourceFilter) instead
Find all resources in the supplied |
| public static Stream | Returns: a stream of all such fields found; nevernull
but potentially emptythe class or interface in which to find the fields; never clazz, Predicate<Field> nullthe field filter; never predicate, HierarchyTraversalMode nullthe hierarchy traversal mode; never traversalMode)nullFind all distinct fields of the supplied class or
interface that match the specified |
| public static Stream | Returns: a stream of all such methods found; nevernull
but potentially emptythe class or interface in which to find the methods; never clazz, Predicate<Method> nullthe method filter; never predicate, HierarchyTraversalMode nullthe hierarchy traversal mode; never traversalMode)nullFind all distinct methods of the supplied class or
interface that match the specified |
| public static Stream | Returns: a stream of all such classes found; nevernull
but potentially emptythe class to be searched; never clazz, Predicate<Class<?>> nullthe predicate against which the list of nested classes is
checked; never predicate)nullFind all nested classes within the supplied class, or inherited by the supplied class, that conform to the supplied predicate. |
| private static ResourceFilter | |
| pack-priv static List | |
| pack-priv static Set | |
| pack-priv static Stream | |
| public static Try | Returns: a successfulTry containing the set of loaded resources
(potentially empty) or a failed Try containing the exception in
case a failure occurred while trying to list resources; never
nullthe name of the resource to load; never
classpathResourceName)null or blank
Deprecated
for removal since 1.14. Please use
ResourceSupport#tryToGetResources(String) instead
Try to get the resources for the supplied classpath resource name. |
| public static Try | Returns: a successfulTry containing the set of loaded resources
(potentially empty) or a failed Try containing the exception in
case a failure occurred while trying to list resources; never
nullthe name of the resource to load; never
classpathResourceName, ClassLoader null or blankthe classLoader)ClassLoader to use; never null
Deprecated
for removal since 1.14. Please use
ResourceSupport#tryToGetResources(String, ClassLoader) instead
Try to load the resources for the supplied classpath
resource name, using the supplied |
| public static Try | Returns: a successfulTry containing the loaded class or a failed
Try containing the exception if no such class could be loaded;
never nullthe name of the class to load; never name)null or blankTry to load a class by its primitive name or fully qualified
name, using the default |
| public static Try | Returns: a successfulTry containing the loaded class or a failed
Try containing the exception if no such class could be loaded;
never nullthe name of the class to load; never name, ClassLoader null or blankthe classLoader)ClassLoader to use; never nullTry to load a class by its primitive name or fully qualified
name, using the supplied |
| public static Try | tryToReadFieldValue(Field
the field to read; never field, @Nullable Object nullthe instance from which the value is to be read; may
be instance)null for a static fieldTry to read the value of a potentially inaccessible field. |