aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src/test
diff options
context:
space:
mode:
authorFabrice Bellingard <bellingard@gmail.com>2012-02-03 17:09:26 +0100
committerFabrice Bellingard <bellingard@gmail.com>2012-02-03 17:19:07 +0100
commit01906e4e61dcde195d2368c092f8471c0894079f (patch)
tree2bb68d32a6fd7586c2120dd3eec4492b67b8bc29 /sonar-batch/src/test
parent12552a94eebf5bf80fb6fb3952a9b363d568397e (diff)
downloadsonarqube-01906e4e61dcde195d2368c092f8471c0894079f.tar.gz
sonarqube-01906e4e61dcde195d2368c092f8471c0894079f.zip
SONAR-2747 Send email when new violations appear on favourite project
The email is sent only if: * the user has set the project as a favourite * this is a "last analysis" (= no 'sonar.projectDate' specified) * 'since last analysis' period was not removed in the admin page * there are new violations (obviously...)
Diffstat (limited to 'sonar-batch/src/test')
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/components/TimeMachineConfigurationTest.java45
1 files changed, 35 insertions, 10 deletions
diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/TimeMachineConfigurationTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/TimeMachineConfigurationTest.java
index ab1c621cdde..7d4be9f7802 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/components/TimeMachineConfigurationTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/components/TimeMachineConfigurationTest.java
@@ -19,6 +19,15 @@
*/
package org.sonar.batch.components;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.nullValue;
+import static org.mockito.Matchers.argThat;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
+
import org.apache.commons.configuration.PropertiesConfiguration;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
@@ -26,29 +35,25 @@ import org.junit.Test;
import org.sonar.api.CoreProperties;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.resources.Project;
-import org.sonar.batch.components.PastSnapshotFinder;
-import org.sonar.batch.components.TimeMachineConfiguration;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Matchers.argThat;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.*;
-
public class TimeMachineConfigurationTest extends AbstractDbUnitTestCase {
@Test
public void shouldSkipTendencies() {
PropertiesConfiguration conf = new PropertiesConfiguration();
conf.setProperty(CoreProperties.SKIP_TENDENCIES_PROPERTY, true);
- assertThat(new TimeMachineConfiguration(getSession(), new Project("my:project"), conf, mock(PastSnapshotFinder.class)).skipTendencies(), is(true));
+ assertThat(
+ new TimeMachineConfiguration(getSession(), new Project("my:project"), conf, mock(PastSnapshotFinder.class)).skipTendencies(),
+ is(true));
}
@Test
public void shouldNotSkipTendenciesByDefault() {
PropertiesConfiguration conf = new PropertiesConfiguration();
- assertThat(new TimeMachineConfiguration(getSession(), new Project("my:project"), conf, mock(PastSnapshotFinder.class)).skipTendencies(), is(false));
+ assertThat(
+ new TimeMachineConfiguration(getSession(), new Project("my:project"), conf, mock(PastSnapshotFinder.class)).skipTendencies(),
+ is(false));
}
@Test
@@ -79,4 +84,24 @@ public class TimeMachineConfigurationTest extends AbstractDbUnitTestCase {
verifyZeroInteractions(pastSnapshotFinder);
}
+
+ @Test
+ public void shouldReturnLastAnalysisIndexIfSet() {
+ PropertiesConfiguration conf = new PropertiesConfiguration();
+ TimeMachineConfiguration timeMachineConfiguration = new TimeMachineConfiguration(getSession(), new Project("my:project"), conf,
+ mock(PastSnapshotFinder.class));
+
+ // Nothing set, so period for 'previous_analysis' is 1 by default
+ assertThat(timeMachineConfiguration.getLastAnalysisPeriodIndex(), is(1));
+
+ // period1 has been replaced and 'previous_analysis' not set elsewhere...
+ conf.setProperty(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + 1, "Version 1");
+ conf.setProperty(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + 2, "Version 2");
+ assertThat(timeMachineConfiguration.getLastAnalysisPeriodIndex(), is(nullValue()));
+
+ // 'previous_analysis' has now been set on period 4
+ conf.setProperty(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + 4, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS);
+ assertThat(timeMachineConfiguration.getLastAnalysisPeriodIndex(), is(4));
+ }
+
}