Search in sources :

Example 1 with LoadLocalReplaysTask

use of com.faforever.client.replay.LoadLocalReplaysTask in project downlords-faf-client by FAForever.

the class ReplayVaultControllerTest method testLoadLocalReplaysInBackground.

@Test
public void testLoadLocalReplaysInBackground() throws Exception {
    LoadLocalReplaysTask task = mock(LoadLocalReplaysTask.class);
    when(task.getFuture()).thenReturn(CompletableFuture.completedFuture(Arrays.asList(ReplayInfoBeanBuilder.create().get(), ReplayInfoBeanBuilder.create().get(), ReplayInfoBeanBuilder.create().get())));
    when(applicationContext.getBean(LoadLocalReplaysTask.class)).thenReturn(task);
    CountDownLatch loadedLatch = new CountDownLatch(1);
    ((TableView) instance.getRoot()).getItems().addListener((InvalidationListener) observable -> loadedLatch.countDown());
    instance.loadLocalReplaysInBackground();
    assertTrue(loadedLatch.await(5000, TimeUnit.MILLISECONDS));
    assertThat(((TableView) instance.getRoot()).getItems().size(), is(3));
    verify(taskService).submitTask(task);
    verifyZeroInteractions(notificationService);
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) Arrays(java.util.Arrays) UiService(com.faforever.client.theme.UiService) Mock(org.mockito.Mock) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) CompletableFuture(java.util.concurrent.CompletableFuture) ReportingService(com.faforever.client.reporting.ReportingService) LoadLocalReplaysTask(com.faforever.client.replay.LoadLocalReplaysTask) InvalidationListener(javafx.beans.InvalidationListener) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) Assert.assertThat(org.junit.Assert.assertThat) NotificationService(com.faforever.client.notification.NotificationService) TimeService(com.faforever.client.util.TimeService) Mockito.doAnswer(org.mockito.Mockito.doAnswer) TableView(javafx.scene.control.TableView) Mockito.doReturn(org.mockito.Mockito.doReturn) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) Before(org.junit.Before) ReplayService(com.faforever.client.replay.ReplayService) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ApplicationContext(org.springframework.context.ApplicationContext) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) Matchers.any(org.mockito.Matchers.any) CountDownLatch(java.util.concurrent.CountDownLatch) ReplayInfoBeanBuilder(com.faforever.client.replay.ReplayInfoBeanBuilder) I18n(com.faforever.client.i18n.I18n) MapService(com.faforever.client.map.MapService) TaskService(com.faforever.client.task.TaskService) AbstractPlainJavaFxTest(com.faforever.client.test.AbstractPlainJavaFxTest) Mockito.mock(org.mockito.Mockito.mock) LoadLocalReplaysTask(com.faforever.client.replay.LoadLocalReplaysTask) CountDownLatch(java.util.concurrent.CountDownLatch) TableView(javafx.scene.control.TableView) Test(org.junit.Test) AbstractPlainJavaFxTest(com.faforever.client.test.AbstractPlainJavaFxTest)

Example 2 with LoadLocalReplaysTask

use of com.faforever.client.replay.LoadLocalReplaysTask in project downlords-faf-client by FAForever.

the class ReplayVaultControllerTest method setUp.

@Before
public void setUp() throws Exception {
    instance = new ReplayVaultController(notificationService, replayService, mapService, taskService, i18n, timeService, reportingService, applicationContext, uiService);
    doReturn(new LoadLocalReplaysTask(replayService, i18n)).when(applicationContext).getBean(eq(LoadLocalReplaysTask.class));
    doAnswer(invocation -> invocation.getArgument(0)).when(taskService).submitTask(any());
    loadFxml("theme/vault/replay/replay_vault.fxml", clazz -> instance);
}
Also used : LoadLocalReplaysTask(com.faforever.client.replay.LoadLocalReplaysTask) Before(org.junit.Before)

Example 3 with LoadLocalReplaysTask

use of com.faforever.client.replay.LoadLocalReplaysTask in project downlords-faf-client by FAForever.

the class ReplayVaultController method loadLocalReplaysInBackground.

public CompletableFuture<Void> loadLocalReplaysInBackground() {
    // TODO use replay service
    LoadLocalReplaysTask task = applicationContext.getBean(LoadLocalReplaysTask.class);
    replayVaultRoot.getItems().clear();
    return taskService.submitTask(task).getFuture().thenAccept(this::addLocalReplays).exceptionally(throwable -> {
        logger.warn("Error while loading local replays", throwable);
        notificationService.addNotification(new PersistentNotification(i18n.get("replays.loadingLocalTask.failed"), Severity.ERROR, asList(new ReportAction(i18n, reportingService, throwable), new DismissAction(i18n))));
        return null;
    });
}
Also used : LoadLocalReplaysTask(com.faforever.client.replay.LoadLocalReplaysTask) DismissAction(com.faforever.client.notification.DismissAction) ReportAction(com.faforever.client.notification.ReportAction) PersistentNotification(com.faforever.client.notification.PersistentNotification)

Aggregations

LoadLocalReplaysTask (com.faforever.client.replay.LoadLocalReplaysTask)3 Before (org.junit.Before)2 I18n (com.faforever.client.i18n.I18n)1 MapService (com.faforever.client.map.MapService)1 DismissAction (com.faforever.client.notification.DismissAction)1 NotificationService (com.faforever.client.notification.NotificationService)1 PersistentNotification (com.faforever.client.notification.PersistentNotification)1 ReportAction (com.faforever.client.notification.ReportAction)1 ReplayInfoBeanBuilder (com.faforever.client.replay.ReplayInfoBeanBuilder)1 ReplayService (com.faforever.client.replay.ReplayService)1 ReportingService (com.faforever.client.reporting.ReportingService)1 TaskService (com.faforever.client.task.TaskService)1 AbstractPlainJavaFxTest (com.faforever.client.test.AbstractPlainJavaFxTest)1 UiService (com.faforever.client.theme.UiService)1 TimeService (com.faforever.client.util.TimeService)1 Arrays (java.util.Arrays)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 TimeUnit (java.util.concurrent.TimeUnit)1 InvalidationListener (javafx.beans.InvalidationListener)1