org.eclipse.jetty.toolchain.test
Class TestingDir

java.lang.Object
  extended by org.eclipse.jetty.toolchain.test.TestingDir
All Implemented Interfaces:
org.junit.rules.MethodRule

public class TestingDir
extends Object
implements org.junit.rules.MethodRule

A junit 4.x Rule to provide a common, easy to use, testing directory that is unique per unit test.

Similar in scope to the TemporaryFolder rule, as it creates a directory, when asked (via getDir() or getEmptyDir()) in the maven project familiar and friendly location: ${basedir}/target/tests/${testclass}/${testmethod}.

Note: existing facilities within MavenTestingUtils for keeping the directory name short for the sake of windows users is being used.


Constructor Summary
TestingDir()
           
 
Method Summary
 org.junit.runners.model.Statement apply(org.junit.runners.model.Statement statement, org.junit.runners.model.FrameworkMethod method, Object target)
           
 void ensureEmpty()
          Ensure that the test directory is empty.
 File getDir()
          Get the test specific directory to use for testing work directory.
 File getEmptyDir()
          Get the unique testing directory while ensuring that it is empty (if not).
 File getFile(String name)
          Get a file inside of the test specific test directory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TestingDir

public TestingDir()
Method Detail

apply

public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement statement,
                                               org.junit.runners.model.FrameworkMethod method,
                                               Object target)
Specified by:
apply in interface org.junit.rules.MethodRule

getDir

public File getDir()
Get the test specific directory to use for testing work directory.

Name is derived from the test classname & method name.

Returns:
the test specific directory.

getFile

public File getFile(String name)
Get a file inside of the test specific test directory.

Note: No assertions are made if the file exists or not.

Parameters:
name - the path name of the file (supports deep paths)
Returns:
the file reference.

ensureEmpty

public void ensureEmpty()
Ensure that the test directory is empty.

Useful for repeated testing without using the maven clean goal (such as within Eclipse).


getEmptyDir

public File getEmptyDir()
Get the unique testing directory while ensuring that it is empty (if not).

Returns:
the unique testing directory, created, and empty.


Copyright © 1995-2012 Mort Bay Consulting. All Rights Reserved.