@API(status=STABLE,
since="1.0")
public class MethodSelector
extends java.lang.Object
implements DiscoverySelector
DiscoverySelector that selects a Method or a combination of
class name, method name, and parameter types so that
TestEngines can discover tests
or containers based on methods.
If a Java Method is provided, the selector will return that
method and its method name, class name, and
parameter types accordingly. If a Class and method name, a class name
and method name, or a fully qualified method name is provided,
this selector will only attempt to lazily load the class, method, or parameter
types if getJavaClass(), getJavaMethod(), or
getParameterTypes() is invoked.
In this context, a Java Method means anything that can be referenced
as a Method on the JVM — for example, methods from Java classes
or methods from other JVM languages such Groovy, Scala, etc.
DiscoverySelectors.selectMethod(String),
DiscoverySelectors.selectMethod(String, String),
DiscoverySelectors.selectMethod(String, String, String),
DiscoverySelectors.selectMethod(Class, String),
DiscoverySelectors.selectMethod(Class, String, String),
DiscoverySelectors.selectMethod(Class, Method),
MethodSource| Modifier and Type | Field and Description |
|---|---|
private java.lang.ClassLoader |
classLoader |
private java.lang.String |
className |
private java.lang.Class<?> |
javaClass |
private java.lang.reflect.Method |
javaMethod |
private java.lang.String |
methodName |
private java.lang.String |
parameterTypeNames |
private java.lang.Class<?>[] |
parameterTypes |
| Constructor and Description |
|---|
MethodSelector(java.lang.Class<?> javaClass,
java.lang.reflect.Method method) |
MethodSelector(java.lang.Class<?> javaClass,
java.lang.String methodName,
java.lang.Class<?>... parameterTypes) |
MethodSelector(java.lang.Class<?> javaClass,
java.lang.String methodName,
java.lang.String parameterTypeNames) |
MethodSelector(java.lang.ClassLoader classLoader,
java.lang.String className,
java.lang.String methodName,
java.lang.Class<?>... parameterTypes) |
MethodSelector(java.lang.ClassLoader classLoader,
java.lang.String className,
java.lang.String methodName,
java.lang.String parameterTypeNames) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(java.lang.Object o) |
java.lang.ClassLoader |
getClassLoader()
Get the
ClassLoader used to load the specified class. |
java.lang.String |
getClassName()
Get the selected class name.
|
java.lang.Class<?> |
getJavaClass()
Get the
Class in which the selected method is declared, or a subclass thereof. |
java.lang.reflect.Method |
getJavaMethod()
Get the selected
Method. |
java.lang.String |
getMethodName()
Get the selected method name.
|
java.lang.String |
getMethodParameterTypes()
Deprecated.
since 1.10 in favor of
getParameterTypeNames() |
java.lang.String |
getParameterTypeNames()
Get the names of parameter types for the selected method as a
String,
typically a comma-separated list of primitive types, fully qualified class
names, or array types. |
java.lang.Class<?>[] |
getParameterTypes()
Get the parameter types for the selected method.
|
int |
hashCode() |
private void |
lazyLoadJavaClass() |
private void |
lazyLoadJavaMethod() |
private void |
lazyLoadParameterTypes() |
java.lang.String |
toString() |
private final java.lang.ClassLoader classLoader
private final java.lang.String className
private final java.lang.String methodName
private final java.lang.String parameterTypeNames
private volatile java.lang.Class<?> javaClass
private volatile java.lang.reflect.Method javaMethod
private volatile java.lang.Class<?>[] parameterTypes
MethodSelector(java.lang.ClassLoader classLoader,
java.lang.String className,
java.lang.String methodName,
java.lang.String parameterTypeNames)
MethodSelector(java.lang.Class<?> javaClass,
java.lang.String methodName,
java.lang.String parameterTypeNames)
MethodSelector(java.lang.ClassLoader classLoader,
java.lang.String className,
java.lang.String methodName,
java.lang.Class<?>... parameterTypes)
MethodSelector(java.lang.Class<?> javaClass,
java.lang.String methodName,
java.lang.Class<?>... parameterTypes)
MethodSelector(java.lang.Class<?> javaClass,
java.lang.reflect.Method method)
@API(status=EXPERIMENTAL,
since="1.10")
public java.lang.ClassLoader getClassLoader()
ClassLoader used to load the specified class.ClassLoader; potentially nullpublic java.lang.String getClassName()
public java.lang.String getMethodName()
@Deprecated
@API(status=DEPRECATED,
since="1.10")
public java.lang.String getMethodParameterTypes()
getParameterTypeNames()See getParameterTypeNames() for details.
getParameterTypeNames(),
getParameterTypes()@API(status=STABLE,
since="1.10")
public java.lang.String getParameterTypeNames()
String,
typically a comma-separated list of primitive types, fully qualified class
names, or array types.
Note: the names of parameter types are provided as a single string instead of a collection in order to allow this selector to be used in a generic fashion by various test engines. It is therefore the responsibility of the caller of this method to determine how to parse the returned string.
MethodSelector
via a constructor or deduced from a Method or parameter types supplied
via a constructor; never null but potentially an empty stringgetParameterTypes()public java.lang.Class<?> getJavaClass()
Class in which the selected method is declared, or a subclass thereof.
If the Class was not provided, but only the name, this method
attempts to lazily load the Class based on its name and throws a
PreconditionViolationException if the class cannot be loaded.
getJavaMethod()public java.lang.reflect.Method getJavaMethod()
Method.
If the Method was not provided, but only the name, this method
attempts to lazily load the Method based on its name and throws a
PreconditionViolationException if the method cannot be loaded.
getJavaClass()@API(status=EXPERIMENTAL,
since="1.10")
public java.lang.Class<?>[] getParameterTypes()
If the parameter types were not provided as Class references
(or could not be deduced as Class references in the constructor),
this method attempts to lazily load the class reference for each parameter
type based on its name and throws a JUnitException if the class
cannot be loaded.
null but potentially
an empty array if the selected method does not declare parametersgetParameterTypeNames(),
Method.getParameterTypes()private void lazyLoadJavaClass()
private void lazyLoadJavaMethod()
private void lazyLoadParameterTypes()
@API(status=STABLE,
since="1.3")
public boolean equals(java.lang.Object o)
equals in class java.lang.Object@API(status=STABLE,
since="1.3")
public int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Object