Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Create and manage temporary folders to simplify integration testing
Java
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
.settings
src
.classpath
.gitignore
.project
.travis.yml
README.md
pom.xml
properties.yaml
sandbox.iml

README.md

Build Status

Sandbox

Create and manage temporary folders to simplify integration testing

Usage

Add sandbox as a dependency (you probably only want it for tests). Maven dependency info:

    <dependency>
        <groupId>net.avh4.util</groupId>
        <artifactId>sandbox</artifactId>
        <version>0.0.6</version>
        <scope>test</scope>
    </dependency>

Any code that wants to play in the sandbox should have a root path that can be injected:

    public class MyService {
        private final File root;

        public MyService(File root) {
            this.root = root;
        }

        public void doSomething() {
            File configFile = new File(root, "config.xml");
            File fileToWrite = new File(root, "output.txt");
            ...
        }
    }

Create a sandbox and populate it with some files. This example copies test-config.xml from the classpath into config.xml in the sandbox.

    Sandbox sandbox = new Sandbox();
    sandbox.useResource("test-config.xml", "config.xml");

Test your code in the sandbox.

    MyService service = new MyService(sandbox.getRoot());
    assert(sandbox.newFile("output.txt").exists() == true);
Something went wrong with that request. Please try again.