diff options
author | Fabrice Bellingard <bellingard@gmail.com> | 2012-07-13 15:06:43 +0200 |
---|---|---|
committer | Fabrice Bellingard <bellingard@gmail.com> | 2012-07-13 15:06:43 +0200 |
commit | 8a2b810abcc15ec1766cbfbd2e2907a9c12fe702 (patch) | |
tree | 7c4e1e2603c34ec9e663d54f6081a80d16a64511 | |
parent | 7f54582bcc24905c708f0d9f71378c3c71bfb7ab (diff) | |
download | sonarqube-8a2b810abcc15ec1766cbfbd2e2907a9c12fe702.tar.gz sonarqube-8a2b810abcc15ec1766cbfbd2e2907a9c12fe702.zip |
Improve test coverage
-rw-r--r-- | sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest.java | 14 | ||||
-rw-r--r-- | sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByVersionTest.java | 18 | ||||
-rw-r--r-- | sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest/no-previous-version.xml | 22 | ||||
-rw-r--r-- | sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest/with-previous-version.xml (renamed from sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest/shared.xml) | 0 |
4 files changed, 52 insertions, 2 deletions
diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest.java index 793c800758d..9e5fc6f7608 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest.java @@ -30,7 +30,7 @@ public class PastSnapshotFinderByPreviousVersionTest extends AbstractDbUnitTestC @Test public void shouldFindByPreviousVersion() { - setupData("shared"); + setupData("with-previous-version"); PastSnapshotFinderByPreviousVersion finder = new PastSnapshotFinderByPreviousVersion(getSession()); Snapshot currentProjectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1010); @@ -44,4 +44,16 @@ public class PastSnapshotFinderByPreviousVersionTest extends AbstractDbUnitTestC assertThat(finder.findByPreviousVersion(currentProjectSnapshot).getProjectSnapshotId()).isEqualTo(1003); } + @Test + public void testWithNoPreviousVersion() { + setupData("no-previous-version"); + PastSnapshotFinderByPreviousVersion finder = new PastSnapshotFinderByPreviousVersion(getSession()); + + Snapshot currentProjectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1003); + PastSnapshot foundSnapshot = finder.findByPreviousVersion(currentProjectSnapshot); + assertThat(foundSnapshot.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION); + assertThat(foundSnapshot.getProjectSnapshot()).isNull(); + assertThat(foundSnapshot.getModeParameter()).isNull(); + } + } diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByVersionTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByVersionTest.java index 2c952a4cf9a..597a79a3bee 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByVersionTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByVersionTest.java @@ -20,6 +20,7 @@ package org.sonar.batch.components; import org.junit.Test; +import org.sonar.api.CoreProperties; import org.sonar.api.database.model.Snapshot; import org.sonar.jpa.test.AbstractDbUnitTestCase; @@ -34,7 +35,22 @@ public class PastSnapshotFinderByVersionTest extends AbstractDbUnitTestCase { Snapshot currentProjectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1010); PastSnapshotFinderByVersion finder = new PastSnapshotFinderByVersion(getSession()); - assertThat(finder.findByVersion(currentProjectSnapshot, "1.1").getProjectSnapshotId()).isEqualTo(1009); + PastSnapshot foundSnapshot = finder.findByVersion(currentProjectSnapshot, "1.1"); + assertThat(foundSnapshot.getProjectSnapshotId()).isEqualTo(1009); + assertThat(foundSnapshot.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_VERSION); + } + + @Test + public void testIfNoVersionFound() { + setupData("shared"); + + Snapshot currentProjectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1010); + PastSnapshotFinderByVersion finder = new PastSnapshotFinderByVersion(getSession()); + + PastSnapshot foundSnapshot = finder.findByVersion(currentProjectSnapshot, "2.1"); + assertThat(foundSnapshot.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_VERSION); + assertThat(foundSnapshot.getProjectSnapshot()).isNull(); + assertThat(foundSnapshot.getModeParameter()).isNull(); } } diff --git a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest/no-previous-version.xml b/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest/no-previous-version.xml new file mode 100644 index 00000000000..67bbfc454b4 --- /dev/null +++ b/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest/no-previous-version.xml @@ -0,0 +1,22 @@ +<dataset> + + <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="project" name="project" + root_id="[null]" + description="[null]" + enabled="true" language="java" copy_resource_id="[null]" person_id="[null]"/> + + + <!-- version 1.1-SNAPSHOT --> + <snapshots purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="1000" + project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]" + scope="PRJ" qualifier="TRK" created_at="2008-11-01 13:58:00.00" build_date="2008-11-01 13:58:00.00" version="1.1-SNAPSHOT" path="" + status="P" islast="false" depth="0" /> + + + <!-- version 1.1-SNAPSHOT --> + <snapshots purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="1003" + project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]" + scope="PRJ" qualifier="TRK" created_at="2008-11-02 13:58:00.00" build_date="2008-11-02 13:58:00.00" version="1.1-SNAPSHOT" path="" + status="P" islast="true" depth="0" /> + +</dataset>
\ No newline at end of file diff --git a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest/shared.xml b/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest/with-previous-version.xml index 98c40a5fc53..98c40a5fc53 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest/shared.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest/with-previous-version.xml |