Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/avh4/sandbox
Create and manage temporary folders to simplify integration testing
https://github.com/avh4/sandbox
Last synced: 8 days ago
JSON representation
Create and manage temporary folders to simplify integration testing
- Host: GitHub
- URL: https://github.com/avh4/sandbox
- Owner: avh4
- Created: 2011-12-03T10:29:30.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2013-04-29T02:00:51.000Z (over 11 years ago)
- Last Synced: 2024-10-27T12:06:03.084Z (about 2 months ago)
- Language: Java
- Homepage:
- Size: 129 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[![Build Status](https://secure.travis-ci.org/avh4/sandbox.png?branch=master)](http://travis-ci.org/avh4/sandbox)
## 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:
```xml
net.avh4.util
sandbox
0.0.6
test
```Any code that wants to play in the sandbox should have a root path that can be injected:
```java
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.```java
Sandbox sandbox = new Sandbox();
sandbox.useResource("test-config.xml", "config.xml");
```Test your code in the sandbox.
```java
MyService service = new MyService(sandbox.getRoot());
assert(sandbox.newFile("output.txt").exists() == true);
```