1111import org .janelia .saalfeldlab .n5 .hdf5 .N5HDF5Writer ;
1212import org .janelia .saalfeldlab .n5 .zarr .ZarrKeyValueReader ;
1313import org .janelia .saalfeldlab .n5 .zarr .ZarrKeyValueWriter ;
14+ import org .janelia .saalfeldlab .n5 .zarr .v3 .ZarrV3KeyValueReader ;
1415import org .janelia .saalfeldlab .n5 .zarr .v3 .ZarrV3KeyValueWriter ;
1516import org .junit .Test ;
17+ import org .junit .runners .Parameterized ;
1618
1719import java .io .File ;
1820import java .io .IOException ;
@@ -280,6 +282,42 @@ public void testDefaultForAmbiguousWriters() throws IOException {
280282 }
281283 }
282284
285+ @ Test
286+ public void testAmbiguousZarrFormat () throws IOException {
287+
288+ final N5Factory factory = new N5Factory ();
289+ File tmpDir = Files .createTempDirectory ("factory-test-" ).toFile ();
290+
291+ /* by default, should be zarr 3 with no other information */
292+ URI doesntExistsIsZarr3 = tmpDir .toPath ().resolve ("doesnt_exists_is_zarr3" ).toUri ();
293+ N5Writer n5 = factory .openWriter (StorageFormat .ZARR , doesntExistsIsZarr3 );
294+ assertEquals (ZarrV3KeyValueWriter .class , n5 .getClass ());
295+
296+ /* If a zarr2 container exists, it should correctly return zarr2 */
297+ URI explicitZarr2 = tmpDir .toPath ().resolve ("explicit_zarr2" ).toUri ();
298+ N5Writer explicitZarr2n5 = factory .openWriter (StorageFormat .ZARR2 , explicitZarr2 );
299+ assertEquals (ZarrKeyValueWriter .class , explicitZarr2n5 .getClass ());
300+
301+ N5Reader guessZarr2Reader = factory .openReader (StorageFormat .ZARR , explicitZarr2 );
302+ assertEquals (ZarrKeyValueReader .class , guessZarr2Reader .getClass ());
303+
304+ N5Reader guessZarr2Writer = factory .openWriter (StorageFormat .ZARR , explicitZarr2 );
305+ assertEquals (ZarrKeyValueWriter .class , guessZarr2Writer .getClass ());
306+
307+ /* If zarr container is valid Zarr2 and Zarr3, should return zarr3 preferentially */
308+ URI bothZarrs = tmpDir .toPath ().resolve ("both_zarr2_zarr3" ).toUri ();
309+ N5Writer bothZarr2 = factory .openWriter (StorageFormat .ZARR2 , bothZarrs );
310+ assertEquals (ZarrKeyValueReader .class , factory .openReader (StorageFormat .ZARR , bothZarrs ).getClass ());
311+ assertEquals (ZarrKeyValueWriter .class , factory .openWriter (StorageFormat .ZARR , bothZarrs ).getClass ());
312+
313+ N5Writer bothZarr3 = factory .openWriter (StorageFormat .ZARR3 , bothZarrs );
314+ assertEquals (ZarrV3KeyValueReader .class , factory .openReader (StorageFormat .ZARR , bothZarrs ).getClass ());
315+ assertEquals (ZarrV3KeyValueWriter .class , factory .openWriter (StorageFormat .ZARR , bothZarrs ).getClass ());
316+
317+ assertEquals (ZarrKeyValueReader .class , factory .openReader (StorageFormat .ZARR2 , bothZarrs ).getClass ());
318+ assertEquals (ZarrKeyValueWriter .class , factory .openWriter (StorageFormat .ZARR2 , bothZarrs ).getClass ());
319+ }
320+
283321 @ Test
284322 public void testForExistingWriters () throws IOException {
285323
@@ -292,7 +330,7 @@ public void testForExistingWriters() throws IOException {
292330 final Object [][] testData = new Object [][] {
293331 {"h5WithWeirdExtension.zarr" , StorageFormat .HDF5 , N5HDF5Writer .class },
294332 {"zarr2WithWeirdExtension.n5" , StorageFormat .ZARR2 , ZarrKeyValueWriter .class },
295- {"zarr3WithWeirdExtension.jpg" , StorageFormat .ZARR , ZarrV3KeyValueWriter .class },
333+ {"zarr3WithWeirdExtension.jpg" , StorageFormat .ZARR3 , ZarrV3KeyValueWriter .class },
296334 {"n5WithWeirdExtension.h5" , StorageFormat .N5 , N5KeyValueWriter .class },
297335 };
298336
0 commit comments