Search in sources :

Example 11 with Player

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

the class ChannelTabControllerTest method testOnUserJoinsChannel.

@Test
@SuppressWarnings("unchecked")
public void testOnUserJoinsChannel() throws Exception {
    Channel channel = new Channel(CHANNEL_NAME);
    instance.setChannel(channel);
    ArgumentCaptor<MapChangeListener<String, ChatUser>> captor = ArgumentCaptor.forClass(MapChangeListener.class);
    verify(chatService).addUsersListener(anyString(), captor.capture());
    ChatUser chatUser = new ChatUser("junit", null);
    ObservableMap<String, ChatUser> userMap = FXCollections.observableHashMap();
    userMap.put("junit", chatUser);
    Change<String, ChatUser> change = mock(Change.class);
    when(change.wasAdded()).thenReturn(true);
    when(change.getValueAdded()).thenReturn(chatUser);
    when(change.getMap()).thenReturn(userMap);
    Player player = PlayerBuilder.create("Hans").defaultValues().get();
    when(playerService.createAndGetPlayerForUsername("junit")).thenReturn(player);
    when(i18n.get("chat.userCount", 1)).thenReturn("1 Players");
    when(chatUserItemController.getPlayer()).thenReturn(player);
    // Actual test execution
    captor.getValue().onChanged(change);
    WaitForAsyncUtils.waitForFxEvents();
    assertThat(player.usernameProperty().isBound(), is(true));
    assertThat(player.getUsername(), is("junit"));
    assertThat(instance.userSearchTextField.getPromptText(), is("1 Players"));
}
Also used : Player(com.faforever.client.player.Player) MapChangeListener(javafx.collections.MapChangeListener) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test) AbstractPlainJavaFxTest(com.faforever.client.test.AbstractPlainJavaFxTest)

Example 12 with Player

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

the class ChannelTabControllerTest method testGetMessageCssClassModerator.

@Test
public void testGetMessageCssClassModerator() throws Exception {
    Channel channel = new Channel(CHANNEL_NAME);
    String playerName = "junit";
    Player player = new Player(playerName);
    player.moderatorForChannelsProperty().set(FXCollections.observableSet(CHANNEL_NAME));
    instance.setChannel(channel);
    when(playerService.getPlayerForUsername(playerName)).thenReturn(player);
    assertEquals(instance.getMessageCssClass(playerName), ChannelTabController.CSS_CLASS_MODERATOR);
}
Also used : Player(com.faforever.client.player.Player) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test) AbstractPlainJavaFxTest(com.faforever.client.test.AbstractPlainJavaFxTest)

Example 13 with Player

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

the class ChatUserContextMenuControllerTest method testHideUserInfoOnIdBeingNull.

@Test
public void testHideUserInfoOnIdBeingNull() {
    Player player = PlayerBuilder.create("xyz").get();
    instance.setPlayer(player);
    assertThat(instance.showUserInfo.isVisible(), is(false));
}
Also used : Player(com.faforever.client.player.Player) Test(org.junit.Test) AbstractPlainJavaFxTest(com.faforever.client.test.AbstractPlainJavaFxTest)

Example 14 with Player

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

the class PrivateChatTabControllerTest method setUp.

@Before
public void setUp() throws IOException {
    Vault vault = new Vault();
    vault.setReplayDownloadUrlFormat("test.de");
    when(clientProperties.getVault()).thenReturn(vault);
    PreferencesService preferencesService = new PreferencesService();
    preferencesService.postConstruct();
    preferencesService.getPreferences().getMainWindow().setLastView(NavigationItem.CHAT.name());
    instance = new PrivateChatTabController(clanService, userService, platformService, preferencesService, playerService, timeService, i18n, imageUploadService, urlPreviewResolver, notificationService, reportingService, uiService, autoCompletionHelper, eventBus, audioService, chatService, mapService, webViewConfigurer, countryFlagService, replayService, clientProperties, externalReplayInfoGenerator);
    playerName = "testUser";
    Player player = new Player(playerName);
    when(playerService.getPlayerForUsername(playerName)).thenReturn(player);
    when(userService.getUsername()).thenReturn(playerName);
    when(uiService.getThemeFileUrl(CHAT_CONTAINER)).then(invocation -> getThemeFileUrl(invocation.getArgument(0)));
    TabPane tabPane = new TabPane();
    tabPane.setSkin(new TabPaneSkin(tabPane));
    loadFxml("theme/chat/private_chat_tab.fxml", clazz -> {
        if (clazz == PrivateUserInfoController.class) {
            return privateUserInfoController;
        }
        if (clazz == GameDetailController.class) {
            return gameDetailController;
        }
        if (clazz == WatchButtonController.class) {
            return watchButtonController;
        }
        return instance;
    });
    instance.setReceiver(playerName);
    WaitForAsyncUtils.asyncFx(() -> {
        getRoot().getChildren().setAll(tabPane);
        tabPane.getTabs().add(instance.getRoot());
    });
    WaitForAsyncUtils.waitForFxEvents();
    verify(webViewConfigurer).configureWebView(instance.messagesWebView);
}
Also used : TabPane(javafx.scene.control.TabPane) Player(com.faforever.client.player.Player) Vault(com.faforever.client.config.ClientProperties.Vault) TabPaneSkin(com.sun.javafx.scene.control.skin.TabPaneSkin) PreferencesService(com.faforever.client.preferences.PreferencesService) Before(org.junit.Before)

Example 15 with Player

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

the class PircBotXChatServiceTest method testSuppressFoeMessage.

@Test
public void testSuppressFoeMessage() throws Exception {
    String message = "private message";
    preferences.getChat().setHideFoeMessages(true);
    User user = mock(User.class);
    when(user.getNick()).thenReturn(chatUser1.getUsername());
    Player playerMock = mock(Player.class);
    when(playerService.getPlayerForUsername(chatUser1.getUsername())).thenReturn(playerMock);
    when(playerMock.getSocialStatus()).thenReturn(SocialStatus.FOE);
    connect();
    firePircBotXEvent(createPrivateMessageEvent(user, message));
    verify(eventBus, never()).post(any(Object.class));
}
Also used : Player(com.faforever.client.player.Player) User(org.pircbotx.User) Test(org.junit.Test) AbstractPlainJavaFxTest(com.faforever.client.test.AbstractPlainJavaFxTest)

Aggregations

Player (com.faforever.client.player.Player)51 AbstractPlainJavaFxTest (com.faforever.client.test.AbstractPlainJavaFxTest)17 Test (org.junit.Test)17 Pane (javafx.scene.layout.Pane)8 I18n (com.faforever.client.i18n.I18n)7 PlayerService (com.faforever.client.player.PlayerService)7 UiService (com.faforever.client.theme.UiService)7 ClientProperties (com.faforever.client.config.ClientProperties)6 Controller (com.faforever.client.fx.Controller)6 ArrayList (java.util.ArrayList)6 Platform (javafx.application.Platform)6 Node (javafx.scene.Node)6 Scope (org.springframework.context.annotation.Scope)6 Component (org.springframework.stereotype.Component)6 JavaFxUtil (com.faforever.client.fx.JavaFxUtil)5 NotificationService (com.faforever.client.notification.NotificationService)5 TimeService (com.faforever.client.util.TimeService)5 Collection (java.util.Collection)5 List (java.util.List)5 Map (java.util.Map)5