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 java.lang.Object implements DiscoverySelectorADiscoverySelectorthat selects aClassor class name so thatTestEnginescan discover tests or containers based on classes.If a Java
Classreference is provided, the selector will return thatClassand its class name accordingly. If a class name is provided, the selector will only attempt to lazily load theClassifgetJavaClass()is invoked.In this context, Java
Classmeans anything that can be referenced as aClasson the JVM — for example, classes from other JVM languages such Groovy, Scala, etc.- Since:
- 1.0
- See Also:
DiscoverySelectors.selectClass(String),DiscoverySelectors.selectClass(Class),ClassSource
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classClassSelector.IdentifierParser
-
Field Summary
Fields Modifier and Type Field Description private java.lang.ClassLoaderclassLoaderprivate java.lang.StringclassNameprivate java.lang.Class<?>javaClass
-
Constructor Summary
Constructors Constructor Description ClassSelector(java.lang.Class<?> javaClass)ClassSelector(java.lang.ClassLoader classLoader, java.lang.String className)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object o)java.lang.ClassLoadergetClassLoader()Get theClassLoaderused to load the selected class.java.lang.StringgetClassName()Get the selected class name.java.lang.Class<?>getJavaClass()Get the selectedClass.inthashCode()java.util.Optional<DiscoverySelectorIdentifier>toIdentifier()Return the identifier of this selector.java.lang.StringtoString()
-
-
-
Method Detail
-
getClassLoader
@API(status=MAINTAINED, since="1.13.3") public java.lang.ClassLoader getClassLoader()Get theClassLoaderused to load the selected class.- Returns:
- the
ClassLoader; potentiallynull - Since:
- 1.10
-
getClassName
public java.lang.String getClassName()
Get the selected class name.
-
getJavaClass
public java.lang.Class<?> getJavaClass()
Get the selectedClass.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.
-
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
-
-