public class TestUtils extends Object
| Constructor and Description |
|---|
TestUtils() |
| Modifier and Type | Method and Description |
|---|---|
static File |
createPath(File parent,
String path)
Creates an empty file at the given path, creating intermediate directories
as necessary.
|
static File |
createTemporaryDirectory(String prefix)
Makes a temporary directory for use with unit tests.
|
static File |
createTemporaryDirectory(String prefix,
Class<?> forClass)
Makes a temporary directory for use with unit tests.
|
static File |
createTemporaryDirectory(String prefix,
Class<?> forClass,
String suffix)
Makes a temporary directory for use with unit tests.
|
static Class<?> |
getCallingClass(Class<?> excluding)
Returns the class of the caller (excluding the specified class).
|
static Map.Entry<Class<?>,String> |
getCallingCodeLocation(Class<?> excluding)
Returns the class and the method/line number of the caller (excluding the specified class).
|
public static File createPath(File parent, String path) throws IOException
parent - The parent directory of the relative path.path - The forward-slash-separated path to create.File pointing at the newly created empty path.IOException - if the file cannot be created.public static File createTemporaryDirectory(String prefix) throws IOException
When the unit test runs in a Maven context, the temporary directory will be created in the target/ directory corresponding to the calling class instead of /tmp/.
prefix - the prefix for the directory's nameIOExceptionpublic static File createTemporaryDirectory(String prefix, Class<?> forClass) throws IOException
When the unit test runs in a Maven context, the temporary directory will be created in the corresponding target/ directory instead of /tmp/.
prefix - the prefix for the directory's nameforClass - the class for context (to determine whether there's a
target/ directory)IOExceptionpublic static File createTemporaryDirectory(String prefix, Class<?> forClass, String suffix) throws IOException
When the unit test runs in a Maven context, the temporary directory will be created in the corresponding target/ directory instead of /tmp/.
prefix - the prefix for the directory's nameforClass - the class for context (to determine whether there's a
target/ directory)suffix - the suffix for the directory's nameIOExceptionpublic static Class<?> getCallingClass(Class<?> excluding)
Sometimes it is convenient to determine the caller's context, e.g. to determine whether running in a maven-surefire-plugin context (in which case the location of the caller's class would end in target/test-classes/).
excluding - the class to exclude (or null)public static Map.Entry<Class<?>,String> getCallingCodeLocation(Class<?> excluding)
Sometimes it is convenient to determine the caller's context, e.g. to determine whether running in a maven-surefire-plugin context (in which case the location of the caller's class would end in target/test-classes/).
excluding - the class to exclude (or null)Copyright © 2009–2016 SciJava. All rights reserved.