org.geotools.resources
Class TestData

java.lang.Object
  extended byorg.geotools.resources.TestData

public class TestData
extends java.lang.Object

Provides access to test-data directories associated with junit tests.

We have chosen test-data to follow the javadoc "doc-files" convention of ensuring that data directories don't look anything like normal java packages.

Example:


 class MyClass {
   public void example(){
     Image testImage =
       new ImageIcon( TestData.getResource( this, "test.png" ) ).getImage();
     Reader reader = TestData.getReader( this, "script.xml" );
   }
 }
 
Where:

By convention you should try and locate test-data near the junit test cases that uses it.

Version:
$Id: TestData.java 12690 2005-03-25 21:37:43Z simboss $
Author:
James McGill, Simone Giannecchiin (simboss)

Constructor Summary
TestData()
           
 
Method Summary
static java.io.File file(java.lang.Class caller, java.lang.String path)
          Access to getResource(caller, path) as a File.
static java.io.File file(java.lang.Object caller, java.lang.String path)
          Access to getResource(caller, path) as a File.
static java.io.BufferedReader getReader(java.lang.Class caller, java.lang.String name)
          Provided a BufferedReader for named test data.
static java.io.BufferedReader getReader(java.lang.Object host, java.lang.String name)
          Provided a BufferedReader for named test data.
static java.net.URL getResource(java.lang.Class caller, java.lang.String name)
          Locate named test-data resource for caller.
static java.net.URL getResource(java.lang.Object caller, java.lang.String name)
          Locate named test-data resource for caller.
static java.io.File temp(java.lang.Object caller, java.lang.String name)
          Creates a temporary file with the given name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TestData

public TestData()
Method Detail

getReader

public static final java.io.BufferedReader getReader(java.lang.Class caller,
                                                     java.lang.String name)
                                              throws java.io.IOException
Provided a BufferedReader for named test data. It is the caller responsability to close this reader after usage.

Parameters:
caller - The class of the object associated with named data.
name - of test data to load.
Returns:
The reader, or null if the named test data are not found.
Throws:
java.io.IOException - if an error occurs during an input operation.

getReader

public static final java.io.BufferedReader getReader(java.lang.Object host,
                                                     java.lang.String name)
                                              throws java.io.IOException
Provided a BufferedReader for named test data. It is the caller responsability to close this reader after usage.

Parameters:
host - Object associated with named data
name - of test data to load
Returns:
The reader, or null if the named test data are not found.
Throws:
java.io.IOException - if an error occurs during an input operation.

getResource

public static final java.net.URL getResource(java.lang.Class caller,
                                             java.lang.String name)
Locate named test-data resource for caller.

Parameters:
caller - Class used to locate test-data.
name - name of test-data.
Returns:
URL or null of named test-data could not be found.
To Do:
Should this be getURL() - or simply url? I tend to save getX method for accessors.

getResource

public static final java.net.URL getResource(java.lang.Object caller,
                                             java.lang.String name)
Locate named test-data resource for caller.

Parameters:
caller - Object used to locate test-data
name - name of test-data
Returns:
URL or null of named test-data could not be found
To Do:
Should this be getURL() - or simply url? I tend to save getX method for accessors.

file

public static final java.io.File file(java.lang.Object caller,
                                      java.lang.String path)
                               throws java.io.IOException
Access to getResource(caller, path) as a File.

You can access the test-data directory with:


 TestData.file( this, null )
 

Parameters:
caller - Calling object used to locate test-data
path - Path to file in testdata
Returns:
File from test-data
Throws:
java.io.IOException - if the file is not found.

file

public static final java.io.File file(java.lang.Class caller,
                                      java.lang.String path)
                               throws java.io.IOException
Access to getResource(caller, path) as a File.

You can access the test-data directory with:


 TestData.file( MyClass.class, null )
 

Parameters:
caller - Calling class used to locate test-data
path - Path to file in testdata
Returns:
File from test-data
Throws:
java.io.IOException - if the file is not found.

temp

public static final java.io.File temp(java.lang.Object caller,
                                      java.lang.String name)
                               throws java.io.IOException
Creates a temporary file with the given name.

Throws:
java.io.IOException


Copyright © GeoTools. All Rights Reserved.