- java.lang.Object
-
- org.junit.platform.engine.discovery.MethodSelector
-
- All Implemented Interfaces:
DiscoverySelector
@API(status=STABLE, since="1.0") public class MethodSelector extends java.lang.Object implements DiscoverySelector
ADiscoverySelector
that selects aMethod
or a combination of class name, method name, and parameter types so thatTestEngines
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 aClass
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 ifgetJavaClass()
,getJavaMethod()
, orgetParameterTypes()
is invoked.In this context, a Java
Method
means anything that can be referenced as aMethod
on the JVM — for example, methods from Java classes or methods from other JVM languages such Groovy, Scala, etc.- Since:
- 1.0
- See Also:
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
-
-
Field Summary
Fields Modifier and Type Field 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 Summary
Constructors Constructor 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)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
equals(java.lang.Object o)
java.lang.ClassLoader
getClassLoader()
Get theClassLoader
used to load the specified class.java.lang.String
getClassName()
Get the selected class name.java.lang.Class<?>
getJavaClass()
Get theClass
in which the selected method is declared, or a subclass thereof.java.lang.reflect.Method
getJavaMethod()
Get the selectedMethod
.java.lang.String
getMethodName()
Get the selected method name.java.lang.String
getMethodParameterTypes()
Deprecated.since 1.10 in favor ofgetParameterTypeNames()
java.lang.String
getParameterTypeNames()
Get the names of parameter types for the selected method as aString
, 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()
-
-
-
Field Detail
-
classLoader
private final java.lang.ClassLoader classLoader
-
className
private final java.lang.String className
-
methodName
private final java.lang.String methodName
-
parameterTypeNames
private final java.lang.String parameterTypeNames
-
javaClass
private volatile java.lang.Class<?> javaClass
-
javaMethod
private volatile java.lang.reflect.Method javaMethod
-
parameterTypes
private volatile java.lang.Class<?>[] parameterTypes
-
-
Constructor Detail
-
MethodSelector
MethodSelector(java.lang.ClassLoader classLoader, java.lang.String className, java.lang.String methodName, java.lang.String parameterTypeNames)
- Since:
- 1.10
-
MethodSelector
MethodSelector(java.lang.Class<?> javaClass, java.lang.String methodName, java.lang.String parameterTypeNames)
-
MethodSelector
MethodSelector(java.lang.ClassLoader classLoader, java.lang.String className, java.lang.String methodName, java.lang.Class<?>... parameterTypes)
- Since:
- 1.10
-
MethodSelector
MethodSelector(java.lang.Class<?> javaClass, java.lang.String methodName, java.lang.Class<?>... parameterTypes)
- Since:
- 1.10
-
MethodSelector
MethodSelector(java.lang.Class<?> javaClass, java.lang.reflect.Method method)
-
-
Method Detail
-
getClassLoader
@API(status=EXPERIMENTAL, since="1.10") public java.lang.ClassLoader getClassLoader()
Get theClassLoader
used to load the specified class.- Returns:
- the
ClassLoader
; potentiallynull
- Since:
- 1.10
-
getClassName
public java.lang.String getClassName()
Get the selected class name.
-
getMethodName
public java.lang.String getMethodName()
Get the selected method name.
-
getMethodParameterTypes
@Deprecated @API(status=DEPRECATED, since="1.10") public java.lang.String getMethodParameterTypes()
Deprecated.since 1.10 in favor ofgetParameterTypeNames()
Get the names of parameter types for the selected method.See
getParameterTypeNames()
for details.- Returns:
- the names of parameter types
- Since:
- 1.0
- See Also:
getParameterTypeNames()
,getParameterTypes()
-
getParameterTypeNames
@API(status=STABLE, since="1.10") public java.lang.String getParameterTypeNames()
Get the names of parameter types for the selected method as aString
, 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.
- Returns:
- the names of parameter types supplied to this
MethodSelector
via a constructor or deduced from aMethod
or parameter types supplied via a constructor; nevernull
but potentially an empty string - Since:
- 1.10
- See Also:
getParameterTypes()
-
getJavaClass
public java.lang.Class<?> getJavaClass()
Get theClass
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 theClass
based on its name and throws aPreconditionViolationException
if the class cannot be loaded.- See Also:
getJavaMethod()
-
getJavaMethod
public java.lang.reflect.Method getJavaMethod()
Get the selectedMethod
.If the
Method
was not provided, but only the name, this method attempts to lazily load theMethod
based on its name and throws aPreconditionViolationException
if the method cannot be loaded.- See Also:
getJavaClass()
-
getParameterTypes
@API(status=EXPERIMENTAL, since="1.10") public java.lang.Class<?>[] getParameterTypes()
Get the parameter types for the selected method.If the parameter types were not provided as
Class
references (or could not be deduced asClass
references in the constructor), this method attempts to lazily load the class reference for each parameter type based on its name and throws aJUnitException
if the class cannot be loaded.- Returns:
- the method's parameter types; never
null
but potentially an empty array if the selected method does not declare parameters - Since:
- 1.10
- See Also:
getParameterTypeNames()
,Method.getParameterTypes()
-
lazyLoadJavaClass
private void lazyLoadJavaClass()
-
lazyLoadJavaMethod
private void lazyLoadJavaMethod()
-
lazyLoadParameterTypes
private void lazyLoadParameterTypes()
-
equals
@API(status=STABLE, since="1.3") public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
- Since:
- 1.3
-
hashCode
@API(status=STABLE, since="1.3") public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
- Since:
- 1.3
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-