Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Create and manage temporary folders to simplify integration testing

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 .settings
Octocat-spinner-32 src
Octocat-spinner-32 .classpath
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .project
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 README.md
Octocat-spinner-32 pom.xml
Octocat-spinner-32 properties.yaml
Octocat-spinner-32 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.