From: Fabrice Bellingard Date: Fri, 13 Jul 2012 13:06:43 +0000 (+0200) Subject: Improve test coverage X-Git-Tag: 3.2~90 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8a2b810abcc15ec1766cbfbd2e2907a9c12fe702;p=sonarqube.git Improve test coverage --- 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 @@ + + + + + + + + + + + + + \ 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/shared.xml deleted file mode 100644 index 98c40a5fc53..00000000000 --- a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest/shared.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest/with-previous-version.xml b/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest/with-previous-version.xml new file mode 100644 index 00000000000..98c40a5fc53 --- /dev/null +++ b/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest/with-previous-version.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file