diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-07-03 08:37:43 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-07-03 11:23:41 +0200 |
commit | 854f1e5cd9acdad37fc041f7966aa85f39c8523f (patch) | |
tree | 36b7f6d145912f98abdbda28b84e5389a2356ebb /sonar-core | |
parent | 7f218017d505877feb4415b0568dde3fb8492172 (diff) | |
download | sonarqube-854f1e5cd9acdad37fc041f7966aa85f39c8523f.tar.gz sonarqube-854f1e5cd9acdad37fc041f7966aa85f39c8523f.zip |
Fix quality flaws
Diffstat (limited to 'sonar-core')
-rw-r--r-- | sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java | 30 | ||||
-rw-r--r-- | sonar-core/src/test/java/org/sonar/core/measure/db/PastMeasureDtoTest.java | 20 |
2 files changed, 36 insertions, 14 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java b/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java index ad12d18d368..49ee6b18d38 100644 --- a/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java +++ b/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java @@ -21,6 +21,12 @@ package org.sonar.core.resource; import com.google.common.base.Function; import com.google.common.collect.Iterables; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.List; +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; import org.apache.ibatis.session.SqlSession; import org.sonar.api.component.Component; import org.sonar.api.resources.Scopes; @@ -32,14 +38,6 @@ import org.sonar.core.persistence.DaoComponent; import org.sonar.core.persistence.DbSession; import org.sonar.core.persistence.MyBatis; -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; - -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.List; - import static com.google.common.collect.Lists.newArrayList; public class ResourceDao implements DaoComponent { @@ -358,16 +356,20 @@ public class ResourceDao implements DaoComponent { } public static List<Component> toComponents(List<ResourceDto> resourceDto) { - return newArrayList(Iterables.transform(resourceDto, new Function<ResourceDto, Component>() { - @Override - public Component apply(@Nullable ResourceDto resourceDto) { - return resourceDto == null ? null : toComponent(resourceDto); - } - })); + return newArrayList(Iterables.transform(resourceDto, ToComponent.INSTANCE)); } public void insertUsingExistingSession(ResourceDto resourceDto, SqlSession session) { ResourceMapper resourceMapper = session.getMapper(ResourceMapper.class); resourceMapper.insert(resourceDto); } + + private enum ToComponent implements Function<ResourceDto, Component> { + INSTANCE; + + @Override + public Component apply(@Nonnull ResourceDto resourceDto) { + return toComponent(resourceDto); + } + } } diff --git a/sonar-core/src/test/java/org/sonar/core/measure/db/PastMeasureDtoTest.java b/sonar-core/src/test/java/org/sonar/core/measure/db/PastMeasureDtoTest.java index 2baf547ff16..9808471c1b0 100644 --- a/sonar-core/src/test/java/org/sonar/core/measure/db/PastMeasureDtoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/measure/db/PastMeasureDtoTest.java @@ -45,6 +45,26 @@ public class PastMeasureDtoTest { assertThat(dto.getPersonId()).isEqualTo(5); } + @Test + public void test_has_value() throws Exception { + PastMeasureDto measureWithValue = new PastMeasureDto() + .setId(10L) + .setValue(1d) + .setMetricId(2) + .setRuleId(3) + .setCharacteristicId(4) + .setPersonId(5); + assertThat(measureWithValue.hasValue()).isTrue(); + + PastMeasureDto measureWithoutValue = new PastMeasureDto() + .setId(10L) + .setMetricId(2) + .setRuleId(3) + .setCharacteristicId(4) + .setPersonId(5); + assertThat(measureWithoutValue.hasValue()).isFalse(); + } + @Test(expected = NullPointerException.class) public void get_value_throw_a_NPE_if_value_is_null() throws Exception { new PastMeasureDto().getValue(); |