if (lastAnalysisPeriodIndex != null) {
PastSnapshot pastSnapshot = timeMachineConfiguration.getProjectPastSnapshots().get(lastAnalysisPeriodIndex - 1);
Double newViolationsCount = context.getMeasure(CoreMetrics.NEW_VIOLATIONS).getVariation(lastAnalysisPeriodIndex);
- if (newViolationsCount != null && newViolationsCount > 0) {
+ // Do not send notification if this is the first analysis or if there's no violation
+ if (pastSnapshot.getTargetDate() != null && newViolationsCount != null && newViolationsCount > 0) {
// Maybe we should check if this is the first analysis or not?
DateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd");
Notification notification = new Notification("new-violations")
verify(notificationManager, never()).scheduleForSending(any(Notification.class));
}
+ @Test
+ public void shouldNotNotifyUserIfFirstAnalysis() throws Exception {
+ Project project = new Project("key").setName("LongName");
+ project.setId(45);
+ when(timeMachineConfiguration.getLastAnalysisPeriodIndex()).thenReturn(1);
+ // PastSnaptho with targetDate==null means first analysis
+ PastSnapshot pastSnapshot = new PastSnapshot("", null);
+ when(timeMachineConfiguration.getProjectPastSnapshots()).thenReturn(Lists.newArrayList(pastSnapshot));
+ Measure m = new Measure(CoreMetrics.NEW_VIOLATIONS).setVariation1(0.0);
+ when(context.getMeasure(CoreMetrics.NEW_VIOLATIONS)).thenReturn(m);
+
+ decorator.decorate(project, context);
+ verify(notificationManager, never()).scheduleForSending(any(Notification.class));
+ }
+
@Test
public void shouldNotifyUserAboutNewViolations() throws Exception {
Project project = new Project("key").setName("LongName");