aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabrice Bellingard <bellingard@gmail.com>2012-01-16 10:22:16 +0100
committerFabrice Bellingard <bellingard@gmail.com>2012-01-16 10:23:00 +0100
commite5d8abcccd285c3b6798e882c173eafec14d7e31 (patch)
tree8997ccf84ce8433a93af0c84f602d9b382fa1b78
parent5e5c910205bc245e660062a811bb7b862d28c911 (diff)
downloadsonarqube-e5d8abcccd285c3b6798e882c173eafec14d7e31.tar.gz
sonarqube-e5d8abcccd285c3b6798e882c173eafec14d7e31.zip
SONAR-3012 Check that resource is not a unit test for reviews metrics
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ReviewsMeasuresDecorator.java6
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ReviewsMeasuresDecoratorTest.java14
2 files changed, 16 insertions, 4 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ReviewsMeasuresDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ReviewsMeasuresDecorator.java
index 864c44148a0..c581fce39c8 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ReviewsMeasuresDecorator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ReviewsMeasuresDecorator.java
@@ -60,13 +60,13 @@ public class ReviewsMeasuresDecorator implements Decorator {
@SuppressWarnings({"rawtypes"})
public void decorate(Resource resource, DecoratorContext context) {
- if (!ResourceUtils.isPersistable(resource)) {
+ if (!ResourceUtils.isPersistable(resource) || ResourceUtils.isUnitTestClass(resource)) {
return;
}
// Open reviews
ReviewQuery openReviewQuery = ReviewQuery.create().setResourceId(resource.getId()).addStatus(ReviewDto.STATUS_OPEN)
- .addStatus(ReviewDto.STATUS_REOPENED);
+ .addStatus(ReviewDto.STATUS_REOPENED);
Double resourceOpenReviewsCount = reviewDao.countByQuery(openReviewQuery).doubleValue();
Double totalOpenReviewsCount = resourceOpenReviewsCount + getChildrenSum(resource, context, CoreMetrics.ACTIVE_REVIEWS);
context.saveMeasure(CoreMetrics.ACTIVE_REVIEWS, totalOpenReviewsCount);
@@ -87,7 +87,7 @@ public class ReviewsMeasuresDecorator implements Decorator {
// False positive reviews
ReviewQuery falsePositiveReviewQuery = ReviewQuery.create().setResourceId(resource.getId())
- .addResolution(ReviewDto.RESOLUTION_FALSE_POSITIVE);
+ .addResolution(ReviewDto.RESOLUTION_FALSE_POSITIVE);
Double resourceFalsePositiveReviewsCount = reviewDao.countByQuery(falsePositiveReviewQuery).doubleValue();
Double totalFalsePositiveReviewsCount = resourceFalsePositiveReviewsCount
+ getChildrenSum(resource, context, CoreMetrics.FALSE_POSITIVE_REVIEWS);
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ReviewsMeasuresDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ReviewsMeasuresDecoratorTest.java
index 3c0333048ed..21938e80a44 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ReviewsMeasuresDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ReviewsMeasuresDecoratorTest.java
@@ -39,6 +39,7 @@ import org.sonar.api.measures.Measure;
import org.sonar.api.measures.Metric;
import org.sonar.api.resources.File;
import org.sonar.api.resources.Project;
+import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.Resource;
import org.sonar.api.resources.Scopes;
import org.sonar.core.review.ReviewDao;
@@ -65,7 +66,7 @@ public class ReviewsMeasuresDecoratorTest {
}
@Test
- public void shouldDecorateOnlyPersistableResource() throws Exception {
+ public void shouldDecoratePersistableResource() throws Exception {
ReviewsMeasuresDecorator decorator = new ReviewsMeasuresDecorator(null);
DecoratorContext context = mock(DecoratorContext.class);
Resource<?> resource = mock(Resource.class);
@@ -75,6 +76,17 @@ public class ReviewsMeasuresDecoratorTest {
}
@Test
+ public void shouldNotDecorateUnitTest() throws Exception {
+ ReviewsMeasuresDecorator decorator = new ReviewsMeasuresDecorator(null);
+ DecoratorContext context = mock(DecoratorContext.class);
+ Resource<?> resource = mock(Resource.class);
+ when(resource.getScope()).thenReturn(Scopes.FILE);
+ when(resource.getQualifier()).thenReturn(Qualifiers.UNIT_TEST_FILE);
+ decorator.decorate(resource, context);
+ verify(context, never()).saveMeasure(any(Metric.class), anyDouble());
+ }
+
+ @Test
public void shouldComputeReviewMetricsOnFile() throws Exception {
ReviewDao reviewDao = mock(ReviewDao.class);
when(reviewDao.countByQuery(argThat(openReviewQueryMatcher()))).thenReturn(10);