### Question:
PurgeLastPositionCommand implements ExecutableCommand { @Override public void executeCommand(final CommandSender sender, List<String> arguments) { String playerName = arguments.isEmpty() ? sender.getName() : arguments.get(0); if ("*".equals(playerName)) { for (PlayerAuth auth : dataSource.getAllAuths()) { resetLastPosition(auth); dataSource.updateQuitLoc(auth); bungeeSender.sendAuthMeBungeecordMessage(MessageType.REFRESH_QUITLOC, playerName); } sender.sendMessage("All players last position locations are now reset"); } else { PlayerAuth auth = dataSource.getAuth(playerName); if (auth == null) { commonService.send(sender, MessageKey.UNKNOWN_USER); return; } resetLastPosition(auth); dataSource.updateQuitLoc(auth); bungeeSender.sendAuthMeBungeecordMessage(MessageType.REFRESH_QUITLOC, playerName); sender.sendMessage(playerName + "'s last position location is now reset"); } }  @Override void executeCommand(final CommandSender sender, List<String> arguments);  }### Answer:
@Test public void shouldPurgeLastPosOfUser() { String player = "_Bobby"; PlayerAuth auth = mock(PlayerAuth.class); given(dataSource.getAuth(player)).willReturn(auth); CommandSender sender = mock(CommandSender.class); command.executeCommand(sender, Collections.singletonList(player)); verify(dataSource).getAuth(player); verifyPositionWasReset(auth); verify(sender).sendMessage(argThat(containsString("last position location is now reset"))); }
@Test public void shouldPurgePositionOfCommandSender() { String player = "_Bobby"; CommandSender sender = mock(CommandSender.class); given(sender.getName()).willReturn(player); PlayerAuth auth = mock(PlayerAuth.class); given(dataSource.getAuth(player)).willReturn(auth); command.executeCommand(sender, Collections.emptyList()); verify(dataSource).getAuth(player); verifyPositionWasReset(auth); verify(sender).sendMessage(argThat(containsString("position location is now reset"))); }
@Test public void shouldHandleNonExistentUser() { String name = "invalidPlayer"; CommandSender sender = mock(CommandSender.class); command.executeCommand(sender, Collections.singletonList(name)); verify(dataSource).getAuth(name); verify(service).send(sender, MessageKey.UNKNOWN_USER); }
@Test public void shouldResetAllLastPositions() { PlayerAuth auth1 = mock(PlayerAuth.class); PlayerAuth auth2 = mock(PlayerAuth.class); PlayerAuth auth3 = mock(PlayerAuth.class); given(dataSource.getAllAuths()).willReturn(Arrays.asList(auth1, auth2, auth3)); CommandSender sender = mock(CommandSender.class); command.executeCommand(sender, Collections.singletonList("*")); verify(dataSource).getAllAuths(); verifyPositionWasReset(auth1); verifyPositionWasReset(auth2); verifyPositionWasReset(auth3); verify(sender).sendMessage(argThat(containsString("last position locations are now reset"))); }