PluginUtil { public static void getPriorityCommandFromString(List<PluginPriorityCommand> commands, String commandString) throws Exception { try { if (commandString != null) { String[] parts = commandString.split(","); for (String cmd : parts) { if (cmd.split(":").length == 2) { commands.add(new PluginPriorityCommand(cmd.split(":")[0], Float.parseFloat(cmd.split(":")[1]))); } else { commands.add(new PluginPriorityCommand(cmd, 0)); } } } } catch (NumberFormatException e) { throw new Exception("Priority number type error. Float is expected"); } }  static String getRootPath(); static List<URL> getPluginsJarList(); static List<PluginPriorityCommand> getExtendCommandList(); static void getPriorityCommandFromString(List<PluginPriorityCommand> commands,
                                                  String commandString); static Properties getPluginProperty(Class<?> cls); static void printPluginCommandPriority();  }
@Test public void normalTest() throws Exception { List<PluginPriorityCommand> commandList = new ArrayList<PluginPriorityCommand>(); PluginUtil.getPriorityCommandFromString(commandList, commandString1); Collections.sort(commandList); int i = 0; for (PluginPriorityCommand command : commandList) { i++; Assert.assertEquals(command.getCommandName(), "command_test" + i); } }
@Test public void boundAndDefalutTest() throws Exception { List<PluginPriorityCommand> commandList = new ArrayList<PluginPriorityCommand>(); PluginUtil.getPriorityCommandFromString(commandList, commandString2); Collections.sort(commandList); int i = 0; Assert.assertEquals("command_testMax", (commandList.get(i)).getCommandName()); Assert.assertTrue(PluginPriorityCommand.MAX_PRIORITY == (commandList.get(i).getCommandPriority())); i++; Assert.assertEquals("command_test", (commandList.get(i)).getCommandName()); Assert.assertTrue(0 == (commandList.get(i).getCommandPriority())); i++; Assert.assertEquals("command_testMin", (commandList.get(i)).getCommandName()); Assert.assertTrue(PluginPriorityCommand.MIN_PRIORITY == (commandList.get(i).getCommandPriority())); commandList.add(new PluginPriorityCommand("command_test2", 20)); Collections.sort(commandList); Assert.assertEquals("command_test2", (commandList.get(1)).getCommandName()); Assert.assertTrue(20 == (commandList.get(1).getCommandPriority())); }
@Test(expected = Exception.class) public void priorityTypeErrorTest() throws Exception { List<PluginPriorityCommand> commandList = new ArrayList<PluginPriorityCommand>(); PluginUtil.getPriorityCommandFromString(commandList, commandString3); }