Class TestData
-
- All Implemented Interfaces:
Runnable
public final class TestData extends TestData
Provides access to the commontest-datadirectories provided in thesample-datamodule. This directory is shared by test suites in other modules.This file has to live in the
org.geotoolsroot package in order to get access to theorg/geotools/test-datadirectory. If you don't need this directory, then use theTestDataclass provided in theorg.geotools.resourcesdirectory.- Since:
- 2.2
- Author:
- Martin Desruisseaux
-
-
Field Summary
-
Fields inherited from class TestData
EXTENSIVE_TEST_KEY, INTERACTIVE_TEST_KEY
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Filecopy(Object caller, String name)Copies the named resources from thesample-datamodule to thetest-datadirectory in an other module.static Filecopy(Object caller, String name, String directoryName)See the other copy, this one accepts a target directory name inside "test-data" (useful for test with directory containing spaces)static Filefile(String name)Access togetResource(name)as a non-nullFile.static ReadableByteChannelopenChannel(String name)Provides a channel for named test data.static LineNumberReaderopenReader(String name)Provides aBufferedReaderfor named test data.static InputStreamopenStream(String name)Provides a non-nullInputStreamfor named test data.static URLurl(String name)Access togetResource(name)as a non-nullURL.-
Methods inherited from class TestData
deleteOnExit, deleteOnExit, file, getResource, isBaseJavaPlatform, isExtensiveTest, isInteractiveTest, isMediaLibAvailable, openChannel, openReader, openStream, run, temp, unzip, unzipFile, url
-
-
-
-
Method Detail
-
url
public static URL url(String name) throws FileNotFoundException
Access togetResource(name)as a non-nullURL. At the difference ofgetResource, this method throws an exception if the resource is not found. This provides a more explicit explanation about the failure reason than the infamousNullPointerException.- Parameters:
name- Path to file inorg/geotools/test-data.- Returns:
- The URL to the
test-dataresource. - Throws:
FileNotFoundException- if the resource is not found.
-
file
public static File file(String name) throws IOException
Access togetResource(name)as a non-nullFile. You can access thetest-datadirectory with:TestData.file(null);
- Parameters:
name- Path to file inorg/geotools/test-data.- Returns:
- The file to the
test-dataresource. - Throws:
FileNotFoundException- if the file is not found.IOException- if the resource can't be fetched for an other reason.
-
openStream
public static InputStream openStream(String name) throws IOException
Provides a non-nullInputStreamfor named test data. It is the caller responsability to close this stream after usage.- Parameters:
name- Path to file inorg/geotools/test-data.- Returns:
- The input stream.
- Throws:
FileNotFoundException- if the resource is not found.IOException- if an error occurs during an input operation.
-
openReader
public static LineNumberReader openReader(String name) throws IOException
Provides aBufferedReaderfor named test data. The buffered reader is provided as anLineNumberReaderinstance, which is useful for displaying line numbers where error occur. It is the caller responsability to close this reader after usage.- Parameters:
name- Path to file inorg/geotools/test-data.- Returns:
- The buffered reader.
- Throws:
FileNotFoundException- if the resource is not found.IOException- if an error occurs during an input operation.
-
openChannel
public static ReadableByteChannel openChannel(String name) throws IOException
Provides a channel for named test data. It is the caller responsability to close this chanel after usage.- Parameters:
name- Path to file inorg/geotools/test-data.- Returns:
- The chanel.
- Throws:
FileNotFoundException- if the resource is not found.IOException- if an error occurs during an input operation.
-
copy
public static File copy(Object caller, String name) throws IOException
Copies the named resources from thesample-datamodule to thetest-datadirectory in an other module. For example ifTestData.copy(this, "foo.txt")is invoked inside a test suite in theorg.geotools.foopackage, then this method copiesorg/geotools/test-data/foo.txt(fromsample-datamodule) toorg/geotools/foo/test-data/foo.txt(in thefoomodule).This method is useful when a test case needs to access a resource through a
File, for example because it want to open it usingRandomAccess. Because the resources provided in thesample-datamodule are available to other modules as a JAR file, other modules can only access them through anURLunless they copy them in their owntest-datadirectory.If the named file already exists in the caller
test-datadirectory, 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-datadirectory, which is not versioned by Git and is cleaned by Maven onmvn cleanexecution.- Parameters:
caller- Calling class or object used to locate the destinationtest-data.name- Path to file inorg/geotools/test-data.- Returns:
- The file to the
org/geotools/caller-package/test-dataresource copy, returned for convenience. - Throws:
FileNotFoundException- if the file is not found.IOException- if the resource can't be fetched for an other reason.
-
copy
public static File copy(Object caller, String name, String directoryName) throws IOException
See the other copy, this one accepts a target directory name inside "test-data" (useful for test with directory containing spaces)- Throws:
IOException
-
-