Skip to content

Instantly share code, notes, and snippets.

@pzelnip
Last active December 20, 2015 05:49
Show Gist options
  • Save pzelnip/6080964 to your computer and use it in GitHub Desktop.
Save pzelnip/6080964 to your computer and use it in GitHub Desktop.
Creating a static temporary directory as suitable for use in a JUnit @DataPoints method. Based upon the advice at: http://stackoverflow.com/a/17846991/808804
private static File tmpDir;
@BeforeClass
public static void setUp() {
String dirname = UUID.randomUUID().toString().replace("-", "");
tmpDir = new File(System.getProperty("java.io.tmpdir"), dirname);
if (!tmpDir.exists()) {
tmpDir.mkdir();
}
}
@AfterClass
public static void tearDown() {
if(tmpDir.exists()) {
try {
FileUtils.deleteDirectory(tmpDir);
} catch (IOException e) {
System.err.println("Error deleting temporary directory: "
+ tmpDir + " -- " + e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment