package org.royaldev.royalcommands;

import org.bukkit.Material;
import org.junit.Test;
import org.royaldev.royalcommands.opencsv.CSVReader;

import java.io.File;
import java.io.FileReader;
import java.io.Reader;
import java.util.logging.Logger;

import static org.junit.Assert.assertTrue;

public class TestAliases {

    @Test
    public void testAliases() throws Throwable {
        final Logger l = Logger.getLogger("org.royaldev.royalcommands");
        final File csv = new File("src/main/resources/items.csv");
        assertTrue("No items.csv found!", csv.exists());
        final Reader in = new FileReader(csv);
        final ItemNameManager inm = new ItemNameManager(new CSVReader(in).readAll());
        boolean allAliasesExist = true;
        for (final Material m : Material.values()) {
            if (inm.aliasExists(m)) continue;
            if (allAliasesExist) allAliasesExist = false;
            l.warning("Missing alias for Material " + m.name() + ".");
        }
        assertTrue("Missing aliases!", allAliasesExist);
    }

}

@@ -58,16 +58,126 @@
 terial;%0A
+import org.bukkit.configuration.ConfigurationSection;%0Aimport org.bukkit.configuration.file.YamlConfiguration;%0A
 import o
@@ -308,32 +308,83 @@
 java.io.Reader;%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0A
 import java.util
@@ -442,41 +442,493 @@
 sert
-True;%0A%0Apublic class TestAliases %7B
+False;%0Aimport static org.junit.Assert.assertTrue;%0A%0Apublic class TestAliases %7B%0A%0A    private YamlConfiguration pluginYml = null;%0A%0A    private YamlConfiguration getPluginYml() %7B%0A        if (this.pluginYml == null) %7B%0A            final File pluginFile = new File(%22src/main/resources/plugin.yml%22);%0A            assertTrue(%22No plugin.yml found!%22, pluginFile.exists());%0A            this.pluginYml = YamlConfiguration.loadConfiguration(pluginFile);%0A        %7D%0A        return this.pluginYml;%0A    %7D
 %0A%0A  
@@ -1656,10 +1656,703 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void testCommandAliases() throws Throwable %7B%0A        final ConfigurationSection reflectCommands = this.getPluginYml().getConfigurationSection(%22reflectcommands%22);%0A        final List%3CString%3E usedAliases = new ArrayList%3C%3E();%0A        for (String key : reflectCommands.getKeys(false)) %7B%0A            final ConfigurationSection cs = reflectCommands.getConfigurationSection(key);%0A            final List%3CString%3E aliases = cs.getStringList(%22aliases%22);%0A            for (String alias : aliases) %7B%0A                assertFalse(%22Alias %22 + alias + %22 is reused in command %22 + key + %22.%22, usedAliases.contains(alias));%0A            %7D%0A            usedAliases.addAll(aliases);%0A        %7D%0A    %7D%0A%0A
 %7D%0A

Test for reused aliases