Better error for unknown icon material, and test class

This commit is contained in:
tastybento 2023-07-08 08:52:20 -07:00
parent 9a464ab795
commit 4ef974fbde
2 changed files with 25 additions and 3 deletions

View File

@ -125,7 +125,11 @@ public class AddonClassLoader extends URLClassLoader {
if (softDepend != null) {
builder.softDependencies(Arrays.asList(softDepend.split("\\s*,\\s*")));
}
builder.icon(Objects.requireNonNull(Material.getMaterial(data.getString("icon", "PAPER").toUpperCase(Locale.ENGLISH))));
Material icon = Material.getMaterial(data.getString("icon", "PAPER").toUpperCase(Locale.ENGLISH));
if (icon == null) {
throw new InvalidAddonDescriptionException("'icon' tag refers to an unknown Material: " + data.getString("icon"));
}
builder.icon(Objects.requireNonNull(icon));
String apiVersion = data.getString("api-version");
if (apiVersion != null) {

View File

@ -53,7 +53,8 @@ public class AddonClassLoaderTest {
MAIN,
NAME,
VERSION,
AUTHORS
AUTHORS,
ICON
}
/**
* Used for file writing etc.
@ -129,7 +130,11 @@ public class AddonClassLoaderTest {
r.set("repository", "repo");
r.set("depend", "Level, Warps");
r.set("softdepend", "Boxed, AcidIsland");
r.set("icon", "IRON_INGOT");
if (!missingTags.contains(mandatoryTags.ICON)) {
r.set("icon", "IRON_INGOT");
} else {
r.set("icon", "unkOwnMateriaL");
}
r.set("api-version", "1.21-SNAPSHOT");
return r;
}
@ -278,6 +283,19 @@ public class AddonClassLoaderTest {
}
}
/**
* Test method for {@link world.bentobox.bentobox.api.addons.AddonClassLoader#asDescription(org.bukkit.configuration.file.YamlConfiguration)}.
*/
@Test
public void testAsDescriptionUnknownIconMaterial() {
YamlConfiguration yml = this.getYaml(List.of(mandatoryTags.ICON));
try {
AddonClassLoader.asDescription(yml);
} catch (InvalidAddonDescriptionException e) {
assertEquals("AddonException : 'icon' tag refers to an unknown Material: unkOwnMateriaL", e.getMessage());
}
}
/**
* Test method for {@link world.bentobox.bentobox.api.addons.AddonClassLoader#findClass(java.lang.String)}.
*/