Skip to content

Commit 27a482d

Browse files
authored
Merge pull request #215 from jonesbusy/feature/remove-common-lang
Remove usages of Commons Lang 2
2 parents a22c30a + c0e549c commit 27a482d

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

src/test/java/io/jenkins/plugins/oss/symbols/OpenSourceSymbolsTest.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22

33
import 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;
77
import java.util.Comparator;
88
import java.util.List;
99
import 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;
1411
import org.junit.jupiter.api.Test;
1512

1613
class 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

Comments
 (0)