Class ClassSource
- java.lang.Object
-
- org.junit.platform.engine.support.descriptor.ClassSource
-
- All Implemented Interfaces:
java.io.Serializable,TestSource
@API(status=STABLE, since="1.0") public class ClassSource extends java.lang.Object implements TestSourceClass basedTestSourcewith an optional file position.If a Java
Classreference is provided, theClassSourcewill contain thatClassand its class name accordingly. If a class name is provided, theClassSourcewill contain the class name and 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:
ClassSelector, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCLASS_SCHEMEURIscheme for class sources: "class"private java.lang.StringclassNameprivate FilePositionfilePositionprivate java.lang.Class<?>javaClassprivate static longserialVersionUID
-
Constructor Summary
Constructors Modifier Constructor Description privateClassSource(java.lang.Class<?> javaClass)privateClassSource(java.lang.Class<?> javaClass, FilePosition filePosition)privateClassSource(java.lang.String className)privateClassSource(java.lang.String className, FilePosition filePosition)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object o)static ClassSourcefrom(java.lang.Class<?> javaClass)Create a newClassSourceusing the supplied class.static ClassSourcefrom(java.lang.Class<?> javaClass, FilePosition filePosition)Create a newClassSourceusing the supplied class and file position.static ClassSourcefrom(java.lang.String className)Create a newClassSourceusing the supplied class name.static ClassSourcefrom(java.lang.String className, FilePosition filePosition)Create a newClassSourceusing the supplied class name and file position.static ClassSourcefrom(java.net.URI uri)Create a newClassSourcefrom the suppliedURI.java.lang.StringgetClassName()Get the class name of this source.java.lang.Class<?>getJavaClass()Get the Java class of this source.java.util.Optional<FilePosition>getPosition()inthashCode()java.lang.StringtoString()
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
CLASS_SCHEME
@API(status=STABLE, since="1.8") public static final java.lang.String CLASS_SCHEMEURIscheme for class sources: "class"- Since:
- 1.8
- See Also:
- Constant Field Values
-
className
private final java.lang.String className
-
filePosition
private final FilePosition filePosition
-
javaClass
private java.lang.Class<?> javaClass
-
-
Constructor Detail
-
ClassSource
private ClassSource(java.lang.String className)
-
ClassSource
private ClassSource(java.lang.String className, FilePosition filePosition)
-
ClassSource
private ClassSource(java.lang.Class<?> javaClass)
-
ClassSource
private ClassSource(java.lang.Class<?> javaClass, FilePosition filePosition)
-
-
Method Detail
-
from
public static ClassSource from(java.lang.String className)
Create a newClassSourceusing the supplied class name.- Parameters:
className- the class name; must not benullor blank
-
from
public static ClassSource from(java.lang.String className, FilePosition filePosition)
Create a newClassSourceusing the supplied class name and file position.- Parameters:
className- the class name; must not benullor blankfilePosition- the position in the source file; may benull
-
from
public static ClassSource from(java.lang.Class<?> javaClass)
Create a newClassSourceusing the supplied class.- Parameters:
javaClass- the Java class; must not benull
-
from
public static ClassSource from(java.lang.Class<?> javaClass, FilePosition filePosition)
Create a newClassSourceusing the supplied class and file position.- Parameters:
javaClass- the Java class; must not benullfilePosition- the position in the Java source file; may benull
-
from
@API(status=STABLE, since="1.8") public static ClassSource from(java.net.URI uri)Create a newClassSourcefrom the suppliedURI.URIs should be formatted as
class:fully.qualified.class.Name. The query component of theURI, if present, will be used to retrieve theFilePositionviaFilePosition.fromQuery(String). For example, line 42 and column 13 can be referenced in classorg.example.MyTypevia the following URI:class:com.example.MyType?line=42&column=13. The URI fragment, if present, will be ignored.- Parameters:
uri- theURIfor the class source; nevernull- Returns:
- a new
ClassSource; nevernull - Throws:
org.junit.platform.commons.PreconditionViolationException- if the suppliedURIisnull, if the scheme of the suppliedURIis not equal to theCLASS_SCHEME, or if the specified class name is empty- Since:
- 1.8
- See Also:
CLASS_SCHEME
-
getClassName
public final java.lang.String getClassName()
Get the class name of this source.- See Also:
getJavaClass(),getPosition()
-
getJavaClass
public final java.lang.Class<?> getJavaClass()
Get the Java class of this source.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.- See Also:
getClassName(),getPosition()
-
getPosition
public final java.util.Optional<FilePosition> getPosition()
- See Also:
getClassName(),getJavaClass()
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-