aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-07-10 17:20:58 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-07-10 17:20:58 +0200
commit239c1c798c2c7685ab71c1b063072dab0be06aae (patch)
tree1226f18b272474a227dd473d9857720aaca18da1 /sonar-batch
parente1f4102e815edcf784fba3387613079cfed76559 (diff)
downloadsonarqube-239c1c798c2c7685ab71c1b063072dab0be06aae.tar.gz
sonarqube-239c1c798c2c7685ab71c1b063072dab0be06aae.zip
SONAR-5445 Introduce new metric "SQALE Debt Ratio"
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/debt/SqaleRatingDecorator.java4
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/debt/SqaleRatingDecoratorTest.java10
2 files changed, 10 insertions, 4 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/debt/SqaleRatingDecorator.java b/sonar-batch/src/main/java/org/sonar/batch/debt/SqaleRatingDecorator.java
index d94fc38f5c5..458b1d27eb0 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/debt/SqaleRatingDecorator.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/debt/SqaleRatingDecorator.java
@@ -76,7 +76,7 @@ public final class SqaleRatingDecorator implements Decorator {
@DependedUpon
public List<Metric> generatesMetrics() {
- return Lists.<Metric>newArrayList(CoreMetrics.RATING, CoreMetrics.DEVELOPMENT_COST);
+ return Lists.<Metric>newArrayList(CoreMetrics.RATING, CoreMetrics.DEVELOPMENT_COST, CoreMetrics.SQALE_DEBT_RATIO);
}
public void decorate(Resource resource, DecoratorContext context) {
@@ -86,6 +86,8 @@ public final class SqaleRatingDecorator implements Decorator {
long debt = getMeasureValue(context, CoreMetrics.TECHNICAL_DEBT);
double density = computeDensity(debt, developmentCost);
+ context.saveMeasure(CoreMetrics.SQALE_DEBT_RATIO, 100.0 * density);
+
SqaleRatingGrid ratingGrid = new SqaleRatingGrid(sqaleRatingSettings.getRatingGrid());
context.saveMeasure(createRatingMeasure(ratingGrid.getRatingForDensity(density)));
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/debt/SqaleRatingDecoratorTest.java b/sonar-batch/src/test/java/org/sonar/batch/debt/SqaleRatingDecoratorTest.java
index cd3029f6e51..48a58f4a050 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/debt/SqaleRatingDecoratorTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/debt/SqaleRatingDecoratorTest.java
@@ -55,7 +55,7 @@ public class SqaleRatingDecoratorTest {
static final Long ONE_DAY_IN_MINUTES = 8L * 60;
Settings settings;
- Metric[] metrics = {CoreMetrics.NCLOC, CoreMetrics.ABSTRACTNESS, CoreMetrics.COMPLEXITY};
+ Metric[] metrics = {CoreMetrics.NCLOC, CoreMetrics.COMPLEXITY};
@Mock
DecoratorContext context;
@@ -81,7 +81,7 @@ public class SqaleRatingDecoratorTest {
@Test
public void generates_metrics() throws Exception {
SqaleRatingDecorator decorator = new SqaleRatingDecorator();
- assertThat(decorator.generatesMetrics()).hasSize(2);
+ assertThat(decorator.generatesMetrics()).hasSize(3);
}
@Test
@@ -121,6 +121,7 @@ public class SqaleRatingDecoratorTest {
decorator.decorate(file, context);
verify(context).saveMeasure(argThat(new IsMeasure(CoreMetrics.RATING, 3.0)));
verify(context).saveMeasure(argThat(new IsMeasure(CoreMetrics.DEVELOPMENT_COST, "9600")));
+ verify(context).saveMeasure(CoreMetrics.SQALE_DEBT_RATIO, 1500d);
verify(context).getMeasure(CoreMetrics.NCLOC);
}
@@ -138,6 +139,7 @@ public class SqaleRatingDecoratorTest {
decorator.decorate(file, context);
verify(context).saveMeasure(argThat(new IsMeasure(CoreMetrics.RATING, 1.0)));
verify(context).saveMeasure(argThat(new IsMeasure(CoreMetrics.DEVELOPMENT_COST, "9600")));
+ verify(context).saveMeasure(CoreMetrics.SQALE_DEBT_RATIO, 0d);
verify(context).getMeasure(CoreMetrics.NCLOC);
}
@@ -150,11 +152,12 @@ public class SqaleRatingDecoratorTest {
when(context.getResource()).thenReturn(file);
when(context.getMeasure(CoreMetrics.NCLOC)).thenReturn(new Measure(CoreMetrics.NCLOC, 10.0));
- when(context.getMeasure(CoreMetrics.TECHNICAL_DEBT)).thenReturn(new Measure(CoreMetrics.TECHNICAL_DEBT, 100000000000.0));
+ when(context.getMeasure(CoreMetrics.TECHNICAL_DEBT)).thenReturn(new Measure(CoreMetrics.TECHNICAL_DEBT, 960000.0));
decorator.decorate(file, context);
verify(context).saveMeasure(argThat(new IsMeasure(CoreMetrics.RATING, 5.0)));
verify(context).saveMeasure(argThat(new IsMeasure(CoreMetrics.DEVELOPMENT_COST, "9600")));
+ verify(context).saveMeasure(CoreMetrics.SQALE_DEBT_RATIO, 10000d);
verify(context).getMeasure(CoreMetrics.NCLOC);
}
@@ -170,6 +173,7 @@ public class SqaleRatingDecoratorTest {
decorator.decorate(mock(File.class), context);
verify(context).saveMeasure(argThat(new IsMeasure(CoreMetrics.RATING, 3.0)));
verify(context).saveMeasure(argThat(new IsMeasure(CoreMetrics.DEVELOPMENT_COST, "9600")));
+ verify(context).saveMeasure(CoreMetrics.SQALE_DEBT_RATIO, 1500d);
verify(context, never()).getMeasure(CoreMetrics.NCLOC);
}