Last active
December 20, 2015 05:49
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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