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 java.lang.Object implements DiscoverySelectorADiscoverySelectorthat selects the name of a classpath resource so thatTestEnginescan 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:
DiscoverySelectors.selectClasspathResource(String),ClasspathRootSelector,getClasspathResourceName()
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classClasspathResourceSelector.IdentifierParser
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringclasspathResourceNameprivate FilePositionpositionprivate java.util.Set<org.junit.platform.commons.io.Resource>resources
-
Constructor Summary
Constructors Constructor Description ClasspathResourceSelector(java.lang.String classpathResourceName, FilePosition position)ClasspathResourceSelector(java.util.Set<? extends org.junit.platform.commons.io.Resource> resources)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleanequals(java.lang.Object o)java.lang.StringgetClasspathResourceName()Get the name of the selected classpath resource.java.util.Set<org.junit.platform.commons.support.Resource>getClasspathResources()Deprecated.Please use {getResources()} instead.java.util.Optional<FilePosition>getPosition()Get the selectedFilePositionwithin the classpath resource.java.util.Set<org.junit.platform.commons.io.Resource>getResources()Get the selectedresources.inthashCode()java.util.Optional<DiscoverySelectorIdentifier>toIdentifier()Return the identifier of this selector.java.lang.StringtoString()
-
-
-
Field Detail
-
classpathResourceName
private final java.lang.String classpathResourceName
-
position
private final FilePosition position
-
resources
private java.util.Set<org.junit.platform.commons.io.Resource> resources
-
-
Constructor Detail
-
ClasspathResourceSelector
ClasspathResourceSelector(java.lang.String classpathResourceName, FilePosition position)
-
ClasspathResourceSelector
ClasspathResourceSelector(java.util.Set<? extends org.junit.platform.commons.io.Resource> resources)
-
-
Method Detail
-
getClasspathResourceName
public java.lang.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:
ClassLoader.getResource(String),ClassLoader.getResourceAsStream(String),ClassLoader.getResources(String)
-
getClasspathResources
@API(status=DEPRECATED, since="1.14") @Deprecated public java.util.Set<org.junit.platform.commons.support.Resource> getClasspathResources()Deprecated.Please use {getResources()} instead.Get the selectedresources.If the
resourceswere not provided, but only their name, this method attempts to lazily load theresourcesbased on their name and throws aPreconditionViolationExceptionif the resource cannot be loaded.- Since:
- 1.12
-
getResources
@API(status=MAINTAINED, since="1.14") public java.util.Set<org.junit.platform.commons.io.Resource> getResources()Get the selectedresources.If the
resourceswere not provided, but only their name, this method attempts to lazily load theresourcesbased on their name and throws aPreconditionViolationExceptionif the resource cannot be loaded.- Since:
- 1.14
-
getPosition
public java.util.Optional<FilePosition> getPosition()
Get the selectedFilePositionwithin the classpath resource.
-
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
-
-