### Question:
ForceLoginCommand implements ExecutableCommand { @Override public void executeCommand(CommandSender sender, List<String> arguments) { String playerName = arguments.isEmpty() ? sender.getName() : arguments.get(0); Player player = bukkitService.getPlayerExact(playerName); if (player == null || !player.isOnline()) { sender.sendMessage("Player needs to be online!"); } else if (!permissionsManager.hasPermission(player, CAN_LOGIN_BE_FORCED)) { sender.sendMessage("You cannot force login the player " + playerName + "!"); } else { management.forceLogin(player); sender.sendMessage("Force login for " + playerName + " performed!"); } }  @Override void executeCommand(CommandSender sender, List<String> arguments);  }### Answer:
@Test public void shouldRejectOfflinePlayer() { String playerName = "Bobby"; Player player = mockPlayer(false); given(bukkitService.getPlayerExact(playerName)).willReturn(player); CommandSender sender = mock(CommandSender.class); command.executeCommand(sender, Collections.singletonList(playerName)); verify(bukkitService).getPlayerExact(playerName); verify(sender).sendMessage("Player needs to be online!"); verifyZeroInteractions(management); }
@Test public void shouldRejectInexistentPlayer() { String playerName = "us3rname01"; given(bukkitService.getPlayerExact(playerName)).willReturn(null); CommandSender sender = mock(CommandSender.class); command.executeCommand(sender, Collections.singletonList(playerName)); verify(bukkitService).getPlayerExact(playerName); verify(sender).sendMessage("Player needs to be online!"); verifyZeroInteractions(management); }
@Test public void shouldRejectPlayerWithMissingPermission() { String playerName = "testTest"; Player player = mockPlayer(true); given(bukkitService.getPlayerExact(playerName)).willReturn(player); given(permissionsManager.hasPermission(player, PlayerPermission.CAN_LOGIN_BE_FORCED)).willReturn(false); CommandSender sender = mock(CommandSender.class); command.executeCommand(sender, Collections.singletonList(playerName)); verify(bukkitService).getPlayerExact(playerName); verify(sender).sendMessage(argThat(containsString("You cannot force login the player"))); verifyZeroInteractions(management); }
@Test public void shouldForceLoginPlayer() { String playerName = "tester23"; Player player = mockPlayer(true); given(bukkitService.getPlayerExact(playerName)).willReturn(player); given(permissionsManager.hasPermission(player, PlayerPermission.CAN_LOGIN_BE_FORCED)).willReturn(true); CommandSender sender = mock(CommandSender.class); command.executeCommand(sender, Collections.singletonList(playerName)); verify(bukkitService).getPlayerExact(playerName); verify(management).forceLogin(player); }
@Test public void shouldForceLoginSenderSelf() { String senderName = "tester23"; Player player = mockPlayer(true); given(bukkitService.getPlayerExact(senderName)).willReturn(player); given(permissionsManager.hasPermission(player, PlayerPermission.CAN_LOGIN_BE_FORCED)).willReturn(true); CommandSender sender = mock(CommandSender.class); given(sender.getName()).willReturn(senderName); command.executeCommand(sender, Collections.emptyList()); verify(bukkitService).getPlayerExact(senderName); verify(management).forceLogin(player); }