summaryrefslogtreecommitdiffstats
path: root/sonar-core/src
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2014-10-31 16:33:15 +0100
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2014-10-31 16:33:30 +0100
commit605455cb03c5cf67a8c2e4a1d8ba1b7b90f4c63b (patch)
tree45e2feb4b95629ca362af1c0e1e988085e07380c /sonar-core/src
parent0ffd9d683485c9a179e83ed4a466370c6036d1fe (diff)
downloadsonarqube-605455cb03c5cf67a8c2e4a1d8ba1b7b90f4c63b.tar.gz
sonarqube-605455cb03c5cf67a8c2e4a1d8ba1b7b90f4c63b.zip
Improve branch code coverage on snapshot related classes
Diffstat (limited to 'sonar-core/src')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/component/SnapshotDto.java16
-rw-r--r--sonar-core/src/test/java/org/sonar/core/component/SnapshotDtoTest.java17
2 files changed, 33 insertions, 0 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/component/SnapshotDto.java b/sonar-core/src/main/java/org/sonar/core/component/SnapshotDto.java
index 3cd77466dd8..a9b5aaa5a56 100644
--- a/sonar-core/src/main/java/org/sonar/core/component/SnapshotDto.java
+++ b/sonar-core/src/main/java/org/sonar/core/component/SnapshotDto.java
@@ -317,4 +317,20 @@ public final class SnapshotDto extends Dto<Long> {
public Long getKey() {
return id;
}
+
+ @Override
+ public SnapshotDto setCreatedAt(Date datetime) {
+ super.setCreatedAt(datetime);
+ return this;
+ }
+
+ @Override
+ public SnapshotDto setUpdatedAt(Date datetime) {
+ super.setUpdatedAt(datetime);
+ return this;
+ }
+
+ public Long getRootIdOrSelf() {
+ return getRootId() == null ? getId() : getRootId();
+ }
}
diff --git a/sonar-core/src/test/java/org/sonar/core/component/SnapshotDtoTest.java b/sonar-core/src/test/java/org/sonar/core/component/SnapshotDtoTest.java
index 4ba5618578f..ac13ac5a2b8 100644
--- a/sonar-core/src/test/java/org/sonar/core/component/SnapshotDtoTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/component/SnapshotDtoTest.java
@@ -88,4 +88,21 @@ public class SnapshotDtoTest {
assertThat(snapshotDto.getPeriodDate(5)).isEqualTo(DateUtils.parseDate("2014-06-05"));
}
+ @Test
+ public void get_root_id_if_when_it_is_not_null() {
+ SnapshotDto snapshot = new SnapshotDto().setRootId(123L).setId(456L);
+
+ Long rootIdOrSelf = snapshot.getRootIdOrSelf();
+
+ assertThat(rootIdOrSelf).isEqualTo(123L);
+ }
+
+ @Test
+ public void getRootIdOrSelf_return_own_id_when_root_id_is_null() {
+ SnapshotDto snapshot = new SnapshotDto().setRootId(null).setId(456L);
+
+ Long rootIdOrSelf = snapshot.getRootIdOrSelf();
+
+ assertThat(rootIdOrSelf).isEqualTo(456L);
+ }
}