aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/bridges/ChidamberKemererBridge.java6
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/ChidamberKemererBridgeTest.java20
2 files changed, 23 insertions, 3 deletions
diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/bridges/ChidamberKemererBridge.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/bridges/ChidamberKemererBridge.java
index e4c99ecd65d..a262b639b5d 100644
--- a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/bridges/ChidamberKemererBridge.java
+++ b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/bridges/ChidamberKemererBridge.java
@@ -35,6 +35,10 @@ public class ChidamberKemererBridge extends Bridge {
context.saveMeasure(sonarFile, CoreMetrics.DEPTH_IN_TREE, squidFile.getDouble(Metric.DIT));
context.saveMeasure(sonarFile, CoreMetrics.NUMBER_OF_CHILDREN, squidFile.getDouble(Metric.NOC));
context.saveMeasure(sonarFile, CoreMetrics.RFC, squidFile.getDouble(Metric.RFC));
- context.saveMeasure(sonarFile, CoreMetrics.LCOM4, squidFile.getDouble(Metric.LCOM4));
+ context.saveMeasure(sonarFile, CoreMetrics.LCOM4, getLcom4(squidFile));
+ }
+
+ static double getLcom4(SourceFile squidFile) {
+ return Math.max(squidFile.getDouble(Metric.LCOM4), 1.0);
}
}
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/ChidamberKemererBridgeTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/ChidamberKemererBridgeTest.java
index c032a434b31..0d67ba202c5 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/ChidamberKemererBridgeTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/ChidamberKemererBridgeTest.java
@@ -23,13 +23,15 @@ import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.anyDouble;
import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.*;
import org.junit.Test;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.resources.JavaFile;
import org.sonar.api.resources.JavaPackage;
+import org.sonar.squid.api.SourceFile;
+import org.sonar.squid.measures.Metric;
+import org.sonar.squid.measures.MetricDef;
public class ChidamberKemererBridgeTest extends BridgeTestCase {
@@ -58,4 +60,18 @@ public class ChidamberKemererBridgeTest extends BridgeTestCase {
verify(context, never()).saveMeasure(eq(new JavaPackage("org.apache.struts.config")), eq(CoreMetrics.LCOM4), anyDouble());
verify(context, never()).saveMeasure(eq(project), eq(CoreMetrics.LCOM4), anyDouble());
}
+
+ @Test
+ public void lcom4ShouldBeGreaterThanZero() {
+ SourceFile sourceFile = mock(SourceFile.class);
+
+ when(sourceFile.getDouble(Metric.LCOM4)).thenReturn(2.0);
+ assertThat(ChidamberKemererBridge.getLcom4(sourceFile), is(2.0));
+
+ when(sourceFile.getDouble(Metric.LCOM4)).thenReturn(1.0);
+ assertThat(ChidamberKemererBridge.getLcom4(sourceFile), is(1.0));
+
+ when(sourceFile.getDouble(Metric.LCOM4)).thenReturn(0.0);
+ assertThat(ChidamberKemererBridge.getLcom4(sourceFile), is(1.0));
+ }
}