Class ClassSelector

java.lang.Object
org.junit.platform.engine.discovery.ClassSelector
All Implemented Interfaces:
DiscoverySelector

@API(status=STABLE, since="1.0") public class ClassSelector extends Object implements DiscoverySelector
A DiscoverySelector that selects a Class or class name so that TestEngines can discover tests or containers based on classes.

If a Java Class reference is provided, the selector will return that Class and its class name accordingly. If a class name is provided, the selector will only attempt to lazily load the Class if getJavaClass() is invoked.

In this context, Java Class means anything that can be referenced as a Class on the JVM — for example, classes 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 selected class.
      Returns:
      the ClassLoader; potentially null
      Since:
      1.10
    • getClassName

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

      public Class<?> getJavaClass()
      Get the selected Class.

      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.

    • 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 has to be parsable by a corresponding DiscoverySelectorIdentifierParser.

      Specified by:
      toIdentifier in interface DiscoverySelector
      Returns:
      the identifier of this selector or empty if it is not supported; never null