Class ClassSource
- java.lang.Object
-
- org.junit.platform.engine.support.descriptor.ClassSource
-
- All Implemented Interfaces:
Serializable
,TestSource
@API(status=STABLE, since="1.0") public class ClassSource extends Object implements TestSource
Class basedTestSource
with an optional file position.If a Java
Class
reference is provided, theClassSource
will contain thatClass
and its class name accordingly. If a class name is provided, theClassSource
will contain the class name and will only attempt to lazily load theClass
ifgetJavaClass()
is invoked.In this context, Java
Class
means anything that can be referenced as aClass
on 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 String
CLASS_SCHEME
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object o)
static ClassSource
from(Class<?> javaClass)
Create a newClassSource
using the supplied class.static ClassSource
from(Class<?> javaClass, FilePosition filePosition)
static ClassSource
from(String className)
Create a newClassSource
using the supplied class name.static ClassSource
from(String className, FilePosition filePosition)
Create a newClassSource
using the supplied class name and file position.static ClassSource
from(URI uri)
Create a newClassSource
from the suppliedURI
.String
getClassName()
Get the class name of this source.Class<?>
getJavaClass()
Get the Java class of this source.Optional<FilePosition>
getPosition()
int
hashCode()
String
toString()
-
-
-
Field Detail
-
CLASS_SCHEME
@API(status=STABLE, since="1.8") public static final String CLASS_SCHEME
- Since:
- 1.8
- See Also:
- Constant Field Values
-
-
Method Detail
-
from
public static ClassSource from(String className)
Create a newClassSource
using the supplied class name.- Parameters:
className
- the class name; must not benull
or blank
-
from
public static ClassSource from(String className, FilePosition filePosition)
Create a newClassSource
using the supplied class name and file position.- Parameters:
className
- the class name; must not benull
or blankfilePosition
- the position in the source file; may benull
-
from
public static ClassSource from(Class<?> javaClass)
Create a newClassSource
using the supplied class.- Parameters:
javaClass
- the Java class; must not benull
-
from
public static ClassSource from(Class<?> javaClass, FilePosition filePosition)
- Parameters:
javaClass
- the Java class; must not benull
filePosition
- the position in the Java source file; may benull
-
from
@API(status=STABLE, since="1.8") public static ClassSource from(URI uri)
Create a newClassSource
from the suppliedURI
.URIs should be formatted as
class:fully.qualified.class.Name
. The query component of theURI
, if present, will be used to retrieve theFilePosition
viaFilePosition.fromQuery(String)
. For example, line 42 and column 13 can be referenced in classorg.example.MyType
via the following URI:class:com.example.MyType?line=42&column=13
. The URI fragment, if present, will be ignored.- Parameters:
uri
- theURI
for the class source; nevernull
- Returns:
- a new
ClassSource
; nevernull
- Throws:
PreconditionViolationException
- if the suppliedURI
isnull
, if the scheme of the suppliedURI
is not equal to theCLASS_SCHEME
, or if the specified class name is empty- Since:
- 1.8
- See Also:
CLASS_SCHEME
-
getClassName
public final String getClassName()
Get the class name of this source.- See Also:
getJavaClass()
,getPosition()
-
getJavaClass
public final Class<?> getJavaClass()
Get the Java class of this source.If the
Class
was not provided, but only the name, this method attempts to lazily load theClass
based on its name and throws aPreconditionViolationException
if the class cannot be loaded.- See Also:
getClassName()
,getPosition()
-
getPosition
public final Optional<FilePosition> getPosition()
- See Also:
getClassName()
,getJavaClass()
-
-