aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sonar-core-plugin
diff options
context:
space:
mode:
authorFabrice Bellingard <bellingard@gmail.com>2012-02-08 10:15:56 +0100
committerFabrice Bellingard <bellingard@gmail.com>2012-02-08 10:15:56 +0100
commit85e7e49bcfa5fb64fd499060c279cd679c799e39 (patch)
tree613184fccfd86801471d0907633be90712717145 /plugins/sonar-core-plugin
parent6a86b71f63edfb4b9a07246a40fd5c6dccf098a7 (diff)
downloadsonarqube-85e7e49bcfa5fb64fd499060c279cd679c799e39.tar.gz
sonarqube-85e7e49bcfa5fb64fd499060c279cd679c799e39.zip
SONAR-2747 Verification is now done on period1
And not necessarily 'since last analysis' period.
Diffstat (limited to 'plugins/sonar-core-plugin')
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewViolationsDecorator.java9
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/NewViolationsDecoratorTest.java21
2 files changed, 8 insertions, 22 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewViolationsDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewViolationsDecorator.java
index 06a8bf377df..d714cada4fa 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewViolationsDecorator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewViolationsDecorator.java
@@ -209,11 +209,11 @@ public class NewViolationsDecorator implements Decorator {
}
protected void notifyNewViolations(Project project, DecoratorContext context) {
- Integer lastAnalysisPeriodIndex = timeMachineConfiguration.getLastAnalysisPeriodIndex();
List<PastSnapshot> projectPastSnapshots = timeMachineConfiguration.getProjectPastSnapshots();
- if (lastAnalysisPeriodIndex != null && projectPastSnapshots.size() >= lastAnalysisPeriodIndex) {
- PastSnapshot pastSnapshot = projectPastSnapshots.get(lastAnalysisPeriodIndex - 1);
- Double newViolationsCount = context.getMeasure(CoreMetrics.NEW_VIOLATIONS).getVariation(lastAnalysisPeriodIndex);
+ if (projectPastSnapshots.size() >= 1) {
+ // we always check new violations against period1
+ PastSnapshot pastSnapshot = projectPastSnapshots.get(0);
+ Double newViolationsCount = context.getMeasure(CoreMetrics.NEW_VIOLATIONS).getVariation1();
// 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?
@@ -223,7 +223,6 @@ public class NewViolationsDecorator implements Decorator {
.setFieldValue("projectName", project.getLongName())
.setFieldValue("projectKey", project.getKey())
.setFieldValue("projectId", String.valueOf(project.getId()))
- .setFieldValue("period", lastAnalysisPeriodIndex.toString())
.setFieldValue("fromDate", dateformat.format(pastSnapshot.getTargetDate()))
.setFieldValue("toDate", dateformat.format(new Date()));
notificationManager.scheduleForSending(notification);
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/NewViolationsDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/NewViolationsDecoratorTest.java
index e8695960212..a5ee668fa1c 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/NewViolationsDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/NewViolationsDecoratorTest.java
@@ -32,6 +32,7 @@ import static org.mockito.Mockito.when;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
@@ -70,7 +71,7 @@ public class NewViolationsDecoratorTest {
private NewViolationsDecorator decorator;
private DecoratorContext context;
- private Resource resource;
+ private Resource<?> resource;
private NotificationManager notificationManager;
private Date rightNow;
@@ -189,20 +190,10 @@ public class NewViolationsDecoratorTest {
}
@Test
- public void shouldNotNotifyIfNoPeriodForLastAnalysis() throws Exception {
- Project project = new Project("key");
- when(timeMachineConfiguration.getLastAnalysisPeriodIndex()).thenReturn(null);
-
- decorator.notifyNewViolations(project, context);
-
- verify(notificationManager, never()).scheduleForSending(any(Notification.class));
- }
-
- @Test
public void shouldNotNotifyIfNoNotEnoughPastSnapshots() throws Exception {
Project project = new Project("key");
// the #setUp method adds 2 snapshots: if last period analysis is 3, then it's not enough
- when(timeMachineConfiguration.getLastAnalysisPeriodIndex()).thenReturn(3);
+ when(timeMachineConfiguration.getProjectPastSnapshots()).thenReturn(new ArrayList<PastSnapshot>());
decorator.notifyNewViolations(project, context);
verify(notificationManager, never()).scheduleForSending(any(Notification.class));
@@ -211,7 +202,6 @@ public class NewViolationsDecoratorTest {
@Test
public void shouldNotNotifyIfNoNewViolations() throws Exception {
Project project = new Project("key");
- when(timeMachineConfiguration.getLastAnalysisPeriodIndex()).thenReturn(1);
Measure m = new Measure(CoreMetrics.NEW_VIOLATIONS);
when(context.getMeasure(CoreMetrics.NEW_VIOLATIONS)).thenReturn(m);
@@ -229,7 +219,6 @@ public class NewViolationsDecoratorTest {
public void shouldNotNotifyUserIfFirstAnalysis() throws Exception {
Project project = new Project("key").setName("LongName");
project.setId(45);
- when(timeMachineConfiguration.getLastAnalysisPeriodIndex()).thenReturn(1);
// PastSnapshot with targetDate==null means first analysis
PastSnapshot pastSnapshot = new PastSnapshot("", null);
when(timeMachineConfiguration.getProjectPastSnapshots()).thenReturn(Lists.newArrayList(pastSnapshot));
@@ -244,11 +233,10 @@ public class NewViolationsDecoratorTest {
public void shouldNotifyUserAboutNewViolations() throws Exception {
Project project = new Project("key").setName("LongName");
project.setId(45);
- when(timeMachineConfiguration.getLastAnalysisPeriodIndex()).thenReturn(2);
Calendar pastDate = new GregorianCalendar(2011, 10, 25);
PastSnapshot pastSnapshot = new PastSnapshot("", pastDate.getTime());
when(timeMachineConfiguration.getProjectPastSnapshots()).thenReturn(Lists.newArrayList(pastSnapshot, pastSnapshot));
- Measure m = new Measure(CoreMetrics.NEW_VIOLATIONS).setVariation2(32.0);
+ Measure m = new Measure(CoreMetrics.NEW_VIOLATIONS).setVariation1(32.0);
when(context.getMeasure(CoreMetrics.NEW_VIOLATIONS)).thenReturn(m);
decorator.decorate(project, context);
@@ -259,7 +247,6 @@ public class NewViolationsDecoratorTest {
.setFieldValue("projectName", "LongName")
.setFieldValue("projectKey", "key")
.setFieldValue("projectId", "45")
- .setFieldValue("period", "2")
.setFieldValue("fromDate", dateformat.format(pastDate.getTime()))
.setFieldValue("toDate", dateformat.format(new Date()));
verify(notificationManager, times(1)).scheduleForSending(eq(notification));