2727import java .util .Random ;
2828
2929import org .janelia .saalfeldlab .n5 .N5Reader .Version ;
30- import org .junit .AfterClass ;
3130import org .junit .Assert ;
3231import org .junit .Before ;
32+ import org .junit .BeforeClass ;
33+ import org .junit .Rule ;
3334import org .junit .Test ;
35+ import org .junit .rules .TemporaryFolder ;
3436
3537/**
3638 * Abstract base class for testing N5 functionality.
4143 */
4244public 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
0 commit comments