verify that icon paths are valid
package lermitage.intellij.extra.icons.cfg;
+import lermitage.intellij.extra.icons.ExtraIconProvider;
+import lermitage.intellij.extra.icons.providers.Angular2IconProvider;
import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -28,10 +30,14 @@ public class ResourcesTest {
@BeforeAll
static void setUp() {
- File iconsFolder = new File("src/main/resources/extra-icons/");
- icons = Arrays.asList(Objects.requireNonNull(
+ icons = new ArrayList<>();
+ List<File> iconsFolders = Arrays.asList(
+ new File("src/main/resources/extra-icons/"),
+ new File("src/main/resources/extra-icons/ide/"),
+ new File("src/main/resources/extra-icons/officedocs/"));
+ iconsFolders.forEach(iconsFolder -> icons.addAll(Arrays.asList(Objects.requireNonNull(
iconsFolder.listFiles((dir, name) -> name.endsWith(".png") || name.endsWith(".svg"))
- ));
+ ))));
pngIcons = icons.stream().filter(file -> file.getName().endsWith(".png")).collect(Collectors.toList());
svgIcons = icons.stream().filter(file -> file.getName().endsWith(".svg")).collect(Collectors.toList());
assertTrue(svgIcons.size() > 0);
@@ -126,4 +132,48 @@ public class ResourcesTest {
fail("some SVG icons are not 16x16: " + errors);
}
}
+
+ @Test
+ public void extra_icons_provider_icons_should_exist() {
+ List<String> errors = new ArrayList<>();
+
+ List<String> iconNames = icons.stream().map(file -> {
+ String relativePath = file.getAbsolutePath().replaceAll("\\\\", "/");
+ relativePath = relativePath.substring(relativePath.lastIndexOf("/extra-icons/") + "/extra-icons/".length());
+ return relativePath;
+ }).collect(Collectors.toList());
+
+ ExtraIconProvider.allModels().forEach(model -> {
+ String extraIconName = model.getIcon().replace("/extra-icons/", "");
+ if (!iconNames.contains(extraIconName)) {
+ errors.add(model.getId() + " model's icon " + extraIconName + " not found");
+ }
+ });
+
+ if (!errors.isEmpty()) {
+ fail("some ExtraIconProvider model icons not found: " + errors);
+ }
+ }
+
+ @Test
+ public void angular2_icons_provider_icons_should_exist() {
+ List<String> errors = new ArrayList<>();
+
+ List<String> iconNames = icons.stream().map(file -> {
+ String relativePath = file.getAbsolutePath().replaceAll("\\\\", "/");
+ relativePath = relativePath.substring(relativePath.lastIndexOf("/extra-icons/") + "/extra-icons/".length());
+ return relativePath;
+ }).collect(Collectors.toList());
+
+ Angular2IconProvider.allModels().forEach(model -> {
+ String extraIconName = model.getIcon().replace("/extra-icons/", "");
+ if (!iconNames.contains(extraIconName)) {
+ errors.add(model.getId() + " model's icon " + extraIconName + " not found");
+ }
+ });
+
+ if (!errors.isEmpty()) {
+ fail("some Angular2IconProvider model icons not found: " + errors);
+ }
+ }
}
