@Test public void testHelpMessage() { TestHelper.load(); String helpMessage = "DESCRIPTION:\n" + "Add or remove gold from different targets.\n" + "commerce <target> <operation> <quantity>\n" + "\t <target> - player, bank\n" + "\t <operation> - add, remove\n" + "\t <quantity> - integer\n" + "Example:\n" + "\tcommerce player add 100"; assertEquals(helpMessage, command.execute("help")); }
@Override String execute(Object[] arguments) { String target = ((String) arguments[0]).trim(); String operation = ((String) arguments[1]).trim(); Integer amount; if (!"add".equals(operation) && !"remove".equals(operation)) { return "Invalid operation."; } try { amount = Integer.parseInt((String) arguments[2]); } catch (NumberFormatException e) { return "Specified amount is not a number."; } String result = "Invalid target specified."; if ("player".equals(target)) { result = player(operation, amount); } else if ("bank".equals(target)) { result = bank(operation, amount); } return result; }
CommerceCommand extends Command { @Override String execute(Object[] arguments) { String target = ((String) arguments[0]).trim(); String operation = ((String) arguments[1]).trim(); Integer amount; if (!"add".equals(operation) && !"remove".equals(operation)) { return "Invalid operation."; } try { amount = Integer.parseInt((String) arguments[2]); } catch (NumberFormatException e) { return "Specified amount is not a number."; } String result = "Invalid target specified."; if ("player".equals(target)) { result = player(operation, amount); } else if ("bank".equals(target)) { result = bank(operation, amount); } return result; } }
CommerceCommand extends Command { @Override String execute(Object[] arguments) { String target = ((String) arguments[0]).trim(); String operation = ((String) arguments[1]).trim(); Integer amount; if (!"add".equals(operation) && !"remove".equals(operation)) { return "Invalid operation."; } try { amount = Integer.parseInt((String) arguments[2]); } catch (NumberFormatException e) { return "Specified amount is not a number."; } String result = "Invalid target specified."; if ("player".equals(target)) { result = player(operation, amount); } else if ("bank".equals(target)) { result = bank(operation, amount); } return result; } CommerceCommand(); }
CommerceCommand extends Command { @Override String execute(Object[] arguments) { String target = ((String) arguments[0]).trim(); String operation = ((String) arguments[1]).trim(); Integer amount; if (!"add".equals(operation) && !"remove".equals(operation)) { return "Invalid operation."; } try { amount = Integer.parseInt((String) arguments[2]); } catch (NumberFormatException e) { return "Specified amount is not a number."; } String result = "Invalid target specified."; if ("player".equals(target)) { result = player(operation, amount); } else if ("bank".equals(target)) { result = bank(operation, amount); } return result; } CommerceCommand();  }
CommerceCommand extends Command { @Override String execute(Object[] arguments) { String target = ((String) arguments[0]).trim(); String operation = ((String) arguments[1]).trim(); Integer amount; if (!"add".equals(operation) && !"remove".equals(operation)) { return "Invalid operation."; } try { amount = Integer.parseInt((String) arguments[2]); } catch (NumberFormatException e) { return "Specified amount is not a number."; } String result = "Invalid target specified."; if ("player".equals(target)) { result = player(operation, amount); } else if ("bank".equals(target)) { result = bank(operation, amount); } return result; } CommerceCommand();   }