Class ClasspathResourceSelector

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

@API(status=STABLE, since="1.0") public class ClasspathResourceSelector extends Object implements DiscoverySelector
A DiscoverySelector that selects the name of a classpath resource so that TestEngines can load resources from the classpath — for example, to load XML or JSON files from the classpath, potentially within JARs.

Since engines are not expected to modify the classpath, the classpath resource represented by this selector must be on the classpath of the context class loader of the thread that uses it.

Note: Since Java 9, all resources are on the module path. Either in named or unnamed modules. These resources are also considered to be classpath resources.

Since:
1.0
See Also:
  • Method Details

    • getClasspathResourceName

      public String getClasspathResourceName()
      Get the name of the selected classpath resource.

      The name of a classpath resource must follow the semantics for resource paths as defined in ClassLoader.getResource(String).

      See Also:
    • getClasspathResources

      @API(status=DEPRECATED, since="1.14") @Deprecated public Set<org.junit.platform.commons.support.Resource> getClasspathResources()
      Deprecated.
      Please use {getResources()} instead.
      Get the selected resources.

      If the resources were not provided, but only their name, this method attempts to lazily load the resources based on their name and throws a PreconditionViolationException if the resource cannot be loaded.

      Since:
      1.12
    • getResources

      @API(status=MAINTAINED, since="1.14") public Set<org.junit.platform.commons.io.Resource> getResources()
      Get the selected resources.

      If the resources were not provided, but only their name, this method attempts to lazily load the resources based on their name and throws a PreconditionViolationException if the resource cannot be loaded.

      Since:
      1.14
    • getPosition

      public Optional<FilePosition> getPosition()
      Get the selected FilePosition within the classpath resource.
    • 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