Skip to content

Commit c28f8ee

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

2 files changed

Lines changed: 12 additions & 33 deletions

File tree

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

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

2929
import org.janelia.saalfeldlab.n5.N5Reader.Version;
30-
import org.junit.AfterClass;
3130
import org.junit.Assert;
3231
import org.junit.Before;
32+
import org.junit.BeforeClass;
33+
import org.junit.Rule;
3334
import org.junit.Test;
35+
import org.junit.rules.TemporaryFolder;
3436

3537
/**
3638
* Abstract base class for testing N5 functionality.
@@ -41,6 +43,9 @@
4143
*/
4244
public abstract class AbstractN5Test {
4345

46+
@Rule
47+
public TemporaryFolder temp = new TemporaryFolder();
48+
4449
static protected final String groupName = "/test/group";
4550
static protected final String[] subGroupNames = new String[]{"a", "b", "c"};
4651
static protected final String datasetName = "/test/group/dataset";
@@ -54,9 +59,7 @@ public abstract class AbstractN5Test {
5459
static protected float[] floatBlock;
5560
static protected double[] doubleBlock;
5661

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

6164
protected Compression[] getCompressions() {
6265

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

8482
final Random rnd = new Random();
8583
byteBlock = new byte[blockSize[0] * blockSize[1] * blockSize[2]];
@@ -98,16 +96,9 @@ public void setUpOnce() throws IOException {
9896
}
9997
}
10098

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-
}
99+
@Before
100+
public void setUp() throws IOException {
101+
n5 = new N5FSWriter(temp.newFolder("n5-test").getAbsolutePath());
111102
}
112103

113104
@Test

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
*/
1717
package org.janelia.saalfeldlab.n5;
1818

19-
import java.io.IOException;
20-
2119
/**
2220
* Initiates testing of the filesystem-based N5 implementation.
2321
*
@@ -26,14 +24,4 @@
2624
*/
2725
public class N5FSTest extends AbstractN5Test {
2826

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);
38-
}
3927
}

0 commit comments

Comments
 (0)