diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2011-11-21 19:05:11 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2011-11-21 19:05:34 +0100 |
commit | 038521049d805ff6cf1b9d2cf98dcf59b8d665db (patch) | |
tree | 7c2b8c588fa4ecc6386c3d7f414cc994233be8d6 /plugins | |
parent | 58e876d9262832eb3e20cec5434422da7bc3e3e5 (diff) | |
download | sonarqube-038521049d805ff6cf1b9d2cf98dcf59b8d665db.tar.gz sonarqube-038521049d805ff6cf1b9d2cf98dcf59b8d665db.zip |
LCOM4 of Java files without any class - like package-info.java - must be 1
Diffstat (limited to 'plugins')
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)); + } } |