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 Object implements DiscoverySelector
A 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:
  • Method Details

    • getClassLoader

      @API(status=EXPERIMENTAL, since="1.10") public ClassLoader getClassLoader()
      Get the ClassLoader used to load the specified class.
      Returns:
      the ClassLoader; potentially null
      Since:
      1.10
    • getClassName

      public String getClassName()
      Get the selected class name.
    • getMethodName

      public String getMethodName()
      Get the selected method name.
    • getMethodParameterTypes

      @Deprecated @API(status=DEPRECATED, since="1.10") public String getMethodParameterTypes()
      Deprecated.
      since 1.10 in favor of getParameterTypeNames()
      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

      @API(status=STABLE, since="1.10") public 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.

      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 a Method or parameter types supplied via a constructor; never null but potentially an empty string
      Since:
      1.10
      See Also:
    • getJavaClass

      public Class<?> getJavaClass()
      Get the 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.

      See Also:
    • getJavaMethod

      public Method getJavaMethod()
      Get the selected 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.

      See Also:
    • getParameterTypes

      @API(status=EXPERIMENTAL, since="1.10") public 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 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.

      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:
    • equals

      @API(status=STABLE, since="1.3") public boolean equals(Object o)
      Overrides:
      equals in class Object
      Since:
      1.3
    • hashCode

      @API(status=STABLE, since="1.3") public int hashCode()
      Overrides:
      hashCode in class Object
      Since:
      1.3
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toIdentifier

      public Optional<DiscoverySelectorIdentifier> toIdentifier()
      Description copied from interface: DiscoverySelector
      Return 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:
      toIdentifier in interface DiscoverySelector
      Returns:
      an Optional containing the identifier of this selector; never null but potentially empty if the selector does not support identifiers