### Question:
GetIpCommand implements ExecutableCommand { @Override public void executeCommand(CommandSender sender, List<String> arguments) { String playerName = arguments.get(0); Player player = bukkitService.getPlayerExact(playerName); PlayerAuth auth = dataSource.getAuth(playerName); if (player != null) { sender.sendMessage("Current IP of " + player.getName() + " is " + PlayerUtils.getPlayerIp(player) + ":" + player.getAddress().getPort()); } if (auth == null) { String displayName = player == null ? playerName : player.getName(); sender.sendMessage(displayName + " is not registered in the database"); } else { sender.sendMessage("Database: last IP: " + auth.getLastIp() + ", registration IP: " + auth.getRegistrationIp()); } }  @Override void executeCommand(CommandSender sender, List<String> arguments);  }### Answer:
@Test public void shouldGetIpOfPlayer() { given(bukkitService.getPlayerExact(anyString())).willReturn(null); given(dataSource.getAuth(anyString())).willReturn(null); CommandSender sender = mock(CommandSender.class); String name = "Testt"; command.executeCommand(sender, Collections.singletonList(name)); verify(bukkitService).getPlayerExact(name); verify(dataSource).getAuth(name); verify(sender, only()).sendMessage(argThat(containsString("not registered"))); }
@Test public void shouldReturnIpAddressOfPlayer() { String playerName = "charlie"; String ip = "123.34.56.88"; Player player = mockPlayer(playerName, ip); given(bukkitService.getPlayerExact(playerName)).willReturn(player); PlayerAuth auth = PlayerAuth.builder().name("t").lastIp("44.33.22.11").registrationIp("77.11.44.88").build(); given(dataSource.getAuth(playerName)).willReturn(auth); CommandSender sender = mock(CommandSender.class); command.executeCommand(sender, Collections.singletonList(playerName)); verify(bukkitService).getPlayerExact(playerName); verify(dataSource).getAuth(playerName); verify(sender).sendMessage(argThat(both(containsString(playerName)).and(containsString(ip)))); verify(sender).sendMessage(argThat(both(containsString("44.33.22.11")).and(containsString("77.11.44.88")))); }
@Test public void shouldHandleUnregisteredOnlinePlayer() { String playerName = "Test"; String ip = "44.111.22.33"; Player player = mockPlayer(playerName, ip); given(bukkitService.getPlayerExact(playerName)).willReturn(player); given(dataSource.getAuth(anyString())).willReturn(null); CommandSender sender = mock(CommandSender.class); command.executeCommand(sender, Collections.singletonList(playerName)); verify(bukkitService).getPlayerExact(playerName); verify(dataSource).getAuth(playerName); verify(sender).sendMessage(argThat(both(containsString(playerName)).and(containsString(ip)))); verify(sender).sendMessage(argThat(containsString("not registered"))); }