summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java11
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationTest.java11
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/VariationDecoratorTest.java5
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/components/PastMeasuresLoader.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshot.java41
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDate.java24
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDays.java8
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysis.java3
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByVersion.java4
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/components/TimeMachineConfiguration.java5
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByDaysTest.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java8
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotTest.java8
13 files changed, 74 insertions, 58 deletions
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java
index 90481c78e65..afc51cf8969 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java
@@ -21,12 +21,12 @@ package org.sonar.plugins.core.timemachine;
import org.junit.Test;
import org.sonar.api.database.model.Snapshot;
+import org.sonar.api.utils.DateUtils;
import org.sonar.batch.components.PastSnapshot;
import org.sonar.batch.components.TimeMachineConfiguration;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
import java.text.ParseException;
-import java.text.SimpleDateFormat;
import java.util.Arrays;
import static org.mockito.Mockito.mock;
@@ -37,13 +37,12 @@ public class TimeMachineConfigurationPersisterTest extends AbstractDbUnitTestCas
@Test
public void shouldSaveConfigurationInSnapshotsTable() throws ParseException {
setupData("shared");
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
TimeMachineConfiguration conf = mock(TimeMachineConfiguration.class);
- PastSnapshot vs1 = new PastSnapshot("days", getSession().getSingleResult(Snapshot.class, "id", 100))
- .setModeParameter("30").setIndex(1).setTargetDate(format.parse("2009-01-25"));
- PastSnapshot vs3 = new PastSnapshot("version", getSession().getSingleResult(Snapshot.class, "id", 300))
- .setModeParameter("1.2.3").setIndex(3).setTargetDate(format.parse("2008-12-13"));
+ PastSnapshot vs1 = new PastSnapshot("days", DateUtils.parseDate("2009-01-25"), getSession().getSingleResult(Snapshot.class, "id", 100))
+ .setModeParameter("30").setIndex(1);
+ PastSnapshot vs3 = new PastSnapshot("version", DateUtils.parseDate("2008-12-13"), getSession().getSingleResult(Snapshot.class, "id", 300))
+ .setModeParameter("1.2.3").setIndex(3);
when(conf.getProjectPastSnapshots()).thenReturn(Arrays.asList(vs1, vs3));
Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1000);
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationTest.java
index 5af00f44226..f1444bd6acc 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationTest.java
@@ -23,13 +23,13 @@ import org.apache.commons.configuration.PropertiesConfiguration;
import org.junit.Test;
import org.sonar.api.CoreProperties;
import org.sonar.api.database.model.Snapshot;
+import org.sonar.api.utils.DateUtils;
import org.sonar.batch.components.PastSnapshot;
import org.sonar.batch.components.PastSnapshotFinder;
import org.sonar.batch.components.TimeMachineConfiguration;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
import java.text.ParseException;
-import java.text.SimpleDateFormat;
import java.util.Date;
import static org.hamcrest.CoreMatchers.is;
@@ -55,8 +55,8 @@ public class TimeMachineConfigurationTest extends AbstractDbUnitTestCase {
public void shouldInitPastSnapshots() throws ParseException {
PropertiesConfiguration conf = new PropertiesConfiguration();
PastSnapshotFinder pastSnapshotFinder = mock(PastSnapshotFinder.class);
- when(pastSnapshotFinder.find(null, conf, 1)).thenReturn(new PastSnapshot("days", null, newSnapshot("2010-10-15")));
- when(pastSnapshotFinder.find(null, conf, 3)).thenReturn(new PastSnapshot("days", null, newSnapshot("2010-10-13")));
+ when(pastSnapshotFinder.find(null, conf, 1)).thenReturn(new PastSnapshot("days", new Date(), newSnapshot("2010-10-15")));
+ when(pastSnapshotFinder.find(null, conf, 3)).thenReturn(new PastSnapshot("days", new Date(), newSnapshot("2010-10-13")));
TimeMachineConfiguration timeMachineConfiguration = new TimeMachineConfiguration(conf, pastSnapshotFinder, null);
@@ -68,9 +68,6 @@ public class TimeMachineConfigurationTest extends AbstractDbUnitTestCase {
}
private Snapshot newSnapshot(String date) throws ParseException {
- Date createdAt = new SimpleDateFormat("yyyy-MM-dd").parse(date);
- return new Snapshot().setCreatedAt(createdAt);
+ return new Snapshot().setCreatedAt(DateUtils.parseDate(date));
}
-
-
}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/VariationDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/VariationDecoratorTest.java
index 12d95464637..242f6f94393 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/VariationDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/VariationDecoratorTest.java
@@ -34,6 +34,7 @@ import org.sonar.batch.components.PastSnapshot;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
import java.util.Arrays;
+import java.util.Date;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -61,8 +62,8 @@ public class VariationDecoratorTest extends AbstractDbUnitTestCase {
Resource javaPackage = new JavaPackage("org.foo");
PastMeasuresLoader pastMeasuresLoader = mock(PastMeasuresLoader.class);
- PastSnapshot pastSnapshot1 = new PastSnapshot("days", new Snapshot()).setIndex(1);
- PastSnapshot pastSnapshot3 = new PastSnapshot("days", new Snapshot()).setIndex(3);
+ PastSnapshot pastSnapshot1 = new PastSnapshot("days", new Date()).setIndex(1);
+ PastSnapshot pastSnapshot3 = new PastSnapshot("days", new Date()).setIndex(3);
// first past analysis
when(pastMeasuresLoader.getPastMeasures(javaPackage, pastSnapshot1)).thenReturn(Arrays.asList(
diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastMeasuresLoader.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastMeasuresLoader.java
index 8c9ab0e9fde..19efcadd46d 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/components/PastMeasuresLoader.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastMeasuresLoader.java
@@ -62,7 +62,7 @@ public class PastMeasuresLoader implements BatchExtension {
}
public List<MeasureModel> getPastMeasures(Resource resource, Snapshot projectSnapshot) {
- if (isPersisted(resource)) {
+ if (isPersisted(resource) && projectSnapshot!=null) {
return getPastMeasures(resource.getId(), projectSnapshot);
}
return Collections.emptyList();
diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshot.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshot.java
index 00f05439bd7..152dacce0f1 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshot.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshot.java
@@ -23,6 +23,7 @@ import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.sonar.api.CoreProperties;
import org.sonar.api.database.model.Snapshot;
+import org.sonar.api.utils.DateUtils;
import java.util.Date;
@@ -39,9 +40,8 @@ public class PastSnapshot {
this.projectSnapshot = projectSnapshot;
}
- public PastSnapshot(String mode, Snapshot projectSnapshot) {
- this.mode = mode;
- this.projectSnapshot = projectSnapshot;
+ public PastSnapshot(String mode, Date targetDate) {
+ this(mode, targetDate, null);
}
public PastSnapshot setIndex(int index) {
@@ -53,12 +53,16 @@ public class PastSnapshot {
return index;
}
+ public boolean isRelatedToSnapshot() {
+ return projectSnapshot!=null;
+ }
+
public Snapshot getProjectSnapshot() {
return projectSnapshot;
}
public Date getDate() {
- return projectSnapshot.getCreatedAt();
+ return (projectSnapshot!=null ? projectSnapshot.getCreatedAt() : null);
}
public String getMode() {
@@ -74,33 +78,44 @@ public class PastSnapshot {
return this;
}
- public Integer getProjectSnapshotId() {
+ Integer getProjectSnapshotId() {
return (projectSnapshot != null ? projectSnapshot.getId() : null);
}
+ public String getQualifier() {
+ return (projectSnapshot != null ? projectSnapshot.getQualifier() : null);
+ }
+
+
public Date getTargetDate() {
return targetDate;
}
- public PastSnapshot setTargetDate(Date d) {
- this.targetDate = d;
- return this;
- }
@Override
public String toString() {
if (StringUtils.equals(mode, PastSnapshotFinderByVersion.MODE)) {
- return String.format("Compare to version " + modeParameter + "(" + getDate() + ")");
+ return String.format("Compare to version %s (%s)", modeParameter, DateUtils.formatDate(getTargetDate()));
}
if (StringUtils.equals(mode, PastSnapshotFinderByDays.MODE)) {
- return String.format("Compare over " + modeParameter + " days (" + getDate() + ")");
+ String label = String.format("Compare over %s days (%s", modeParameter, DateUtils.formatDate(getTargetDate()));
+ if (isRelatedToSnapshot()) {
+ label += ", analysis of " + getDate();
+ }
+ label+=")";
+ return label;
}
if (StringUtils.equals(mode, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS)) {
- return String.format("Compare to previous analysis " + " (" + getDate() + ")");
+ return String.format("Compare to previous analysis (%s)", DateUtils.formatDate(getDate()));
}
if (StringUtils.equals(mode, PastSnapshotFinderByDate.MODE)) {
- return String.format("Compare to date " + getDate());
+ String label = "Compare to date " + DateUtils.formatDate(getTargetDate());
+ if (isRelatedToSnapshot()) {
+ label += String.format("(analysis of %s)", DateUtils.formatDate(getDate()));
+ }
+ return label;
}
return ReflectionToStringBuilder.toString(this);
}
+
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDate.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDate.java
index 71c95af82b8..4340ac6c4b3 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDate.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDate.java
@@ -22,7 +22,8 @@ package org.sonar.batch.components;
import org.sonar.api.BatchExtension;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.resources.Project;
+import org.sonar.api.resources.Qualifiers;
+import org.sonar.api.utils.DateUtils;
import java.text.SimpleDateFormat;
import java.util.Date;
@@ -39,20 +40,25 @@ public class PastSnapshotFinderByDate implements BatchExtension {
}
PastSnapshot findByDate(Snapshot projectSnapshot, Date date) {
+ Snapshot snapshot = null;
+ if (projectSnapshot != null) {
+ snapshot = findSnapshot(projectSnapshot, date);
+ }
+ SimpleDateFormat format = new SimpleDateFormat(DateUtils.DATE_FORMAT);
+ return new PastSnapshot(MODE, date, snapshot).setModeParameter(format.format(date));
+ }
+
+
+ private Snapshot findSnapshot(Snapshot projectSnapshot, Date date) {
String hql = "from " + Snapshot.class.getSimpleName() + " where createdAt>=:date AND resourceId=:resourceId AND status=:status AND qualifier<>:lib order by createdAt asc";
List<Snapshot> snapshots = session.createQuery(hql)
.setParameter("date", date)
.setParameter("resourceId", projectSnapshot.getResourceId())
.setParameter("status", Snapshot.STATUS_PROCESSED)
- .setParameter("lib", Project.QUALIFIER_LIB)
+ .setParameter("lib", Qualifiers.LIBRARY)
.setMaxResults(1)
.getResultList();
- if (snapshots.isEmpty()) {
- return null;
- }
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
- return new PastSnapshot(MODE, date, snapshots.get(0)).setModeParameter(format.format(date));
+ return (snapshots.isEmpty() ? null : snapshots.get(0));
}
-
-}
+} \ No newline at end of file
diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDays.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDays.java
index ddb0d59c970..b3763107e9c 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDays.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDays.java
@@ -23,7 +23,7 @@ import org.apache.commons.lang.time.DateUtils;
import org.sonar.api.BatchExtension;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.resources.Project;
+import org.sonar.api.resources.Qualifiers;
import java.util.Date;
import java.util.List;
@@ -45,13 +45,9 @@ public class PastSnapshotFinderByDays implements BatchExtension {
.setParameter("date", projectSnapshot.getCreatedAt())
.setParameter("resourceId", projectSnapshot.getResourceId())
.setParameter("status", Snapshot.STATUS_PROCESSED)
- .setParameter("lib", Project.QUALIFIER_LIB)
+ .setParameter("lib", Qualifiers.LIBRARY)
.getResultList();
- if (snapshots.isEmpty()) {
- return null;
- }
-
Snapshot snapshot = getNearestToTarget(snapshots, targetDate);
return new PastSnapshot(MODE, targetDate, snapshot).setModeParameter(String.valueOf(days));
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysis.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysis.java
index 6993ca0b78d..c036530682c 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysis.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysis.java
@@ -24,6 +24,7 @@ import org.sonar.api.CoreProperties;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.resources.Project;
+import org.sonar.api.utils.DateUtils;
import java.text.SimpleDateFormat;
import java.util.List;
@@ -51,7 +52,7 @@ public class PastSnapshotFinderByPreviousAnalysis implements BatchExtension {
return null;
}
Snapshot snapshot = snapshots.get(0);
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+ SimpleDateFormat format = new SimpleDateFormat(DateUtils.DATE_FORMAT);
return new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, snapshot.getCreatedAt(), snapshot).setModeParameter(format.format(snapshot.getCreatedAt()));
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByVersion.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByVersion.java
index e81019f9021..9bf15e1414c 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByVersion.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByVersion.java
@@ -22,7 +22,7 @@ package org.sonar.batch.components;
import org.sonar.api.BatchExtension;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.resources.Project;
+import org.sonar.api.resources.Qualifiers;
import java.util.List;
@@ -42,7 +42,7 @@ public class PastSnapshotFinderByVersion implements BatchExtension {
.setParameter("version", version)
.setParameter("resourceId", projectSnapshot.getResourceId())
.setParameter("status", Snapshot.STATUS_PROCESSED)
- .setParameter("lib", Project.QUALIFIER_LIB)
+ .setParameter("lib", Qualifiers.LIBRARY)
.setMaxResults(1)
.getResultList();
diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/TimeMachineConfiguration.java b/sonar-batch/src/main/java/org/sonar/batch/components/TimeMachineConfiguration.java
index 5a1dfbda48f..fb8d071f5d2 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/components/TimeMachineConfiguration.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/components/TimeMachineConfiguration.java
@@ -26,6 +26,7 @@ import org.slf4j.LoggerFactory;
import org.sonar.api.BatchExtension;
import org.sonar.api.CoreProperties;
import org.sonar.api.database.model.Snapshot;
+import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.Resource;
import org.sonar.api.utils.Logs;
@@ -56,9 +57,9 @@ public class TimeMachineConfiguration implements BatchExtension {
}
private void log(PastSnapshot pastSnapshot) {
- String qualifier = pastSnapshot.getProjectSnapshot().getQualifier();
+ String qualifier = pastSnapshot.getQualifier();
// hack to avoid too many logs when the views plugin is installed
- if (StringUtils.equals(Resource.QUALIFIER_VIEW, qualifier) || StringUtils.equals(Resource.QUALIFIER_SUBVIEW, qualifier)) {
+ if (StringUtils.equals(Qualifiers.VIEW, qualifier) || StringUtils.equals(Qualifiers.SUBVIEW, qualifier)) {
LoggerFactory.getLogger(getClass()).debug(pastSnapshot.toString());
} else {
Logs.INFO.info(pastSnapshot.toString());
diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByDaysTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByDaysTest.java
index c4fc0d34063..ff293fdda77 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByDaysTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByDaysTest.java
@@ -66,7 +66,7 @@ public class PastSnapshotFinderByDaysTest extends AbstractDbUnitTestCase {
Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1009); // 2008-11-16
PastSnapshotFinderByDays finder = new PastSnapshotFinderByDays(getSession());
- assertThat(finder.findFromDays(projectSnapshot, 1), nullValue());
+ assertThat(finder.findFromDays(projectSnapshot, 1).getProjectSnapshot(), nullValue());
}
@Test
diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java
index d524ce8f232..7f24bf1fe5e 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java
@@ -81,7 +81,7 @@ public class PastSnapshotFinderTest {
public void shouldFindByDate() throws ParseException {
final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
final Date date = format.parse("2010-05-18");
- when(finderByDate.findByDate(null, date)).thenReturn(new PastSnapshot("date", new Snapshot()));
+ when(finderByDate.findByDate(null, date)).thenReturn(new PastSnapshot("date", date, new Snapshot()));
PastSnapshot variationSnapshot = finder.find(null, 2, "2010-05-18");
@@ -115,7 +115,7 @@ public class PastSnapshotFinderTest {
final Date date = format.parse("2010-05-18");
Snapshot snapshot = new Snapshot();
snapshot.setCreatedAt(date);
- when(finderByPreviousAnalysis.findByPreviousAnalysis(null)).thenReturn(new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, snapshot));
+ when(finderByPreviousAnalysis.findByPreviousAnalysis(null)).thenReturn(new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, date, snapshot));
PastSnapshot variationSnapshot = finder.find(null, 2, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS);
@@ -138,7 +138,7 @@ public class PastSnapshotFinderTest {
@Test
public void shouldFindByVersion() {
- when(finderByVersion.findByVersion(null, "1.2")).thenReturn(new PastSnapshot("version", new Snapshot()));
+ when(finderByVersion.findByVersion(null, "1.2")).thenReturn(new PastSnapshot("version", new Date(), new Snapshot()));
PastSnapshot variationSnapshot = finder.find(null, 2, "1.2");
@@ -160,7 +160,7 @@ public class PastSnapshotFinderTest {
@Test
public void shouldNotFailIfUnknownFormat() {
- when(finderByPreviousAnalysis.findByPreviousAnalysis(null)).thenReturn(new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, new Snapshot())); // should not be called
+ when(finderByPreviousAnalysis.findByPreviousAnalysis(null)).thenReturn(new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, new Date(), new Snapshot())); // should not be called
assertNull(finder.find(null, 2, "foooo"));
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotTest.java
index b504b0a44b7..48fd131f125 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotTest.java
@@ -32,25 +32,25 @@ public class PastSnapshotTest {
@Test
public void testToStringForVersion() {
- PastSnapshot pastSnapshot = new PastSnapshot(PastSnapshotFinderByVersion.MODE, new Snapshot()).setModeParameter("2.3");
+ PastSnapshot pastSnapshot = new PastSnapshot(PastSnapshotFinderByVersion.MODE, new Date()).setModeParameter("2.3");
assertThat(pastSnapshot.toString(), startsWith("Compare to version 2.3"));
}
@Test
public void testToStringForNumberOfDays() {
- PastSnapshot pastSnapshot = new PastSnapshot(PastSnapshotFinderByDays.MODE, new Snapshot()).setModeParameter("30");
+ PastSnapshot pastSnapshot = new PastSnapshot(PastSnapshotFinderByDays.MODE, new Date()).setModeParameter("30");
assertThat(pastSnapshot.toString(), startsWith("Compare over 30 days"));
}
@Test
public void testToStringForDate() {
- PastSnapshot pastSnapshot = new PastSnapshot(PastSnapshotFinderByDate.MODE, new Snapshot()).setTargetDate(new Date());
+ PastSnapshot pastSnapshot = new PastSnapshot(PastSnapshotFinderByDate.MODE, new Date());
assertThat(pastSnapshot.toString(), startsWith("Compare to date "));
}
@Test
public void testToStringForPreviousAnalysis() {
- PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, new Snapshot()).setTargetDate(new Date());
+ PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, new Date(), new Snapshot().setCreatedAt(new Date()));
assertThat(pastSnapshot.toString(), startsWith("Compare to previous analysis"));
}
}