### Question:
SendPrivateMessage { public MessageSendResponse send(PrivateMessage message) { return this.isMuted(message.getFrom()) ? MessageSendResponse.MUTED : findOnlinePlayer.findAndSend(message); }  MessageSendResponse send(PrivateMessage message);  }### Answer:
@Test public void whenMutedThenNotSent() { PunishmentChecker punishmentChecker = mock(PunishmentChecker.class); FindOnlinePlayer findOnlinePlayer = mock(FindOnlinePlayer.class); PrivateMessage privateMessage = new PrivateMessage(UUID.randomUUID(), "to", "text","fromName"); when(punishmentChecker.checkPunishment(eq(privateMessage.getFrom()), eq(ActivePunishmentType.MUTE))) .thenReturn(Optional.of(mock(ActivePunishmentRecord.class))); SendPrivateMessage sendPrivateMessage = new SendPrivateMessage(punishmentChecker, findOnlinePlayer); MessageSendResponse response = sendPrivateMessage.send(privateMessage); assertEquals(MessageSendResponse.MUTED, response); verifyZeroInteractions(findOnlinePlayer); }
@Test public void whenNotMutedThenSent() { PunishmentChecker punishmentChecker = mock(PunishmentChecker.class); FindOnlinePlayer findOnlinePlayer = mock(FindOnlinePlayer.class); PrivateMessage privateMessage = new PrivateMessage(UUID.randomUUID(), "to", "text","fromName"); when(punishmentChecker.checkPunishment(any(), any())).thenReturn(Optional.empty()); SendPrivateMessage sendPrivateMessage = new SendPrivateMessage(punishmentChecker, findOnlinePlayer); when(findOnlinePlayer.findAndSend(eq(privateMessage))).thenReturn(MessageSendResponse.OK); MessageSendResponse response = sendPrivateMessage.send(privateMessage); assertEquals(MessageSendResponse.OK, response); verify(findOnlinePlayer).findAndSend(eq(privateMessage)); }