22
33import static org .junit .jupiter .api .Assertions .*;
44
5- import java .io . File ;
6- import java .util . Collection ;
5+ import java .nio . file . Files ;
6+ import java .nio . file . Path ;
77import java .util .Comparator ;
88import java .util .List ;
99import java .util .Map ;
10- import java .util .Map .Entry ;
11- import java .util .stream .Collectors ;
12- import org .apache .commons .io .FileUtils ;
13- import org .apache .commons .lang .StringUtils ;
10+ import java .util .stream .Stream ;
1411import org .junit .jupiter .api .Test ;
1512
1613class OpenSourceSymbolsTest {
@@ -21,24 +18,28 @@ void testGetIconClassName() {
2118 }
2219
2320 @ Test
24- void testGetAvailableIcons () {
21+ void testGetAvailableIcons () throws Exception {
2522 Map <String , String > availableIcons = OpenSourceSymbols .getAvailableIcons ();
2623
2724 assertNotNull (availableIcons );
2825 assertFalse (availableIcons .isEmpty ());
2926
30- Collection <File > icons =
31- FileUtils .listFiles (new File ("./src/main/resources/images/symbols/" ), new String [] {"svg" }, false );
32- assertEquals (icons .size (), availableIcons .size ());
33-
34- List <String > iconNames = icons .stream ()
35- .map (icon -> StringUtils .removeEnd (icon .getName (), ".svg" ))
36- .sorted (Comparator .naturalOrder ())
37- .collect (Collectors .toList ());
38- assertIterableEquals (iconNames , availableIcons .keySet ());
39-
40- for (Entry <String , String > icon : availableIcons .entrySet ()) {
41- assertEquals (icon .getValue (), OpenSourceSymbols .getIconClassName (icon .getKey ()));
27+ Path iconsDir = Path .of ("./src/main/resources/images/symbols/" );
28+ try (Stream <Path > stream = Files .list (iconsDir )) {
29+ List <String > iconNames = stream .filter (path -> path .toString ().endsWith (".svg" ))
30+ .map (path -> {
31+ String fileName = path .getFileName ().toString ();
32+ return fileName .endsWith (".svg" ) ? fileName .substring (0 , fileName .length () - 4 ) : fileName ;
33+ })
34+ .sorted (Comparator .naturalOrder ())
35+ .toList ();
36+
37+ assertEquals (iconNames .size (), availableIcons .size ());
38+ assertIterableEquals (iconNames , availableIcons .keySet ());
39+
40+ for (Map .Entry <String , String > icon : availableIcons .entrySet ()) {
41+ assertEquals (icon .getValue (), OpenSourceSymbols .getIconClassName (icon .getKey ()));
42+ }
4243 }
4344 }
4445}
0 commit comments