@API(value=Experimental) public final class DiscoverySelectors extends Object
static factory methods for creating
DiscoverySelectors.ClasspathRootSelector,
ClasspathResourceSelector,
ClassSelector,
MethodSelector,
PackageSelector| Modifier and Type | Method and Description |
|---|---|
static ClassSelector |
selectClass(Class<?> clazz)
Create a
ClassSelector for the supplied Class. |
static ClassSelector |
selectClass(String className)
Create a
ClassSelector for the supplied class name. |
static ClasspathResourceSelector |
selectClasspathResource(String classpathResourceName)
Create a
ClasspathResourceSelector for the supplied classpath
resource name. |
static List<ClasspathRootSelector> |
selectClasspathRoots(Set<Path> directories)
Create a list of
ClasspathRootSelectors for the supplied directories. |
static DirectorySelector |
selectDirectory(File directory)
Create a
DirectorySelector for the supplied directory. |
static DirectorySelector |
selectDirectory(String path)
Create a
DirectorySelector for the supplied directory path. |
static FileSelector |
selectFile(File file)
Create a
FileSelector for the supplied file. |
static FileSelector |
selectFile(String path)
Create a
FileSelector for the supplied file path. |
static MethodSelector |
selectMethod(Class<?> javaClass,
Method method)
|
static MethodSelector |
selectMethod(Class<?> javaClass,
String methodName)
Create a
MethodSelector for the supplied Class and method name. |
static MethodSelector |
selectMethod(Class<?> javaClass,
String methodName,
String methodParameterTypes)
Create a
MethodSelector for the supplied Class, method name,
and method parameter types. |
static MethodSelector |
selectMethod(String fullyQualifiedMethodName)
Create a
MethodSelector for the supplied fully qualified
method methodName. |
static MethodSelector |
selectMethod(String className,
String methodName)
Create a
MethodSelector for the supplied class name and method name. |
static MethodSelector |
selectMethod(String className,
String methodName,
String methodParameterTypes)
Create a
MethodSelector for the supplied class name, method name,
and method parameter types. |
static List<DiscoverySelector> |
selectNames(Collection<String> names)
Deprecated.
This method will be removed in 5.0 M4; use
selectPackage(String), selectClass(String), or
selectMethod(String) instead. |
static PackageSelector |
selectPackage(String packageName)
Create a
PackageSelector for the supplied package name. |
static UniqueIdSelector |
selectUniqueId(String uniqueId)
Create a
UniqueIdSelector for the supplied unique ID. |
static UniqueIdSelector |
selectUniqueId(UniqueId uniqueId)
Create a
UniqueIdSelector for the supplied UniqueId. |
static UriSelector |
selectUri(String uri)
Create a
UriSelector for the supplied URI. |
static UriSelector |
selectUri(URI uri)
Create a
UriSelector for the supplied URI. |
public static UriSelector selectUri(String uri)
UriSelector for the supplied URI.uri - the URI to select; never null or blankUriSelector,
selectUri(URI),
selectFile(String),
selectFile(File),
selectDirectory(String),
selectDirectory(File)public static UriSelector selectUri(URI uri)
UriSelector for the supplied URI.uri - the URI to select; never nullUriSelector,
selectUri(String),
selectFile(String),
selectFile(File),
selectDirectory(String),
selectDirectory(File)public static FileSelector selectFile(String path)
FileSelector for the supplied file path.
This method selects the file using the supplied path as is, without verifying if the file exists.
path - the path to the file to select; never null or blankFileSelector,
selectFile(File),
selectDirectory(String),
selectDirectory(File)public static FileSelector selectFile(File file)
FileSelector for the supplied file.
This method selects the file in its canonical form and throws a PreconditionViolationException if the
file does not exist.
file - the file to select; never nullFileSelector,
selectFile(String),
selectDirectory(String),
selectDirectory(File)public static DirectorySelector selectDirectory(String path)
DirectorySelector for the supplied directory path.
This method selects the directory using the supplied path as is, without verifying if the directory exists.
path - the path to the directory to select; never null or blankDirectorySelector,
selectDirectory(File),
selectFile(String),
selectFile(File)public static DirectorySelector selectDirectory(File directory)
DirectorySelector for the supplied directory.
This method selects the directory in its canonical form and throws a PreconditionViolationException if the
directory does not exist.
directory - the directory to select; never nullDirectorySelector,
selectDirectory(String),
selectFile(String),
selectFile(File)public static List<ClasspathRootSelector> selectClasspathRoots(Set<Path> directories)
ClasspathRootSelectors for the supplied directories.directories - set of directories in the filesystem that represent classpath roots;
never nullClasspathRootSelectorpublic static ClasspathResourceSelector selectClasspathResource(String classpathResourceName)
ClasspathResourceSelector for the supplied classpath
resource name.
The name of a classpath resource must follow the semantics
for resource paths as defined in ClassLoader.getResource(String).
If the supplied classpath resource name is prefixed with a slash
(/), the slash will be removed.
classpathResourceName - the name of the classpath resource; never
null or blankClasspathResourceSelector,
ClassLoader.getResource(String),
ClassLoader.getResourceAsStream(String),
ClassLoader.getResources(String)public static PackageSelector selectPackage(String packageName)
PackageSelector for the supplied package name.
The default package is represented by an empty string ("").
packageName - the package name to select; never null and
never containing whitespace onlyPackageSelectorpublic static ClassSelector selectClass(Class<?> clazz)
ClassSelector for the supplied Class.clazz - the class to select; never nullClassSelectorpublic static ClassSelector selectClass(String className)
ClassSelector for the supplied class name.className - the fully qualified name of the class to select;
never null or blankClassSelectorpublic static MethodSelector selectMethod(String fullyQualifiedMethodName) throws PreconditionViolationException
MethodSelector for the supplied fully qualified
method methodName.
The following formats are supported.
[fully qualified class]#[methodName][fully qualified class]#[methodName](parameter type list)
| Method | Fully Qualified Method Name |
|---|---|
CharSequence.chars() | java.lang.String#chars |
CharSequence.chars() | java.lang.String#chars() |
String.equalsIgnoreCase(String) | java.lang.String#equalsIgnoreCase(java.lang.String) |
String.substring(int, int) | java.lang.String#substring(int, int) |
fullyQualifiedMethodName - the fully qualified name of the method to select; never
null or blankPreconditionViolationExceptionMethodSelectorpublic static MethodSelector selectMethod(String className, String methodName)
MethodSelector for the supplied class name and method name.className - the fully qualified name of the class in which the method
is declared, or a subclass thereof; never null or blankmethodName - the name of the method to select; never null or blankMethodSelectorpublic static MethodSelector selectMethod(String className, String methodName, String methodParameterTypes)
MethodSelector for the supplied class name, method name,
and method parameter types.
The parameter types String is typically a comma-separated list
of atomic types, fully qualified class names, or array types; however,
the exact syntax depends on the underlying test engine.
className - the fully qualified name of the class in which the method
is declared, or a subclass thereof; never null or blankmethodName - the name of the method to select; never null or blankmethodParameterTypes - the method parameter types as a single string; never
null or blankMethodSelectorpublic static MethodSelector selectMethod(Class<?> javaClass, String methodName)
MethodSelector for the supplied Class and method name.javaClass - the class in which the method is declared, or a subclass thereof;
never nullmethodName - the name of the method to select; never null or blankMethodSelectorpublic static MethodSelector selectMethod(Class<?> javaClass, String methodName, String methodParameterTypes)
MethodSelector for the supplied Class, method name,
and method parameter types.
The parameter types String is typically a comma-separated list
of atomic types, fully qualified class names, or array types; however,
the exact syntax depends on the underlying test engine.
javaClass - the class in which the method is declared, or a subclass thereof;
never nullmethodName - the name of the method to select; never null or blankmethodParameterTypes - the method parameter types as a single string; never
null or blankMethodSelectorpublic static MethodSelector selectMethod(Class<?> javaClass, Method method)
javaClass - the class in which the method is declared, or a subclass thereof;
never nullmethod - the method to select; never nullMethodSelector@Deprecated @API(value=Deprecated) public static List<DiscoverySelector> selectNames(Collection<String> names)
selectPackage(String), selectClass(String), or
selectMethod(String) instead.DiscoverySelectors for the
supplied names.
The supported format for a fully qualified method name is
[fully qualified class name]#[methodName]. For example, the
fully qualified name for the chars() method in
java.lang.String is java.lang.String#chars. Names for
overloaded methods are not supported.
names - the names to select; never nullDiscoverySelectors for the supplied names;
potentially emptyselectPackage(String),
selectClass(String),
selectMethod(String)public static UniqueIdSelector selectUniqueId(UniqueId uniqueId)
UniqueIdSelector for the supplied UniqueId.uniqueId - the UniqueId to select; never nullUniqueIdSelectorpublic static UniqueIdSelector selectUniqueId(String uniqueId)
UniqueIdSelector for the supplied unique ID.uniqueId - the unique ID to select; never null or blankUniqueIdSelector