|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ObjectTestData
TestData
public final class TestData
Provides access to the common test-data
directories provided in the
sample-data
module. This directory is shared by test suites in other
modules.
This file has to live in the org.geotools
root package in order to
get access to the org/geotools/test-data
directory. If you don't
need this directory, then use the TestData
class provided in the org.geotools.resources
directory.
Field Summary |
---|
Fields inherited from class TestData |
---|
EXTENSIVE_TEST_KEY, INTERACTIVE_TEST_KEY |
Method Summary | |
---|---|
static File |
copy(Object caller,
String name)
Copies the named resources from the sample-data module to the test-data
directory in an other module. |
static File |
file(String name)
Access to getResource(name) as a non-null
File . |
static ReadableByteChannel |
openChannel(String name)
Provides a channel for named test data. |
static LineNumberReader |
openReader(String name)
Provides a BufferedReader for named test data. |
static InputStream |
openStream(String name)
Provides a non-null InputStream for named test data. |
static URL |
url(String name)
Access to getResource(name) as a non-null
URL . |
Methods inherited from class TestData |
---|
deleteOnExit, deleteOnExit, file, getReader, getResource, isBaseJavaPlatform, isExtensiveTest, isInteractiveTest, isMediaLibAvailable, openChannel, openReader, openStream, run, temp, unzipFile, url |
Methods inherited from class Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static URL url(String name) throws FileNotFoundException
getResource(name)
as a non-null
URL
. At the difference of getResource
, this method throws an exception if
the resource is not found. This provides a more explicit explanation about the failure
reason than the infamous NullPointerException
.
name
- Path to file in org/geotools/test-data
.
test-data
resource.
FileNotFoundException
- if the resource is not found.public static File file(String name) throws IOException
getResource(name)
as a non-null
File
. You can access the test-data
directory with:
TestData.file(null);
name
- Path to file in org/geotools/test-data
.
test-data
resource.
FileNotFoundException
- if the file is not found.
IOException
- if the resource can't be fetched for an other reason.public static InputStream openStream(String name) throws IOException
InputStream
for named test data.
It is the caller responsability to close this stream after usage.
name
- Path to file in org/geotools/test-data
.
FileNotFoundException
- if the resource is not found.
IOException
- if an error occurs during an input operation.public static LineNumberReader openReader(String name) throws IOException
BufferedReader
for named test data. The buffered reader is provided as
an LineNumberReader
instance, which is useful for displaying line numbers where
error occur. It is the caller responsability to close this reader after usage.
name
- Path to file in org/geotools/test-data
.
FileNotFoundException
- if the resource is not found.
IOException
- if an error occurs during an input operation.public static ReadableByteChannel openChannel(String name) throws IOException
name
- Path to file in org/geotools/test-data
.
FileNotFoundException
- if the resource is not found.
IOException
- if an error occurs during an input operation.public static File copy(Object caller, String name) throws IOException
sample-data
module to the test-data
directory in an other module. For example if TestData.copy(this, "foo.txt")
is
invoked inside a test suite in the org.geotools.foo
package, then this method
copies org/geotools/test-data/foo.txt
(from sample-data
module) to
org/geotools/foo/test-data/foo.txt
(in the foo
module).
This method is useful when a test case needs to access a resource through a File
,
for example because it want to open it using RandomAccess
. Because the
resources provided in the sample-data
module are available to other modules as
a JAR file, other modules can only access them through an URL
unless they copy
them in their own test-data
directory.
If the named file already exists in the caller test-data
directory, then this
method does nothing. It make it safe to invoke this method many time in a test suite,
since this method should not copy the file more than once for a given JVM execution.
The file will be deleted on exit if and only if it has
been modified. Callers don't need to worry about cleanup, because the files are copied
in the target/.../test-data
directory, which is not versionned by SVN and is
cleaned by Maven on mvn clean
execution.
caller
- Calling class or object used to locate the destination test-data
.name
- Path to file in org/geotools/test-data
.
org/geotools/caller-package/test-data
resource copy, returned for convenience.
FileNotFoundException
- if the file is not found.
IOException
- if the resource can't be fetched for an other reason.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |