@Test
public final void testJail() throws SQLException, IOException {
MockStendlRPWorld.get().addRPZone(new StendhalRPZone("-1_semos_jail", 100, 100));
final Player player = PlayerTestHelper.createPlayer("hugo");
PlayerTestHelper.registerPlayer(player, "-1_semos_jail");
player.setAdminLevel(5000);
RPAction action = new RPAction();
action.put("type", "jail");
CommandCenter.execute(player, action);
assertEquals("Usage: /jail <name> <minutes> <reason>", player.events().get(0).get("text"));
if (!DAORegister.get().get(CharacterDAO.class).hasCharacter("offlineplayer")) {
RPObject rpobject = new RPObject();
rpobject.setRPClass("player");
rpobject.put("name", "offlineplayer");
DAORegister.get().get(CharacterDAO.class).addCharacter("offlineplayer", "offlineplayer", rpobject);
}
player.clearEvents();
action = new RPAction();
action.put("type", "jail");
action.put("target", "offlineplayer");
action.put("reason", "whynot");
action.put("minutes", 1);
CommandCenter.execute(player, action);
assertEquals("You have jailed offlineplayer for 1 minutes. Reason: whynot.", player.events().get(0).get("text"));
assertEquals("JailKeeper asks for support to ADMIN: hugo jailed offlineplayer for 1 minutes. Reason: whynot.", player.events().get(1).get("text"));
assertEquals("Player offlineplayer is not online, but the arrest warrant has been recorded anyway.", player.events().get(2).get("text"));
player.clearEvents();
player.clearEvents();
action = new RPAction();
action.put("type", "jail");
action.put("target", "notexistingplayerxckjvhyxkjcvhyxkjvchk");
action.put("reason", "whynot");
action.put("minutes", 1);
CommandCenter.execute(player, action);
assertEquals("No character with that name: notexistingplayerxckjvhyxkjcvhyxkjvchk", player.events().get(0).get("text"));
player.clearEvents();
MockStendhalRPRuleProcessor.get().addPlayer(player);
action = new RPAction();
action.put("type", "jail");
action.put("target", "hugo");
action.put("reason", "whynot");
action.put("minutes", "noNumber");
CommandCenter.execute(player, action);
assertEquals("Usage: /jail <name> <minutes> <reason>", player.events().get(0).get("text"));
player.clearEvents();
action = new RPAction();
action.put("type", "jail");
action.put("target", "hugo");
action.put("reason", "whynot");
action.put("minutes", 1);
assertTrue(CommandCenter.execute(player, action));
assertThat(player.events().get(0).get("text"), startsWith("You have been jailed for 1 minutes. Reason: whynot."));
}