Search in sources :

Example 1 with FriendJoinedGameEvent

use of com.faforever.client.player.event.FriendJoinedGameEvent in project downlords-faf-client by FAForever.

the class FriendJoinedGameNotifierTest method onFriendJoinedGame.

@Test
public void onFriendJoinedGame() throws Exception {
    Game game = GameBuilder.create().defaultValues().title("My Game").get();
    Player player = PlayerBuilder.create("junit").id(1).game(game).get();
    when(notification.isFriendJoinsGameToastEnabled()).thenReturn(true);
    when(i18n.get("friend.joinedGameNotification.title", "junit", "My Game")).thenReturn("junit joined My Game");
    when(i18n.get("friend.joinedGameNotification.action")).thenReturn("Click to join");
    instance.onFriendJoinedGame(new FriendJoinedGameEvent(player, game));
    ArgumentCaptor<TransientNotification> captor = ArgumentCaptor.forClass(TransientNotification.class);
    verify(notificationService).addNotification(captor.capture());
    TransientNotification notification = captor.getValue();
    assertThat(notification.getTitle(), is("junit joined My Game"));
    assertThat(notification.getText(), is("Click to join"));
    assertThat(notification.getImage(), notNullValue());
}
Also used : TransientNotification(com.faforever.client.notification.TransientNotification) Game(com.faforever.client.game.Game) FriendJoinedGameEvent(com.faforever.client.player.event.FriendJoinedGameEvent) Test(org.junit.Test)

Example 2 with FriendJoinedGameEvent

use of com.faforever.client.player.event.FriendJoinedGameEvent in project downlords-faf-client by FAForever.

the class FriendJoinedGameNotifier method onFriendJoinedGame.

@Subscribe
public void onFriendJoinedGame(FriendJoinedGameEvent event) {
    Player player = event.getPlayer();
    Game game = event.getGame();
    audioService.playFriendJoinsGameSound();
    if (preferencesService.getPreferences().getNotification().isFriendJoinsGameToastEnabled()) {
        notificationService.addNotification(new TransientNotification(i18n.get("friend.joinedGameNotification.title", player.getUsername(), game.getTitle()), i18n.get("friend.joinedGameNotification.action"), IdenticonUtil.createIdenticon(player.getId()), event1 -> joinGameHelper.join(player.getGame())));
    }
}
Also used : TransientNotification(com.faforever.client.notification.TransientNotification) PreferencesService(com.faforever.client.preferences.PreferencesService) IdenticonUtil(com.faforever.client.util.IdenticonUtil) JoinGameHelper(com.faforever.client.game.JoinGameHelper) TransientNotification(com.faforever.client.notification.TransientNotification) EventBus(com.google.common.eventbus.EventBus) Inject(javax.inject.Inject) NotificationService(com.faforever.client.notification.NotificationService) AudioService(com.faforever.client.audio.AudioService) Component(org.springframework.stereotype.Component) PostConstruct(javax.annotation.PostConstruct) FriendJoinedGameEvent(com.faforever.client.player.event.FriendJoinedGameEvent) Subscribe(com.google.common.eventbus.Subscribe) I18n(com.faforever.client.i18n.I18n) Game(com.faforever.client.game.Game) Game(com.faforever.client.game.Game) Subscribe(com.google.common.eventbus.Subscribe)

Example 3 with FriendJoinedGameEvent

use of com.faforever.client.player.event.FriendJoinedGameEvent in project downlords-faf-client by FAForever.

the class FriendJoinedGameNotifierTest method testNoNotificationIfDisabledInPreferences.

@Test
public void testNoNotificationIfDisabledInPreferences() throws Exception {
    when(notification.isFriendJoinsGameToastEnabled()).thenReturn(false);
    instance.onFriendJoinedGame(new FriendJoinedGameEvent(PlayerBuilder.create("junit").get(), GameBuilder.create().get()));
    verify(notificationService, never()).addNotification(any(TransientNotification.class));
}
Also used : TransientNotification(com.faforever.client.notification.TransientNotification) FriendJoinedGameEvent(com.faforever.client.player.event.FriendJoinedGameEvent) Test(org.junit.Test)

Aggregations

TransientNotification (com.faforever.client.notification.TransientNotification)3 FriendJoinedGameEvent (com.faforever.client.player.event.FriendJoinedGameEvent)3 Game (com.faforever.client.game.Game)2 Test (org.junit.Test)2 AudioService (com.faforever.client.audio.AudioService)1 JoinGameHelper (com.faforever.client.game.JoinGameHelper)1 I18n (com.faforever.client.i18n.I18n)1 NotificationService (com.faforever.client.notification.NotificationService)1 PreferencesService (com.faforever.client.preferences.PreferencesService)1 IdenticonUtil (com.faforever.client.util.IdenticonUtil)1 EventBus (com.google.common.eventbus.EventBus)1 Subscribe (com.google.common.eventbus.Subscribe)1 PostConstruct (javax.annotation.PostConstruct)1 Inject (javax.inject.Inject)1 Component (org.springframework.stereotype.Component)1