Search in sources :

Example 1 with LastNotificationTime

use of org.sonarsource.sonarlint.core.client.api.notifications.LastNotificationTime in project sonarlint-core by SonarSource.

the class NotificationTimerTaskTest method testRepeatedProject.

@Test
public void testRepeatedProject() {
    // return one notification for our project
    SonarQubeNotification notif = mock(SonarQubeNotification.class);
    when(notif.projectKey()).thenReturn("myproject");
    when(notificationChecker.request(Collections.singletonMap("myproject", time))).thenReturn(Collections.singletonList(notif));
    // execute with one project
    NotificationConfiguration project = createProject("myproject");
    NotificationConfiguration project2 = createProject("myproject");
    LastNotificationTime notificationTime = mock(LastNotificationTime.class);
    when(notificationTime.get()).thenReturn(ZonedDateTime.now().minusHours(2));
    when(project2.lastNotificationTime()).thenReturn(notificationTime);
    timerTask.setProjects(Collections.singleton(project));
    timerTask.run();
    // verify checker used once and notification was returned through the listener
    verify(notificationCheckerFactory, times(1)).create(any(ServerConfiguration.class));
    // should use the most recent time
    verify(notificationChecker).request(Collections.singletonMap("myproject", time));
    verify(listener).handle(notif);
}
Also used : LastNotificationTime(org.sonarsource.sonarlint.core.client.api.notifications.LastNotificationTime) SonarQubeNotification(org.sonarsource.sonarlint.core.client.api.notifications.SonarQubeNotification) ServerConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration) NotificationConfiguration(org.sonarsource.sonarlint.core.client.api.common.NotificationConfiguration) Test(org.junit.Test)

Example 2 with LastNotificationTime

use of org.sonarsource.sonarlint.core.client.api.notifications.LastNotificationTime in project sonarlint-core by SonarSource.

the class NotificationConfigurationTest method testGetters.

@Test
public void testGetters() {
    SonarQubeNotificationListener listener = mock(SonarQubeNotificationListener.class);
    LastNotificationTime lastNotificationTime = mock(LastNotificationTime.class);
    String projectKey = "key";
    ServerConfiguration serverConfiguration = mock(ServerConfiguration.class);
    NotificationConfiguration configuration = new NotificationConfiguration(listener, lastNotificationTime, projectKey, serverConfiguration);
    assertThat(configuration.lastNotificationTime()).isEqualTo(lastNotificationTime);
    assertThat(configuration.listener()).isEqualTo(listener);
    assertThat(configuration.projectKey()).isEqualTo(projectKey);
    assertThat(configuration.serverConfiguration()).isEqualTo(serverConfiguration);
}
Also used : LastNotificationTime(org.sonarsource.sonarlint.core.client.api.notifications.LastNotificationTime) SonarQubeNotificationListener(org.sonarsource.sonarlint.core.client.api.notifications.SonarQubeNotificationListener) ServerConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 ServerConfiguration (org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration)2 LastNotificationTime (org.sonarsource.sonarlint.core.client.api.notifications.LastNotificationTime)2 NotificationConfiguration (org.sonarsource.sonarlint.core.client.api.common.NotificationConfiguration)1 SonarQubeNotification (org.sonarsource.sonarlint.core.client.api.notifications.SonarQubeNotification)1 SonarQubeNotificationListener (org.sonarsource.sonarlint.core.client.api.notifications.SonarQubeNotificationListener)1