|
6 | 6 | * %% |
7 | 7 | * Redistribution and use in source and binary forms, with or without |
8 | 8 | * modification, are permitted provided that the following conditions are met: |
9 | | - * |
| 9 | + * |
10 | 10 | * 1. Redistributions of source code must retain the above copyright notice, |
11 | 11 | * this list of conditions and the following disclaimer. |
12 | 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
13 | 13 | * this list of conditions and the following disclaimer in the documentation |
14 | 14 | * and/or other materials provided with the distribution. |
15 | | - * |
| 15 | + * |
16 | 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
17 | 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
18 | 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
33 | 33 | import java.lang.reflect.Field; |
34 | 34 | import java.lang.reflect.InvocationTargetException; |
35 | 35 | 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; |
36 | 40 |
|
37 | 41 | import org.junit.jupiter.api.Test; |
38 | 42 | import org.scijava.Context; |
39 | 43 | import org.scijava.prefs.PrefService; |
40 | 44 |
|
41 | 45 | import sc.fiji.ome.zarr.settings.ZarrDragAndDropOpenSettings; |
42 | 46 | import sc.fiji.ome.zarr.settings.ZarrOpenBehavior; |
| 47 | +import sc.fiji.ome.zarr.settings.ZarrReaderBackend; |
43 | 48 |
|
44 | 49 | /** |
45 | 50 | * Unit tests for the {@link DragAndDropBehaviorSettings#run()} method. |
@@ -84,4 +89,41 @@ void testRunUISavesChosenOpenOption() throws NoSuchFieldException, SecurityExcep |
84 | 89 |
|
85 | 90 | } |
86 | 91 | } |
| 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 | + } |
87 | 129 | } |
0 commit comments