### Question:
MessageService { public String manageMessage(String mess) { Command c; Trigger t = null; Reaction r; String tokenMess[] = mess.split(" "); String triggername = ""; int conditionSep = 0; if (tokenMess[0].equalsIgnoreCase(HELP)) { return help(tokenMess); } if (tokenMess[0].equalsIgnoreCase(LIST)) { return list(tokenMess); } if (tokenMess[0].equalsIgnoreCase(IF) || tokenMess[0].equalsIgnoreCase(WHEN)) { for (int i = 1; i < tokenMess.length; i++) { if (tokenMess[i].equalsIgnoreCase(THEN)) { triggername = unsplit(tokenMess, 1, i - 1, " "); conditionSep = i + 1; break; } } List<Trigger> lst = api.triggers().findByName(triggername); if (!lst.isEmpty()) { t = lst.get(0); } } String commandName = unsplit(tokenMess, conditionSep, tokenMess.length - conditionSep, " "); List<Nlp.Rank<Command>> mostSimilar; try { mostSimilar = nlpCommands.computeSimilarity(commandName, 10); if (commandName.contains("*")) { String response = ""; for (Nlp.Rank<Command> nlpr : mostSimilar) { response += "? " + nlpr.getElement().getName() + "\n"; } return response; } if (!mostSimilar.isEmpty() && mostSimilar.get(0).getSimilarity() > 0) { c = mostSimilar.get(0).getElement(); } else { return "No available commands similar to: " + commandName; } } catch (NoResultsException e) { return "No available commands similar to: " + commandName; } if (tokenMess[0].equalsIgnoreCase(IF)) { Trigger NEWt = t.clone(); NEWt.setNumberOfExecutions(1); r = new Reaction(NEWt, c); api.reactions().create(r); } else if (tokenMess[0].equalsIgnoreCase(WHEN)) { r = new Reaction(t, c); api.reactions().create(r); } else { api.bus().send(c); return c.getName() + "\n DONE."; } return "DONE"; } @Inject  MessageService(NlpCommand nlpCommands, API api); String manageMessage(String mess); static String IF; static String THEN; static String WHEN; static String HELP; static String LIST; static String TRIGGER; }### Answer:
@Test public void testCommand() { String mess = "*"; String expResult = "? pippo"; String result = msg.manageMessage(mess); assertTrue(result.startsWith(expResult)); mess = "pippo"; expResult = mess + "\n DONE."; result = msg.manageMessage(mess); assertEquals(expResult, result); mess = "abcde"; expResult = "No available commands similar to: "+ mess; result = msg.manageMessage(mess); assertEquals(expResult, result); }
@Test public void testTrigger() { String mess = "list trigger"; String expResult = "? \npluto\n"; String result = msg.manageMessage(mess); assertEquals(expResult, result); }
@Test public void testIFTHEN() { String mess = "if pluto then pippo"; String expResult = "DONE"; String result = msg.manageMessage(mess); assertEquals(expResult, result); mess = "if asdfakjsd then sdfasdas"; expResult = "No available commands similar to: sdfasdas"; result = msg.manageMessage(mess); assertEquals(expResult, result); }