Class MavenTestingUtils
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic File
Obtain aFile
reference to the maven ${basedir} for the module.static Path
Obtain aPath
reference to the maven ${basedir} for the module.static URI
Get the Basedir for the project as a URIstatic File
getProjectDir
(String path) Get a directory reference to a required directory in the project module path, based on relative path references from maven ${basedir}.static Path
getProjectDirPath
(String path) Get aPath
reference to a required directory in the project module path, based on relative path references from maven ${basedir}.static File
getProjectFile
(String path) Get aFile
reference to a required file in the project module path, based on relative path references from maven ${basedir}.static Path
getProjectFilePath
(String path) Get aPath
reference to a required file in the project module path, based on relative path references from maven ${basedir}.static File
Get theFile
reference to the/target
directory for this project.static File
getTargetFile
(String path) Create aFile
object for a path in the /target directory.static Path
Get thePath
reference to the/target
directory for this project.static Path
getTargetPath
(String path) Create aPath
object for a path in the /target directory.static File
Get aFile
reference to the maven${basedir}/target/tests/
directory.static File
getTargetTestingDir
(Class<?> testclass, String testmethodname) Obtain a testing directory reference in maven${basedir}/target/tests/${condensed-classname}/${methodname}
path that uses an condensed directory name based on the testclass and subdirectory based on the testmethod being run.static File
getTargetTestingDir
(String testname) Get aFile
reference to the maven${basedir}/target/tests/test-${testname}
using the supplied testnamestatic File
getTargetTestingDir
(junit.framework.TestCase test) Get aFile
reference to the${basedir}/target/tests/test-${testname}
directory.static Path
Get aPath
reference to the maven${basedir}/target/tests/
path.static Path
getTargetTestingPath
(Class<?> testclass, String testmethodname) Obtain a testing directory reference in maven${basedir}/target/tests/${condensed-classname}/${methodname}
path that uses an condensed directory name based on the testclass and subdirectory based on the testmethod being run.static Path
getTargetTestingPath
(String testname) Get aPath
reference to the maven${basedir}/target/tests/test-${testname}
using the supplied testnamestatic Path
getTargetTestingPath
(junit.framework.TestCase test) Get aPath
reference to the${basedir}/target/tests/test-${testname}
directory.static URI
getTargetURI
(String path) Get a URI reference to a path (File or Dir) within the maven "${basedir}/target" directory.static URL
getTargetURL
(String path) Get a URL reference to a path (File or Dir) within the maven "${basedir}/target" directory.private static MavenTestingUtils.TestID
Using junit 3.x naming standards for unit tests and test method names, attempt to discover the unit test name from the execution stack.static File
getTestResourceDir
(String name) Get a dir from the maven${basedir}/src/test/resource
directory.static File
getTestResourceFile
(String name) Get a file from the maven${basedir}/src/test/resource
directory.static Path
getTestResourcePath
(String name) Get a path resource (File or Dir) from the maven${basedir}/src/test/resource
directory.static Path
getTestResourcePathDir
(String name) Get a dir from the maven${basedir}/src/test/resource
directory.static Path
Get a file from the maven${basedir}/src/test/resource
directory.static File
Get theFile
reference to the maven${basedir}/src/test/resources
directorystatic Path
Get thePath
reference to the maven${basedir}/src/test/resources
directory
-
Field Details
-
basePath
-
testResourcesPath
-
targetPath
-
-
Constructor Details
-
MavenTestingUtils
private MavenTestingUtils()
-
-
Method Details
-
getBaseDir
Obtain aFile
reference to the maven ${basedir} for the module.Convenience method for
MavenTestingUtils.getBasePath().toFile()
- Returns:
- the equivalent to the maven ${basedir} property.
- See Also:
-
getBasePath
Obtain aPath
reference to the maven ${basedir} for the module.Note: while running in maven, the ${basedir} is populated by maven and used by the surefire-plugin.
While running in eclipse, the ${basedir} property is unset, resulting in this method falling back to ${user.dir} equivalent use.- Returns:
- the equivalent to the maven ${basedir} property.
-
getBaseURI
Get the Basedir for the project as a URI- Returns:
- the URI for the project basedir
-
getTargetDir
Get theFile
reference to the/target
directory for this project.Convenience method for
MavenTestingUtils.getTargetPath().toFile()
- Returns:
- the directory path to the target directory.
- See Also:
-
getTargetPath
Get thePath
reference to the/target
directory for this project.This is roughly equivalent to the
${project.build.directory}
property.Note: this implementation does not inspect the
pom.xml
for non-standard locations of the${project.build.directory}
property. (it always assumes/target
)- Returns:
- the directory path to the
/target
directory.
-
getTargetFile
Create aFile
object for a path in the /target directory.Convenience method for
MavenTestingUtils.getTargetPath("foo").toFile()
- Parameters:
path
- the path desired, no validation of existence is performed.- Returns:
- the File to the path.
- See Also:
-
getTargetPath
Create aPath
object for a path in the /target directory.- Parameters:
path
- the path desired, no validation of existence is performed.- Returns:
- the File to the path.
-
getTargetTestingDir
Get aFile
reference to the maven${basedir}/target/tests/
directory.Convenience method for
MavenTestingUtils.getTargetTestingPath().toFile()
- Returns:
- the maven
${basedir}/target/tests/
directory. Note: will not validate that the directory exists, or create the directory)
-
getTargetTestingPath
Get aPath
reference to the maven${basedir}/target/tests/
path.- Returns:
- the maven
${basedir}/target/tests/
directory. Note: will not validate that the directory exists, or create the directory)
-
getTargetTestingDir
Get aFile
reference to the maven${basedir}/target/tests/test-${testname}
using the supplied testnameConvenience method for
MavenTestingUtils.getTargetTestingPath(testname).toFile()
- Parameters:
testname
- the testname to create directory against.- Returns:
- the maven
${basedir}/target/tests/test-${testname}
directory
-
getTargetTestingPath
Get aPath
reference to the maven${basedir}/target/tests/test-${testname}
using the supplied testname- Parameters:
testname
- the testname to create directory against.- Returns:
- the maven
${basedir}/target/tests/test-${testname}
directory
-
getTargetTestingDir
Get aFile
reference to the${basedir}/target/tests/test-${testname}
directory. Uses the JUnit 3.xTestCase.getName()
to make a unique directory name per test.Convenience method for
MavenTestingUtils.getTargetTestingPath(TestCase.getName()).toFile()
- Parameters:
test
- the junit 3.x testcase to base this new directory on.- Returns:
- the maven
${basedir}/target/tests/test-${testname}
directory.
-
getTargetTestingPath
Get aPath
reference to the${basedir}/target/tests/test-${testname}
directory. Uses the JUnit 3.xTestCase.getName()
to make a unique directory name per test.Convenience method for
MavenTestingUtils.getTargetTestingPath(TestCase.getName())
- Parameters:
test
- the junit 3.x testcase to base this new directory on.- Returns:
- the maven
${basedir}/target/tests/test-${testname}
directory. - See Also:
-
getTargetURI
Get a URI reference to a path (File or Dir) within the maven "${basedir}/target" directory.Convenience method for
MavenTestingUtils.getTargetPath(path).toUri()
- Parameters:
path
- the relative path to use- Returns:
- the URI reference to the target path
-
getTargetURL
Get a URL reference to a path (File or Dir) within the maven "${basedir}/target" directory.Convenience method for
MavenTestingUtils.getTargetURI(path).toURL()
- Parameters:
path
- the relative path to use- Returns:
- the URL reference to the target path
- Throws:
MalformedURLException
- if unable to create a new target url due to URL error.
-
getTargetTestingDir
Obtain a testing directory reference in maven${basedir}/target/tests/${condensed-classname}/${methodname}
path that uses an condensed directory name based on the testclass and subdirectory based on the testmethod being run.Note: the @Rule
TestingDir
is a better choice in most cases.Convenience method for
MavenTestingUtils.getTargetTestingDir(testclass, testmethodname).toFile()
- Parameters:
testclass
- the class for the test casetestmethodname
- the test method name- Returns:
- the File path to the testname specific testing directory underneath the
${basedir}/target/tests/
sub directory - See Also:
-
getTargetTestingPath
Obtain a testing directory reference in maven${basedir}/target/tests/${condensed-classname}/${methodname}
path that uses an condensed directory name based on the testclass and subdirectory based on the testmethod being run.Note: the @Rule
TestingDir
is a better choice in most cases.- Parameters:
testclass
- the class for the test casetestmethodname
- the test method name- Returns:
- the File path to the testname specific testing directory underneath the
${basedir}/target/tests/
sub directory - See Also:
-
getProjectFile
Get aFile
reference to a required file in the project module path, based on relative path references from maven ${basedir}.Note: will throw assertion error if path does point to an existing file
Convenience method for
MavenTestingUtils.getProjectFilePath(path).toFile()
- Parameters:
path
- the relative path to reference- Returns:
- the file reference (must exist)
-
getProjectFilePath
Get aPath
reference to a required file in the project module path, based on relative path references from maven ${basedir}.Note: will throw assertion error if path does point to an existing file
- Parameters:
path
- the relative path to reference- Returns:
- the file reference (must exist)
-
getProjectDir
Get a directory reference to a required directory in the project module path, based on relative path references from maven ${basedir}.Note: will throw assertion error if path does point to an existing directory
Convenience method for
MavenTestingUtils.getProjectDirPath(path).toFile()
- Parameters:
path
- the relative path to reference- Returns:
- the directory reference (must exist)
-
getProjectDirPath
Get aPath
reference to a required directory in the project module path, based on relative path references from maven ${basedir}.Note: will throw assertion error if path does point to an existing directory
- Parameters:
path
- the relative path to reference- Returns:
- the directory reference (must exist)
-
getTestID
Using junit 3.x naming standards for unit tests and test method names, attempt to discover the unit test name from the execution stack.- Returns:
- the unit test id found via execution stack and junit 3.8 naming conventions.
- See Also:
-
getTestResourcesDir
Get theFile
reference to the maven${basedir}/src/test/resources
directoryConvenience method for
MavenTestingUtils.getTestResourcesPath().toFile()
- Returns:
- the directory
File
to the maven${basedir}/src/test/resources
directory
-
getTestResourcesPath
Get thePath
reference to the maven${basedir}/src/test/resources
directory- Returns:
- the directory
Path
to the maven${basedir}/src/test/resources
directory
-
getTestResourceDir
Get a dir from the maven${basedir}/src/test/resource
directory.Note: will throw assertion error if path does point to an existing directory
Convenience method for
MavenTestingUtils.getTestResourcesPathDir(name).toFile()
- Parameters:
name
- the name of the path to get (it must exist as a dir)- Returns:
- the dir in the maven
${basedir}/src/test/resource
path
-
getTestResourcePathDir
Get a dir from the maven${basedir}/src/test/resource
directory.Note: will throw assertion error if path does point to an existing directory
- Parameters:
name
- the name of the path to get (it must exist as a dir)- Returns:
- the dir in the maven
${basedir}/src/test/resource
path
-
getTestResourceFile
Get a file from the maven${basedir}/src/test/resource
directory.Note: will throw assertion error if path does point to an existing file
- Parameters:
name
- the name of the path to get (it must exist as a file)- Returns:
- the file in maven
${basedir}/src/test/resource
-
getTestResourcePathFile
Get a file from the maven${basedir}/src/test/resource
directory.Note: will throw assertion error if path does point to an existing file
- Parameters:
name
- the name of the path to get (it must exist as a file)- Returns:
- the file in maven
${basedir}/src/test/resource
-
getTestResourcePath
Get a path resource (File or Dir) from the maven${basedir}/src/test/resource
directory.- Parameters:
name
- the name of the path to get (it must exist)- Returns:
- the path in maven
${basedir}/src/test/resource
-