94 lines
2.9 KiB
Java
94 lines
2.9 KiB
Java
package games.dmg.spigotbase;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
|
|
import java.io.InputStream;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.yaml.snakeyaml.Yaml;
|
|
|
|
final class PluginMetadataTest {
|
|
@Test
|
|
void homeadminAliasesBaseadmin() {
|
|
Map<?, ?> commands = commands();
|
|
|
|
Map<?, ?> admin = (Map<?, ?>) commands.get("baseadmin");
|
|
assertEquals(List.of("homeadmin"), admin.get("aliases"));
|
|
}
|
|
|
|
@Test
|
|
void doesNotDeclareSupersededSettingsCommands() {
|
|
Map<?, ?> commands = commands();
|
|
|
|
for (String command : List.of(
|
|
"baseprogress", "basenavigation", "baseflight", "basevisitors"
|
|
)) {
|
|
assertFalse(commands.containsKey(command), command);
|
|
}
|
|
}
|
|
|
|
@Test
|
|
void homesettingsAliasesBasesettings() {
|
|
Map<?, ?> commands = commands();
|
|
|
|
Map<?, ?> settings = (Map<?, ?>) commands.get("basesettings");
|
|
assertNotNull(settings);
|
|
assertEquals(List.of("homesettings"), settings.get("aliases"));
|
|
}
|
|
|
|
@Test
|
|
void sethomeAliasesSetbase() {
|
|
Map<?, ?> commands = commands();
|
|
|
|
Map<?, ?> setbase = (Map<?, ?>) commands.get("setbase");
|
|
assertEquals(List.of("sethome"), setbase.get("aliases"));
|
|
}
|
|
|
|
@Test
|
|
void homeAliasesBase() {
|
|
Map<?, ?> commands = commands();
|
|
|
|
Map<?, ?> base = (Map<?, ?>) commands.get("base");
|
|
assertEquals(List.of("home"), base.get("aliases"));
|
|
}
|
|
|
|
@Test
|
|
void visitAliasesGotobase() {
|
|
Map<?, ?> commands = commands();
|
|
|
|
Map<?, ?> gotobase = (Map<?, ?>) commands.get("gotobase");
|
|
assertEquals(List.of("visit"), gotobase.get("aliases"));
|
|
}
|
|
|
|
@Test
|
|
void declaresPluginEntrypointCommandsAndPermissions() {
|
|
InputStream stream = getClass().getClassLoader().getResourceAsStream("plugin.yml");
|
|
assertNotNull(stream);
|
|
|
|
Map<?, ?> plugin = new Yaml().load(stream);
|
|
assertEquals("SpigotBase", plugin.get("name"));
|
|
assertEquals("games.dmg.spigotbase.SpigotBasePlugin", plugin.get("main"));
|
|
assertEquals("1.20", plugin.get("api-version"));
|
|
|
|
Map<?, ?> commands = (Map<?, ?>) plugin.get("commands");
|
|
for (String command : new String[] {
|
|
"setbase", "base", "gotobase", "basesettings", "baseadmin"
|
|
}) {
|
|
assertNotNull(commands.get(command), command);
|
|
}
|
|
|
|
Map<?, ?> permissions = (Map<?, ?>) plugin.get("permissions");
|
|
assertNotNull(permissions.get("spigotbase.admin"));
|
|
}
|
|
|
|
private Map<?, ?> commands() {
|
|
InputStream stream = getClass().getClassLoader().getResourceAsStream("plugin.yml");
|
|
assertNotNull(stream);
|
|
Map<?, ?> plugin = new Yaml().load(stream);
|
|
return (Map<?, ?>) plugin.get("commands");
|
|
}
|
|
}
|