Class MethodSelector
- 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 DiscoverySelectorADiscoverySelectorthat selects aMethodor a combination of class name, method name, and parameter types so thatTestEnginescan discover tests or containers based on methods.If a Java
Methodis provided, the selector will return that method and its method name, class name, and parameter types accordingly. If aClassand 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
Methodmeans anything that can be referenced as aMethodon 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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMethodSelector.IdentifierParser
-
Field Summary
Fields Modifier and Type Field Description private java.lang.ClassLoaderclassLoaderprivate java.lang.StringclassNameprivate java.lang.Class<?>javaClassprivate java.lang.reflect.MethodjavaMethodprivate java.lang.StringmethodNameprivate java.lang.StringparameterTypeNamesprivate java.lang.Class<?>[]parameterTypes
-
Constructor Summary
Constructors Modifier Constructor Description (package private)MethodSelector(java.lang.Class<?> javaClass, java.lang.reflect.Method method)privateMethodSelector(java.lang.Class<?> javaClass, java.lang.reflect.Method method, java.lang.Class<?>... parameterTypes)(package private)MethodSelector(java.lang.Class<?> javaClass, java.lang.String methodName, java.lang.Class<?>... parameterTypes)(package private)MethodSelector(java.lang.Class<?> javaClass, java.lang.String methodName, java.lang.String parameterTypeNames)(package private)MethodSelector(java.lang.ClassLoader classLoader, java.lang.String className, java.lang.String methodName, java.lang.Class<?>... parameterTypes)(package private)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 booleanequals(java.lang.Object o)java.lang.ClassLoadergetClassLoader()Get theClassLoaderused to load the specified class.java.lang.StringgetClassName()Get the selected class name.java.lang.Class<?>getJavaClass()Get theClassin which the selected method is declared, or a subclass thereof.java.lang.reflect.MethodgetJavaMethod()Get the selectedMethod.java.lang.StringgetMethodName()Get the selected method name.java.lang.StringgetMethodParameterTypes()Deprecated.since 1.10 in favor ofgetParameterTypeNames()java.lang.StringgetParameterTypeNames()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.inthashCode()private voidlazyLoadJavaClass()private voidlazyLoadJavaMethod()private voidlazyLoadParameterTypes()java.util.Optional<DiscoverySelectorIdentifier>toIdentifier()Return the identifier of this selector.java.lang.StringtoString()
-
-
-
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)
-
MethodSelector
private MethodSelector(java.lang.Class<?> javaClass, java.lang.reflect.Method method, java.lang.Class<?>... parameterTypes)
-
-
Method Detail
-
getClassLoader
@API(status=MAINTAINED, since="1.13.3") public java.lang.ClassLoader getClassLoader()Get theClassLoaderused 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
MethodSelectorvia a constructor or deduced from aMethodor parameter types supplied via a constructor; nevernullbut potentially an empty string - Since:
- 1.10
- See Also:
getParameterTypes()
-
getJavaClass
public java.lang.Class<?> getJavaClass()
Get theClassin which the selected method is declared, or a subclass thereof.If the
Classwas not provided, but only the name, this method attempts to lazily load theClassbased on its name and throws aPreconditionViolationExceptionif the class cannot be loaded.- See Also:
getJavaMethod()
-
getJavaMethod
public java.lang.reflect.Method getJavaMethod()
Get the selectedMethod.If the
Methodwas not provided, but only the name, this method attempts to lazily load theMethodbased on its name and throws aPreconditionViolationExceptionif the method cannot be loaded.- See Also:
getJavaClass()
-
getParameterTypes
@API(status=MAINTAINED, since="1.13.3") public java.lang.Class<?>[] getParameterTypes()Get the parameter types for the selected method.If the parameter types were not provided as
Classreferences (or could not be deduced asClassreferences in the constructor), this method attempts to lazily load the class reference for each parameter type based on its name and throws aJUnitExceptionif the class cannot be loaded.- Returns:
- the method's parameter types; never
nullbut 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:
equalsin classjava.lang.Object- Since:
- 1.3
-
hashCode
@API(status=STABLE, since="1.3") public int hashCode()- Overrides:
hashCodein classjava.lang.Object- Since:
- 1.3
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
toIdentifier
public java.util.Optional<DiscoverySelectorIdentifier> toIdentifier()
Description copied from interface:DiscoverySelectorReturn the identifier of this selector.The returned identifier must be parsable by a corresponding
DiscoverySelectorIdentifierParser.The default implementation returns
Optional.empty(). Can be overridden by concrete implementations.- Specified by:
toIdentifierin interfaceDiscoverySelector- Returns:
- an
Optionalcontaining the identifier of this selector; nevernullbut potentially empty if the selector does not support identifiers
-
-