Class MethodSelector
- All Implemented Interfaces:
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.
- Since:
- 1.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class -
Method Summary
Modifier and TypeMethodDescriptionboolean@Nullable ClassLoaderGet theClassLoaderused to load the specified class.Get the selected class name.Class<?> Get the selectedMethod.Get the selected method name.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.Class<?>[]Get the parameter types for the selected method.inthashCode()Return the identifier of this selector.toString()
-
Method Details
-
getClassLoader
Get theClassLoaderused to load the specified class.- Returns:
- the
ClassLoader; potentiallynull - Since:
- 1.10
-
getClassName
Get the selected class name. -
getMethodName
Get the selected method name. -
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:
-
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
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:
-
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:
-
equals
-
hashCode
-
toString
-
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
-