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 based TestSource with an optional file position.

If a Java Class reference is provided, the ClassSource will contain that Class and its class name accordingly. If a class name is provided, the ClassSource will contain the class name and will only attempt to lazily load the Class if getJavaClass() is invoked.

In this context, Java Class means anything that can be referenced as a Class on the JVM — for example, classes from other JVM languages such Groovy, Scala, etc.

Since:
1.0
See Also:
  • Field Details

  • Method Details

    • from

      public static ClassSource from(String className)
      Create a new ClassSource using the supplied class name.
      Parameters:
      className - the class name; must not be null or blank
    • from

      public static ClassSource from(String className, FilePosition filePosition)
      Create a new ClassSource using the supplied class name and file position.
      Parameters:
      className - the class name; must not be null or blank
      filePosition - the position in the source file; may be null
    • from

      public static ClassSource from(Class<?> javaClass)
      Create a new ClassSource using the supplied class.
      Parameters:
      javaClass - the Java class; must not be null
    • from

      public static ClassSource from(Class<?> javaClass, FilePosition filePosition)
      Create a new ClassSource using the supplied class and file position.
      Parameters:
      javaClass - the Java class; must not be null
      filePosition - the position in the Java source file; may be null
    • from

      @API(status=STABLE, since="1.8") public static ClassSource from(URI uri)
      Create a new ClassSource from the supplied URI.

      URIs should be formatted as class:fully.qualified.class.Name. The query component of the URI, if present, will be used to retrieve the FilePosition via FilePosition.fromQuery(String). For example, line 42 and column 13 can be referenced in class org.example.MyType via the following URI: class:com.example.MyType?line=42&column=13. The URI fragment, if present, will be ignored.

      Parameters:
      uri - the URI for the class source; never null
      Returns:
      a new ClassSource; never null
      Throws:
      PreconditionViolationException - if the supplied URI is null, if the scheme of the supplied URI is not equal to the CLASS_SCHEME, or if the specified class name is empty
      Since:
      1.8
      See Also:
    • getClassName

      public final String getClassName()
      Get the class name of this source.
      See Also:
    • 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 the Class based on its name and throws a PreconditionViolationException if the class cannot be loaded.

      See Also:
    • getPosition

      public final Optional<FilePosition> getPosition()
      Get the position in the source file for the associated class, if available.
      See Also:
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object