Skip to content

Commit 4b2991c

Browse files
committed
Use temporary folder for tests
1 parent cd1fbb9 commit 4b2991c

2 files changed

Lines changed: 20 additions & 38 deletions

File tree

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

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@
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;
3332
import org.junit.Test;
3433

3534
/**
@@ -47,16 +46,14 @@ public abstract class AbstractN5Test {
4746
static protected final long[] dimensions = new long[]{100, 200, 300};
4847
static protected final int[] blockSize = new int[]{44, 33, 22};
4948

50-
static protected byte[] byteBlock;
51-
static protected short[] shortBlock;
52-
static protected int[] intBlock;
53-
static protected long[] longBlock;
54-
static protected float[] floatBlock;
55-
static protected double[] doubleBlock;
49+
protected static byte[] byteBlock;
50+
protected static short[] shortBlock;
51+
protected static int[] intBlock;
52+
protected static long[] longBlock;
53+
protected static float[] floatBlock;
54+
protected static double[] doubleBlock;
5655

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

6158
protected Compression[] getCompressions() {
6259

@@ -73,13 +70,8 @@ protected Compression[] getCompressions() {
7370
/**
7471
* @throws IOException
7572
*/
76-
@Before
77-
public void setUpOnce() throws IOException {
78-
79-
if (n5 != null)
80-
return;
81-
82-
n5 = createN5Writer();
73+
@BeforeClass
74+
public static void setUpOnce() throws IOException {
8375

8476
final Random rnd = new Random();
8577
byteBlock = new byte[blockSize[0] * blockSize[1] * blockSize[2]];
@@ -98,18 +90,6 @@ public void setUpOnce() throws IOException {
9890
}
9991
}
10092

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-
11393
@Test
11494
public void testCreateGroup() {
11595

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

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

1919
import java.io.IOException;
2020

21+
import org.junit.Before;
22+
import org.junit.Rule;
23+
import org.junit.rules.TemporaryFolder;
24+
2125
/**
2226
* Initiates testing of the filesystem-based N5 implementation.
2327
*
@@ -26,14 +30,12 @@
2630
*/
2731
public class N5FSTest extends AbstractN5Test {
2832

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 {
33+
@Rule
34+
public TemporaryFolder temp = new TemporaryFolder();
3635

37-
return new N5FSWriter(testDirPath);
36+
@Before
37+
public void setUp() throws IOException {
38+
n5 = new N5FSWriter(temp.newFolder("n5-test").getAbsolutePath());
3839
}
40+
3941
}

0 commit comments

Comments
 (0)