diff --git a/cdm/zarr/src/test/java/ucar/nc2/iosp/zarr/TestZarrIosp.java b/cdm/zarr/src/test/java/ucar/nc2/iosp/zarr/TestZarrIosp.java index fe43236b9c..ac53eced29 100644 --- a/cdm/zarr/src/test/java/ucar/nc2/iosp/zarr/TestZarrIosp.java +++ b/cdm/zarr/src/test/java/ucar/nc2/iosp/zarr/TestZarrIosp.java @@ -5,8 +5,11 @@ package ucar.nc2.iosp.zarr; +import java.nio.file.*; import org.junit.BeforeClass; +import org.junit.ClassRule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import ucar.ma2.Array; import ucar.ma2.DataType; import ucar.ma2.InvalidRangeException; @@ -28,6 +31,9 @@ */ public class TestZarrIosp { + @ClassRule + public static TemporaryFolder tempFolder = new TemporaryFolder(); + // file names private static final String ZARR_FILENAME = "zarr_test_data.zarr/"; private static final String ZARR_ZIP_NAME = "zarr_test_data.zip"; @@ -46,6 +52,8 @@ public class TestZarrIosp { // Non zarr zipped file private static final String NON_ZARR_DATA = ZarrTestsCommon.LOCAL_TEST_DATA_PATH + NON_ZARR_FILENAME; + // Copy to temp folder so unzipped file created when opened will get cleaned up after test + private static String TEMP_NON_ZARR_DATA; // fill values file private static final String FILL_VALUES_DATA = ZarrTestsCommon.LOCAL_TEST_DATA_PATH + FILL_VALUES_FILENAME; @@ -53,11 +61,14 @@ public class TestZarrIosp { private static List stores; @BeforeClass - public static void setUpTests() { + public static void setUpTests() throws IOException { stores = new ArrayList<>(); stores.add(DIRECTORY_STORE_URI); stores.add(ZIP_STORE_URI); stores.add(OBJECT_STORE_ZARR_URI); + + TEMP_NON_ZARR_DATA = + Files.copy(Paths.get(NON_ZARR_DATA), Paths.get(tempFolder.getRoot().toString(), NON_ZARR_FILENAME)).toString(); } @Test @@ -72,7 +83,7 @@ public void testIsValidFile() throws IOException { @Test public void testNonZarrZipIsNotValid() throws IOException { ZarrIosp iosp = new ZarrIosp(); - assertThat(iosp.isValidFile(NetcdfFiles.getRaf(NON_ZARR_DATA, -1))).isFalse(); + assertThat(iosp.isValidFile(NetcdfFiles.getRaf(TEMP_NON_ZARR_DATA, -1))).isFalse(); } ////////////////////////////////////////////////////// @@ -254,7 +265,7 @@ private void _testUninitialized(String location) throws IOException, InvalidRang @Test public void testReadNonZarrZipFile() throws IOException { - try (NetcdfFile ncfile = NetcdfFiles.open(NON_ZARR_DATA)) { + try (NetcdfFile ncfile = NetcdfFiles.open(TEMP_NON_ZARR_DATA)) { assertThat(ncfile).isNotNull(); assertThat(ncfile.findDimension("x")).isNotNull(); }