diff options
author | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-04-19 19:33:47 +0400 |
---|---|---|
committer | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-04-20 01:41:21 +0400 |
commit | 060c18523247bd07431ba5de664193247afa7b9a (patch) | |
tree | f21fbef3885ea97d64939454a7fb3420ab444270 /plugins/sonar-core-plugin | |
parent | 5cc143c7351b3a5d8334a59b42720407232f4153 (diff) | |
download | sonarqube-060c18523247bd07431ba5de664193247afa7b9a.tar.gz sonarqube-060c18523247bd07431ba5de664193247afa7b9a.zip |
SONAR-2371 SurefireSensor should not insert unit test measures when there is no reports
- UnitTestDecorator should save zero for unit test measure for project, when there is
no values for summarizing and type of analysis is reuse reports or dynamic
- Don't use pom.getPackaging() in AbstractSurefireParser
Diffstat (limited to 'plugins/sonar-core-plugin')
2 files changed, 34 insertions, 4 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/UnitTestDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/UnitTestDecorator.java index c61a46bfec2..0f4ce4b9b69 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/UnitTestDecorator.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/UnitTestDecorator.java @@ -60,6 +60,9 @@ public class UnitTestDecorator implements Decorator { if (isPositive(tests, true) && isPositive(errors, false) && isPositive(failures, false)) { Double errorsAndFailuresRatio = (errors + failures) * 100.0 / tests; context.saveMeasure(CoreMetrics.TEST_SUCCESS_DENSITY, 100.0 - errorsAndFailuresRatio); + } else if (tests == null && ResourceUtils.isProject(resource)) { + // See http://jira.codehaus.org/browse/SONAR-2371 + context.saveMeasure(CoreMetrics.TESTS, 0.0); } } } diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/UnitTestDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/UnitTestDecoratorTest.java index 3b46ae33a0f..da3823d9a6d 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/UnitTestDecoratorTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/UnitTestDecoratorTest.java @@ -21,25 +21,52 @@ package org.sonar.plugins.core.sensors; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; -import org.junit.Test; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; + +import org.junit.Before; +import org.junit.Test; +import org.sonar.api.batch.DecoratorContext; +import org.sonar.api.measures.CoreMetrics; import org.sonar.api.resources.Project; public class UnitTestDecoratorTest { + private UnitTestDecorator decorator; + + @Before + public void setUp() { + decorator = new UnitTestDecorator(); + } + @Test public void generatesMetrics() { - assertThat(new UnitTestDecorator().generatesMetrics().size(), is(5)); + assertThat(decorator.generatesMetrics().size(), is(5)); } @Test public void doNotDecorateStaticAnalysis() { Project project = mock(Project.class); when(project.getAnalysisType()).thenReturn(Project.AnalysisType.STATIC); - assertThat(new UnitTestDecorator().shouldExecuteOnProject(project), is(false)); + assertThat(decorator.shouldExecuteOnProject(project), is(false)); when(project.getAnalysisType()).thenReturn(Project.AnalysisType.DYNAMIC); - assertThat(new UnitTestDecorator().shouldExecuteOnProject(project), is(true)); + assertThat(decorator.shouldExecuteOnProject(project), is(true)); } + + /** + * See http://jira.codehaus.org/browse/SONAR-2371 + */ + @Test + public void shouldSaveZeroOnProject() { + DecoratorContext context = mock(DecoratorContext.class); + Project project = new Project(""); + project.setAnalysisType(Project.AnalysisType.DYNAMIC); + + decorator.decorate(project, context); + + verify(context).saveMeasure(CoreMetrics.TESTS, 0.0); + } + } |