Skip to content

Commit

Permalink
Use temporary folder for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-allan committed Jul 30, 2020
1 parent cd1fbb9 commit 4b2991c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 38 deletions.
40 changes: 10 additions & 30 deletions src/test/java/org/janelia/saalfeldlab/n5/AbstractN5Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@
import java.util.Random;

import org.janelia.saalfeldlab.n5.N5Reader.Version;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

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

static protected byte[] byteBlock;
static protected short[] shortBlock;
static protected int[] intBlock;
static protected long[] longBlock;
static protected float[] floatBlock;
static protected double[] doubleBlock;
protected static byte[] byteBlock;
protected static short[] shortBlock;
protected static int[] intBlock;
protected static long[] longBlock;
protected static float[] floatBlock;
protected static double[] doubleBlock;

static protected N5Writer n5;

protected abstract N5Writer createN5Writer() throws IOException;
protected N5Writer n5;

protected Compression[] getCompressions() {

Expand All @@ -73,13 +70,8 @@ protected Compression[] getCompressions() {
/**
* @throws IOException
*/
@Before
public void setUpOnce() throws IOException {

if (n5 != null)
return;

n5 = createN5Writer();
@BeforeClass
public static void setUpOnce() throws IOException {

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

/**
* @throws IOException
*/
@AfterClass
public static void rampDownAfterClass() throws IOException {

if (n5 != null) {
Assert.assertTrue(n5.remove());
n5 = null;
}
}

@Test
public void testCreateGroup() {

Expand Down
18 changes: 10 additions & 8 deletions src/test/java/org/janelia/saalfeldlab/n5/N5FSTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

import java.io.IOException;

import org.junit.Before;
import org.junit.Rule;
import org.junit.rules.TemporaryFolder;

/**
* Initiates testing of the filesystem-based N5 implementation.
*
Expand All @@ -26,14 +30,12 @@
*/
public class N5FSTest extends AbstractN5Test {

static private String testDirPath = System.getProperty("user.home") + "/tmp/n5-test";

/**
* @throws IOException
*/
@Override
protected N5Writer createN5Writer() throws IOException {
@Rule
public TemporaryFolder temp = new TemporaryFolder();

return new N5FSWriter(testDirPath);
@Before
public void setUp() throws IOException {
n5 = new N5FSWriter(temp.newFolder("n5-test").getAbsolutePath());
}

}

0 comments on commit 4b2991c

Please sign in to comment.