2 * SonarQube, open source software quality management tool.
3 * Copyright (C) 2008-2013 SonarSource
4 * mailto:contact AT sonarsource DOT com
6 * SonarQube is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * SonarQube is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.plugins.core.issue.notification;
22 import org.junit.Test;
23 import org.junit.runner.RunWith;
24 import org.mockito.Mock;
25 import org.mockito.runners.MockitoJUnitRunner;
26 import org.sonar.api.batch.SensorContext;
27 import org.sonar.api.resources.Project;
28 import org.sonar.api.rules.RuleFinder;
29 import org.sonar.api.utils.DateUtils;
30 import org.sonar.batch.issue.IssueCache;
31 import org.sonar.core.issue.DefaultIssue;
32 import org.sonar.core.issue.IssueNotifications;
34 import java.util.Arrays;
36 import static org.mockito.Mockito.*;
38 @RunWith(MockitoJUnitRunner.class)
39 public class SendIssueNotificationsPostJobTest {
44 IssueCache issueCache;
47 IssueNotifications notifications;
50 RuleFinder ruleFinder;
53 SensorContext sensorContext;
56 public void should_send_notif_if_new_issues() throws Exception {
57 when(project.getAnalysisDate()).thenReturn(DateUtils.parseDate("2013-05-18"));
58 when(issueCache.all()).thenReturn(Arrays.asList(
59 new DefaultIssue().setNew(true),
60 new DefaultIssue().setNew(false)
63 SendIssueNotificationsPostJob job = new SendIssueNotificationsPostJob(issueCache, notifications, ruleFinder);
64 job.executeOn(project, sensorContext);
66 verify(notifications).sendNewIssues(project, 1);
70 public void should_not_send_notif_if_no_new_issues() throws Exception {
71 when(project.getAnalysisDate()).thenReturn(DateUtils.parseDate("2013-05-18"));
72 when(issueCache.all()).thenReturn(Arrays.asList(
73 new DefaultIssue().setNew(false)
76 SendIssueNotificationsPostJob job = new SendIssueNotificationsPostJob(issueCache, notifications, ruleFinder);
77 job.executeOn(project, sensorContext);
79 verifyZeroInteractions(notifications);