### Question:
PlayerCommand implements ExecutableCommand { @Override public void executeCommand(CommandSender sender, List<String> arguments) { if (sender instanceof Player) { runCommand((Player) sender, arguments); } else { String alternative = getAlternativeCommand(); if (alternative != null) { sender.sendMessage("Player only! Please use " + alternative + " instead."); } else { sender.sendMessage("This command is only for players."); } } }  @Override void executeCommand(CommandSender sender, List<String> arguments);  }### Answer:
@Test public void shouldRejectNonPlayerSender() { CommandSender sender = mock(BlockCommandSender.class); PlayerCommandImpl command = new PlayerCommandImpl(); command.executeCommand(sender, Collections.emptyList()); verify(sender).sendMessage(argThat(containsString("only for players"))); }
@Test public void shouldCallRunCommandForPlayer() { Player player = mock(Player.class); List<String> arguments = Arrays.asList("arg1", "testarg2"); PlayerCommandImpl command = new PlayerCommandImpl(); command.executeCommand(player, arguments); verify(player, times(1)).sendMessage("testarg2"); }
@Test public void shouldRejectNonPlayerAndSendAlternative() { CommandSender sender = mock(CommandSender.class); PlayerCommandWithAlt command = new PlayerCommandWithAlt(); command.executeCommand(sender, Collections.emptyList()); verify(sender, times(1)).sendMessage(argThat(containsString("use /authme test <command> instead"))); }