@Test public void invite() { PreferencesRepository preferencesRepository = mock(PreferencesRepository.class); when(preferencesRepository.findBy(any())).thenAnswer(invocation -> { PlayerPreferences preferences = mock(PlayerPreferences.class); when(preferences.isPartyRequests()).thenReturn(true); return Optional.of(preferences); }); PlayerMessaging playerMessaging = mock(PlayerMessaging.class); when(playerMessaging.isOnline(eq("target"))).thenReturn(true); PartyRepository partyRepository = mock(PartyRepository.class); when(partyRepository.invite(eq("owner"), eq("target"), anyInt())) .thenReturn(InviteResult.INVITED); PartyService partyService = new PartyService(partyRepository, preferencesRepository, playerMessaging); assertEquals(InviteResult.INVITED, partyService.invite("owner", "target")); verify(playerMessaging).sendTo(any(), eq("target")); }
public InviteResult invite(String owner, String player) { if (playerMessaging.isOnline(player)) { return preferencesRepository.findBy( new PlayerNameSpecification(player)) .filter(PlayerPreferences::isPartyRequests) .map(playerProfile -> { InviteResult result = partyRepository.invite(owner, player, EXPIRATION_TIME); if (result == InviteResult.INVITED) { playerMessaging.sendTo(new PartyInvite(owner, player), player); } return result; }).orElse(InviteResult.DISABLED); } else { return InviteResult.NOT_ONLINE; } }
PartyService { public InviteResult invite(String owner, String player) { if (playerMessaging.isOnline(player)) { return preferencesRepository.findBy( new PlayerNameSpecification(player)) .filter(PlayerPreferences::isPartyRequests) .map(playerProfile -> { InviteResult result = partyRepository.invite(owner, player, EXPIRATION_TIME); if (result == InviteResult.INVITED) { playerMessaging.sendTo(new PartyInvite(owner, player), player); } return result; }).orElse(InviteResult.DISABLED); } else { return InviteResult.NOT_ONLINE; } } }
PartyService { public InviteResult invite(String owner, String player) { if (playerMessaging.isOnline(player)) { return preferencesRepository.findBy( new PlayerNameSpecification(player)) .filter(PlayerPreferences::isPartyRequests) .map(playerProfile -> { InviteResult result = partyRepository.invite(owner, player, EXPIRATION_TIME); if (result == InviteResult.INVITED) { playerMessaging.sendTo(new PartyInvite(owner, player), player); } return result; }).orElse(InviteResult.DISABLED); } else { return InviteResult.NOT_ONLINE; } }  }
PartyService { public InviteResult invite(String owner, String player) { if (playerMessaging.isOnline(player)) { return preferencesRepository.findBy( new PlayerNameSpecification(player)) .filter(PlayerPreferences::isPartyRequests) .map(playerProfile -> { InviteResult result = partyRepository.invite(owner, player, EXPIRATION_TIME); if (result == InviteResult.INVITED) { playerMessaging.sendTo(new PartyInvite(owner, player), player); } return result; }).orElse(InviteResult.DISABLED); } else { return InviteResult.NOT_ONLINE; } }  CreateResult create(String playerName); Set<String> getInvitedMembers(String playerName); RemoveResult remove(String applicant, String playerName); AcceptResult accept(String owner, String player); DisbandResult disband(String playerName); InviteResult invite(String owner, String player); boolean partyChat(String member, String text); }
PartyService { public InviteResult invite(String owner, String player) { if (playerMessaging.isOnline(player)) { return preferencesRepository.findBy( new PlayerNameSpecification(player)) .filter(PlayerPreferences::isPartyRequests) .map(playerProfile -> { InviteResult result = partyRepository.invite(owner, player, EXPIRATION_TIME); if (result == InviteResult.INVITED) { playerMessaging.sendTo(new PartyInvite(owner, player), player); } return result; }).orElse(InviteResult.DISABLED); } else { return InviteResult.NOT_ONLINE; } }  CreateResult create(String playerName); Set<String> getInvitedMembers(String playerName); RemoveResult remove(String applicant, String playerName); AcceptResult accept(String owner, String player); DisbandResult disband(String playerName); InviteResult invite(String owner, String player); boolean partyChat(String member, String text); static final int EXPIRATION_TIME; }