### Question:
FindOnlinePlayer { public MessageSendResponse findAndSend(PrivateMessage message) { return playerRepository .getPlayerProxy(message.getToName()) .map(x -> findPlayerProfile.findProfileAndProceed(message, x)) .orElse(MessageSendResponse.OFFLINE); }  MessageSendResponse findAndSend(PrivateMessage message);  }### Answer:
@Test public void whenPlayerOnlineThenSent() { PlayerRepository playerRepository = mock(PlayerRepository.class); FindPlayerProfile findPlayerProfile = mock(FindPlayerProfile.class); when(playerRepository.getPlayerProxy(eq("player"))).thenReturn( Optional.of("proxy-1") ); FindOnlinePlayer findOnlinePlayer = new FindOnlinePlayer(playerRepository, findPlayerProfile); PrivateMessage privateMessage = new PrivateMessage( UUID.randomUUID(), "player", "text","fromName" ); when(findPlayerProfile.findProfileAndProceed(eq(privateMessage), eq("proxy-1"))).thenReturn( MessageSendResponse.OK ); Assert.assertEquals(MessageSendResponse.OK, findOnlinePlayer.findAndSend(privateMessage)); }
@Test public void whenPlayerNotOnlineThenNotSent() { PlayerRepository playerRepository = mock(PlayerRepository.class); FindPlayerProfile findPlayerProfile = mock(FindPlayerProfile.class); when(playerRepository.getPlayerProxy(any())).thenReturn(Optional.empty()); FindOnlinePlayer findOnlinePlayer = new FindOnlinePlayer(playerRepository, findPlayerProfile); PrivateMessage privateMessage = new PrivateMessage( UUID.randomUUID(), "player", "text","fromName" ); Assert.assertEquals(MessageSendResponse.OFFLINE, findOnlinePlayer.findAndSend(privateMessage)); verifyZeroInteractions(findPlayerProfile); }