Skip to content

Commit f47a04d

Browse files
committed
Add unit tests for enumNamesAsList and readerBackendDescriptions
1 parent e2fe2d8 commit f47a04d

1 file changed

Lines changed: 44 additions & 2 deletions

File tree

src/test/java/sc/fiji/ome/zarr/plugins/DragAndDropBehaviorSettingsTest.java

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
* %%
77
* Redistribution and use in source and binary forms, with or without
88
* modification, are permitted provided that the following conditions are met:
9-
*
9+
*
1010
* 1. Redistributions of source code must retain the above copyright notice,
1111
* this list of conditions and the following disclaimer.
1212
* 2. Redistributions in binary form must reproduce the above copyright notice,
1313
* this list of conditions and the following disclaimer in the documentation
1414
* and/or other materials provided with the distribution.
15-
*
15+
*
1616
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1717
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1818
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -33,13 +33,18 @@
3333
import java.lang.reflect.Field;
3434
import java.lang.reflect.InvocationTargetException;
3535
import java.lang.reflect.Method;
36+
import java.util.Arrays;
37+
import java.util.Collections;
38+
import java.util.List;
39+
import java.util.stream.Collectors;
3640

3741
import org.junit.jupiter.api.Test;
3842
import org.scijava.Context;
3943
import org.scijava.prefs.PrefService;
4044

4145
import sc.fiji.ome.zarr.settings.ZarrDragAndDropOpenSettings;
4246
import sc.fiji.ome.zarr.settings.ZarrOpenBehavior;
47+
import sc.fiji.ome.zarr.settings.ZarrReaderBackend;
4348

4449
/**
4550
* Unit tests for the {@link DragAndDropBehaviorSettings#run()} method.
@@ -84,4 +89,41 @@ void testRunUISavesChosenOpenOption() throws NoSuchFieldException, SecurityExcep
8489

8590
}
8691
}
92+
93+
@Test
94+
void testEnumNamesAsListReturnsAllDescriptionsInDeclarationOrder()
95+
{
96+
final List< String > expected =
97+
Arrays.stream( ZarrOpenBehavior.values() ).map( ZarrOpenBehavior::getDescription ).collect( Collectors.toList() );
98+
final List< String > actual = DragAndDropBehaviorSettings.enumNamesAsList( ZarrOpenBehavior.values() );
99+
assertEquals( expected, actual );
100+
// Sanity-check a couple of entries explicitly so the test catches a
101+
// mistaken switch from getDescription() to name() or to toString().
102+
assertEquals( "Open the highest available single-resolution in ImageJ", actual.get( 0 ) );
103+
assertEquals( ZarrOpenBehavior.values().length, actual.size() );
104+
}
105+
106+
@Test
107+
void testEnumNamesAsListIsEmptyForEmptyInput()
108+
{
109+
assertEquals( Collections.emptyList(), DragAndDropBehaviorSettings.enumNamesAsList( new ZarrOpenBehavior[ 0 ] ) );
110+
}
111+
112+
@Test
113+
void testReaderBackendDescriptionsReturnsAllDescriptionsInDeclarationOrder()
114+
{
115+
final List< String > expected =
116+
Arrays.stream( ZarrReaderBackend.values() ).map( ZarrReaderBackend::getDescription ).collect( Collectors.toList() );
117+
final List< String > actual = DragAndDropBehaviorSettings.readerBackendDescriptions( ZarrReaderBackend.values() );
118+
assertEquals( expected, actual );
119+
// Anchored explicit values: these are the strings the settings dialog
120+
// presents to the user, so a stealth rename should fail this test.
121+
assertEquals( Arrays.asList( "N5", "zarr-java" ), actual );
122+
}
123+
124+
@Test
125+
void testReaderBackendDescriptionsIsEmptyForEmptyInput()
126+
{
127+
assertEquals( Collections.emptyList(), DragAndDropBehaviorSettings.readerBackendDescriptions( new ZarrReaderBackend[ 0 ] ) );
128+
}
87129
}

0 commit comments

Comments
 (0)