Skip to content

Commit d122ddc

Browse files
committed
Use temporary folder for tests
1 parent e117bfd commit d122ddc

2 files changed

Lines changed: 15 additions & 33 deletions

File tree

src/test/java/org/janelia/saalfeldlab/n5/AbstractN5Test.java

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@
2727
import java.util.Random;
2828

2929
import org.janelia.saalfeldlab.n5.N5Reader.Version;
30-
import org.junit.AfterClass;
3130
import org.junit.Assert;
32-
import org.junit.Before;
31+
import org.junit.BeforeClass;
32+
import org.junit.Rule;
3333
import org.junit.Test;
34+
import org.junit.rules.TemporaryFolder;
3435

3536
/**
3637
* Abstract base class for testing N5 functionality.
@@ -41,6 +42,9 @@
4142
*/
4243
public abstract class AbstractN5Test {
4344

45+
@Rule
46+
public TemporaryFolder temp = new TemporaryFolder();
47+
4448
static protected final String groupName = "/test/group";
4549
static protected final String[] subGroupNames = new String[]{"a", "b", "c"};
4650
static protected final String datasetName = "/test/group/dataset";
@@ -54,9 +58,7 @@ public abstract class AbstractN5Test {
5458
static protected float[] floatBlock;
5559
static protected double[] doubleBlock;
5660

57-
static protected N5Writer n5;
58-
59-
protected abstract N5Writer createN5Writer() throws IOException;
61+
protected N5Writer n5;
6062

6163
protected Compression[] getCompressions() {
6264

@@ -73,13 +75,8 @@ protected Compression[] getCompressions() {
7375
/**
7476
* @throws IOException
7577
*/
76-
@Before
77-
public void setUpOnce() throws IOException {
78-
79-
if (n5 != null)
80-
return;
81-
82-
n5 = createN5Writer();
78+
@BeforeClass
79+
public static void setUpOnce() throws IOException {
8380

8481
final Random rnd = new Random();
8582
byteBlock = new byte[blockSize[0] * blockSize[1] * blockSize[2]];
@@ -98,18 +95,6 @@ public void setUpOnce() throws IOException {
9895
}
9996
}
10097

101-
/**
102-
* @throws IOException
103-
*/
104-
@AfterClass
105-
public static void rampDownAfterClass() throws IOException {
106-
107-
if (n5 != null) {
108-
Assert.assertTrue(n5.remove());
109-
n5 = null;
110-
}
111-
}
112-
11398
@Test
11499
public void testCreateGroup() {
115100

src/test/java/org/janelia/saalfeldlab/n5/N5FSTest.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import java.io.IOException;
2020

21+
import org.junit.Before;
22+
2123
/**
2224
* Initiates testing of the filesystem-based N5 implementation.
2325
*
@@ -26,14 +28,9 @@
2628
*/
2729
public class N5FSTest extends AbstractN5Test {
2830

29-
static private String testDirPath = System.getProperty("user.home") + "/tmp/n5-test";
30-
31-
/**
32-
* @throws IOException
33-
*/
34-
@Override
35-
protected N5Writer createN5Writer() throws IOException {
36-
37-
return new N5FSWriter(testDirPath);
31+
@Before
32+
public void setUp() throws IOException {
33+
n5 = new N5FSWriter(temp.newFolder("n5-test").getAbsolutePath());
3834
}
35+
3936
}

0 commit comments

Comments
 (0)