From 1d1a0d0b9cc606f3ed6f177f29ade4a40dce06c7 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Wed, 3 Oct 2012 08:20:22 +0200 Subject: [PATCH] SONAR-2804 Add tests for merged coverage --- .../AllTestsLineCoverageDecorator.java | 1 - .../core/widgets/AllTestsCoverageWidget.java | 5 +- .../plugins/core/widgets/CoverageWidget.java | 1 - .../core/widgets/ItCoverageWidget.java | 5 +- .../AllTestsBranchCoverageDecoratorTest.java | 72 +++++++++++ .../AllTestsCoverageDecoratorTest.java | 104 ++++++++++++++++ .../AllTestsLineCoverageDecoratorTest.java | 113 ++++++++++++++++++ .../sensors/BranchCoverageDecoratorTest.java | 56 ++++----- .../core/sensors/CoverageDecoratorTest.java | 59 +++++---- .../ItBranchCoverageDecoratorTest.java | 72 +++++++++++ .../core/sensors/ItCoverageDecoratorTest.java | 104 ++++++++++++++++ .../sensors/ItLineCoverageDecoratorTest.java | 112 +++++++++++++++++ .../sensors/LineCoverageDecoratorTest.java | 76 +++++++----- .../widgets/AllTestsCoverageWidgetTest.java | 41 +++++++ .../core/widgets/CoverageWidgetTest.java | 41 +++++++ .../core/widgets/ItCoverageWidgetTest.java | 41 +++++++ 16 files changed, 804 insertions(+), 99 deletions(-) create mode 100644 plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/AllTestsBranchCoverageDecoratorTest.java create mode 100644 plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/AllTestsCoverageDecoratorTest.java create mode 100644 plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/AllTestsLineCoverageDecoratorTest.java create mode 100644 plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ItBranchCoverageDecoratorTest.java create mode 100644 plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ItCoverageDecoratorTest.java create mode 100644 plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ItLineCoverageDecoratorTest.java create mode 100644 plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/AllTestsCoverageWidgetTest.java create mode 100644 plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/CoverageWidgetTest.java create mode 100644 plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/ItCoverageWidgetTest.java diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AllTestsLineCoverageDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AllTestsLineCoverageDecorator.java index 6fb9a973994..969cc1cae1b 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AllTestsLineCoverageDecorator.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AllTestsLineCoverageDecorator.java @@ -29,7 +29,6 @@ import java.util.Arrays; import java.util.List; public final class AllTestsLineCoverageDecorator extends AbstractCoverageDecorator { - @DependsUpon public List dependsUponMetrics() { return Arrays.asList(CoreMetrics.MERGED_UNCOVERED_LINES, CoreMetrics.MERGED_LINES_TO_COVER, CoreMetrics.NEW_MERGED_UNCOVERED_LINES, diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/AllTestsCoverageWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/AllTestsCoverageWidget.java index 8828ded647a..619352fd3fa 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/AllTestsCoverageWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/AllTestsCoverageWidget.java @@ -24,10 +24,9 @@ import org.sonar.api.web.RubyRailsWidget; import org.sonar.api.web.UserRole; import org.sonar.api.web.WidgetCategory; -@WidgetCategory({ "Tests" }) +@WidgetCategory("Tests") @UserRole(UserRole.USER) public class AllTestsCoverageWidget extends AbstractRubyTemplate implements RubyRailsWidget { - public String getId() { return "merged-coverage"; } @@ -40,4 +39,4 @@ public class AllTestsCoverageWidget extends AbstractRubyTemplate implements Ruby protected String getTemplatePath() { return "/org/sonar/plugins/core/widgets/merged_coverage.html.erb"; } -} \ No newline at end of file +} diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/CoverageWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/CoverageWidget.java index 3811df85872..64c7718d62c 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/CoverageWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/CoverageWidget.java @@ -27,7 +27,6 @@ import org.sonar.api.web.WidgetCategory; @WidgetCategory("Tests") @UserRole(UserRole.USER) public class CoverageWidget extends AbstractRubyTemplate implements RubyRailsWidget { - public String getId() { return "code_coverage"; } diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/ItCoverageWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/ItCoverageWidget.java index f1b85ce49d3..20219bcb9c2 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/ItCoverageWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/ItCoverageWidget.java @@ -24,10 +24,9 @@ import org.sonar.api.web.RubyRailsWidget; import org.sonar.api.web.UserRole; import org.sonar.api.web.WidgetCategory; -@WidgetCategory({ "Tests" }) +@WidgetCategory("Tests") @UserRole(UserRole.USER) public class ItCoverageWidget extends AbstractRubyTemplate implements RubyRailsWidget { - public String getId() { return "it-coverage"; } @@ -40,4 +39,4 @@ public class ItCoverageWidget extends AbstractRubyTemplate implements RubyRailsW protected String getTemplatePath() { return "/org/sonar/plugins/core/widgets/it_coverage.html.erb"; } -} \ No newline at end of file +} diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/AllTestsBranchCoverageDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/AllTestsBranchCoverageDecoratorTest.java new file mode 100644 index 00000000000..58f79a7ad4a --- /dev/null +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/AllTestsBranchCoverageDecoratorTest.java @@ -0,0 +1,72 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2012 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.plugins.core.sensors; + +import org.junit.Before; +import org.junit.Test; +import org.sonar.api.batch.DecoratorContext; +import org.sonar.api.measures.CoreMetrics; +import org.sonar.api.measures.Measure; +import org.sonar.api.resources.Project; +import org.sonar.api.resources.Qualifiers; +import org.sonar.api.resources.Scopes; + +import static org.mockito.Matchers.anyDouble; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class AllTestsBranchCoverageDecoratorTest { + private final AllTestsBranchCoverageDecorator decorator = new AllTestsBranchCoverageDecorator(); + private final Project resource = mock(Project.class); + + @Before + public void setUp() { + when(resource.getScope()).thenReturn(Scopes.PROJECT); + when(resource.getQualifier()).thenReturn(Qualifiers.PROJECT); + } + + @Test + public void shouldSaveBranchCoverage() { + DecoratorContext context = mockContext(20, 15); + + decorator.decorate(resource, context); + + verify(context).saveMeasure(CoreMetrics.MERGED_BRANCH_COVERAGE, 25.0); + } + + @Test + public void shouldNotSaveBranchCoverageIfMissingConditions() { + DecoratorContext context = mock(DecoratorContext.class); + + decorator.decorate(resource, context); + + verify(context, never()).saveMeasure(eq(CoreMetrics.MERGED_BRANCH_COVERAGE), anyDouble()); + } + + private static DecoratorContext mockContext(int conditions, int uncoveredConditions) { + DecoratorContext context = mock(DecoratorContext.class); + when(context.getMeasure(CoreMetrics.MERGED_CONDITIONS_TO_COVER)).thenReturn(new Measure(CoreMetrics.MERGED_CONDITIONS_TO_COVER, (double) conditions)); + when(context.getMeasure(CoreMetrics.MERGED_UNCOVERED_CONDITIONS)).thenReturn(new Measure(CoreMetrics.MERGED_UNCOVERED_CONDITIONS, (double) uncoveredConditions)); + return context; + } +} diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/AllTestsCoverageDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/AllTestsCoverageDecoratorTest.java new file mode 100644 index 00000000000..0a51ab09c5e --- /dev/null +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/AllTestsCoverageDecoratorTest.java @@ -0,0 +1,104 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2012 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.plugins.core.sensors; + +import org.junit.Before; +import org.junit.Test; +import org.sonar.api.batch.DecoratorContext; +import org.sonar.api.measures.CoreMetrics; +import org.sonar.api.measures.Measure; +import org.sonar.api.resources.Project; +import org.sonar.api.resources.Scopes; + +import static org.fest.assertions.Assertions.assertThat; +import static org.mockito.Matchers.anyDouble; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class AllTestsCoverageDecoratorTest { + private final AllTestsCoverageDecorator decorator = new AllTestsCoverageDecorator(); + private final Project project = mock(Project.class); + + @Before + public void before() { + when(project.getScope()).thenReturn(Scopes.PROJECT); + } + + @Test + public void noCoverageWhenStaticAnalysis() { + when(project.getAnalysisType()).thenReturn(Project.AnalysisType.STATIC); + assertThat(new CoverageDecorator().shouldExecuteOnProject(project)).isFalse(); + + when(project.getAnalysisType()).thenReturn(Project.AnalysisType.REUSE_REPORTS); + assertThat(new CoverageDecorator().shouldExecuteOnProject(project)).isTrue(); + + when(project.getAnalysisType()).thenReturn(Project.AnalysisType.DYNAMIC); + assertThat(new CoverageDecorator().shouldExecuteOnProject(project)).isTrue(); + } + + @Test + public void coverage() { + DecoratorContext context = mockContext(50, 40, 10, 8); + + decorator.decorate(project, context); + + // (50-40 covered lines + 10-8 covered conditions) / (50 lines + 10 conditions) + verify(context).saveMeasure(CoreMetrics.MERGED_COVERAGE, 20.0); + } + + @Test + public void coverageCanBe0() { + DecoratorContext context = mockContext(50, 50, 5, 5); + + decorator.decorate(project, context); + + verify(context).saveMeasure(CoreMetrics.MERGED_COVERAGE, 0.0); + } + + @Test + public void coverageCanBe100() { + DecoratorContext context = mockContext(50, 0, 5, 0); + + decorator.decorate(project, context); + + verify(context).saveMeasure(CoreMetrics.MERGED_COVERAGE, 100.0); + } + + @Test + public void noCoverageIfNoElements() { + DecoratorContext context = mock(DecoratorContext.class); + + decorator.decorate(project, context); + + verify(context, never()).saveMeasure(eq(CoreMetrics.MERGED_COVERAGE), anyDouble()); + } + + private static DecoratorContext mockContext(int lines, int uncoveredLines, int conditions, int uncoveredConditions) { + DecoratorContext context = mock(DecoratorContext.class); + when(context.getMeasure(CoreMetrics.MERGED_LINES_TO_COVER)).thenReturn(new Measure(CoreMetrics.MERGED_LINES_TO_COVER, (double) lines)); + when(context.getMeasure(CoreMetrics.MERGED_UNCOVERED_LINES)).thenReturn(new Measure(CoreMetrics.MERGED_UNCOVERED_LINES, (double) uncoveredLines)); + when(context.getMeasure(CoreMetrics.MERGED_CONDITIONS_TO_COVER)).thenReturn(new Measure(CoreMetrics.MERGED_CONDITIONS_TO_COVER, (double) conditions)); + when(context.getMeasure(CoreMetrics.MERGED_UNCOVERED_CONDITIONS)).thenReturn(new Measure(CoreMetrics.MERGED_UNCOVERED_CONDITIONS, (double) uncoveredConditions)); + return context; + } +} diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/AllTestsLineCoverageDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/AllTestsLineCoverageDecoratorTest.java new file mode 100644 index 00000000000..d9eb3f67744 --- /dev/null +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/AllTestsLineCoverageDecoratorTest.java @@ -0,0 +1,113 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2012 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.plugins.core.sensors; + +import org.junit.Before; +import org.junit.Test; +import org.sonar.api.batch.DecoratorContext; +import org.sonar.api.measures.CoreMetrics; +import org.sonar.api.measures.Measure; +import org.sonar.api.measures.Metric; +import org.sonar.api.resources.Project; +import org.sonar.api.resources.Scopes; + +import java.util.List; + +import static org.fest.assertions.Assertions.assertThat; +import static org.mockito.Mockito.anyDouble; +import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class AllTestsLineCoverageDecoratorTest { + private final AllTestsLineCoverageDecorator decorator = new AllTestsLineCoverageDecorator(); + private final Project project = mock(Project.class); + + @Before + public void before() { + when(project.getScope()).thenReturn(Scopes.PROJECT); + } + + @Test + public void should_depend_on_coverage_metrics() { + List metrics = decorator.dependsUponMetrics(); + + assertThat(metrics).containsOnly(CoreMetrics.MERGED_UNCOVERED_LINES, CoreMetrics.MERGED_LINES_TO_COVER, CoreMetrics.NEW_MERGED_UNCOVERED_LINES, + CoreMetrics.NEW_MERGED_LINES_TO_COVER); + } + + @Test + public void noCoverageWhenStaticAnalysis() { + when(project.getAnalysisType()).thenReturn(Project.AnalysisType.STATIC); + assertThat(decorator.shouldExecuteOnProject(project)).isFalse(); + + when(project.getAnalysisType()).thenReturn(Project.AnalysisType.REUSE_REPORTS); + assertThat(decorator.shouldExecuteOnProject(project)).isTrue(); + + when(project.getAnalysisType()).thenReturn(Project.AnalysisType.DYNAMIC); + assertThat(decorator.shouldExecuteOnProject(project)).isTrue(); + } + + @Test + public void lineCoverage() { + DecoratorContext context = mockContext(50, 10); + + decorator.decorate(project, context); + + // 50-10 covered lines / 50 lines + verify(context).saveMeasure(CoreMetrics.MERGED_LINE_COVERAGE, 80.0); + } + + @Test + public void zeroCoveredLines() { + DecoratorContext context = mockContext(50, 50); + + decorator.decorate(project, context); + + verify(context).saveMeasure(CoreMetrics.MERGED_LINE_COVERAGE, 0.0); + } + + @Test + public void allCoveredLines() { + DecoratorContext context = mockContext(50, 00); + + decorator.decorate(project, context); + + verify(context).saveMeasure(CoreMetrics.MERGED_LINE_COVERAGE, 100.0); + } + + @Test + public void noLineCoverageIfNoLines() { + DecoratorContext context = mock(DecoratorContext.class); + + decorator.decorate(project, context); + + verify(context, never()).saveMeasure(eq(CoreMetrics.MERGED_LINE_COVERAGE), anyDouble()); + } + + private static DecoratorContext mockContext(int lines, int uncoveredLines) { + DecoratorContext context = mock(DecoratorContext.class); + when(context.getMeasure(CoreMetrics.MERGED_LINES_TO_COVER)).thenReturn(new Measure(CoreMetrics.MERGED_LINES_TO_COVER, (double) lines)); + when(context.getMeasure(CoreMetrics.MERGED_UNCOVERED_LINES)).thenReturn(new Measure(CoreMetrics.MERGED_UNCOVERED_LINES, (double) uncoveredLines)); + return context; + } +} diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/BranchCoverageDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/BranchCoverageDecoratorTest.java index f20bc69ba81..c49c38ee1f0 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/BranchCoverageDecoratorTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/BranchCoverageDecoratorTest.java @@ -19,52 +19,54 @@ */ package org.sonar.plugins.core.sensors; -import org.sonar.api.resources.Resource; - +import org.junit.Before; import org.junit.Test; -import static org.mockito.Matchers.anyDouble; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.*; import org.sonar.api.batch.DecoratorContext; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Measure; import org.sonar.api.resources.Project; +import org.sonar.api.resources.Qualifiers; +import org.sonar.api.resources.Scopes; -public class BranchCoverageDecoratorTest { - - @Test - public void shouldNotSaveBranchCoverageIfMissingConditions() { - Project resource = mock(Project.class); - when(resource.getScope()).thenReturn(Resource.SCOPE_SET); - when(resource.getQualifier()).thenReturn(Resource.QUALIFIER_SUBVIEW); +import static org.mockito.Matchers.anyDouble; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; - DecoratorContext context = mockContext(null, null); - new BranchCoverageDecorator().decorate(resource, context); +public class BranchCoverageDecoratorTest { + private final BranchCoverageDecorator decorator = new BranchCoverageDecorator(); + private final Project resource = mock(Project.class); - verify(context, never()).saveMeasure(eq(CoreMetrics.BRANCH_COVERAGE), anyDouble()); + @Before + public void setUp() { + when(resource.getScope()).thenReturn(Scopes.PROJECT); + when(resource.getQualifier()).thenReturn(Qualifiers.PROJECT); } @Test public void shouldSaveBranchCoverage() { - Project resource = mock(Project.class); - when(resource.getScope()).thenReturn(Resource.SCOPE_SET); - when(resource.getQualifier()).thenReturn(Resource.QUALIFIER_PROJECT); - DecoratorContext context = mockContext(20, 15); - new BranchCoverageDecorator().decorate(resource, context); + decorator.decorate(resource, context); + verify(context).saveMeasure(CoreMetrics.BRANCH_COVERAGE, 25.0); } + @Test + public void shouldNotSaveBranchCoverageIfMissingConditions() { + DecoratorContext context = mock(DecoratorContext.class); + + decorator.decorate(resource, context); + + verify(context, never()).saveMeasure(eq(CoreMetrics.BRANCH_COVERAGE), anyDouble()); + } - private DecoratorContext mockContext(Integer conditions, Integer uncoveredConditions) { + private static DecoratorContext mockContext(int conditions, int uncoveredConditions) { DecoratorContext context = mock(DecoratorContext.class); - if (conditions != null) { - when(context.getMeasure(CoreMetrics.CONDITIONS_TO_COVER)).thenReturn(new Measure(CoreMetrics.CONDITIONS_TO_COVER, conditions.doubleValue())); - } - if (uncoveredConditions != null) { - when(context.getMeasure(CoreMetrics.UNCOVERED_CONDITIONS)).thenReturn(new Measure(CoreMetrics.UNCOVERED_CONDITIONS, uncoveredConditions.doubleValue())); - } + when(context.getMeasure(CoreMetrics.CONDITIONS_TO_COVER)).thenReturn(new Measure(CoreMetrics.CONDITIONS_TO_COVER, (double) conditions)); + when(context.getMeasure(CoreMetrics.UNCOVERED_CONDITIONS)).thenReturn(new Measure(CoreMetrics.UNCOVERED_CONDITIONS, (double) uncoveredConditions)); return context; } } diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CoverageDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CoverageDecoratorTest.java index 30067c35fa7..2821f94c407 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CoverageDecoratorTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CoverageDecoratorTest.java @@ -19,46 +19,48 @@ */ package org.sonar.plugins.core.sensors; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -import org.sonar.api.resources.Resource; - import org.junit.Before; import org.junit.Test; -import static org.mockito.Mockito.*; import org.sonar.api.batch.DecoratorContext; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Measure; import org.sonar.api.resources.Project; +import org.sonar.api.resources.Scopes; -public class CoverageDecoratorTest { +import static org.fest.assertions.Assertions.assertThat; +import static org.mockito.Mockito.anyDouble; +import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; - private Project project = null; +public class CoverageDecoratorTest { + private final CoverageDecorator decorator = new CoverageDecorator(); + private final Project project = mock(Project.class); @Before public void before() { - project = mock(Project.class); - when(project.getScope()).thenReturn(Resource.SCOPE_SET); + when(project.getScope()).thenReturn(Scopes.PROJECT); } @Test public void noCoverageWhenStaticAnalysis() { when(project.getAnalysisType()).thenReturn(Project.AnalysisType.STATIC); - assertThat(new CoverageDecorator().shouldExecuteOnProject(project), is(false)); + assertThat(new CoverageDecorator().shouldExecuteOnProject(project)).isFalse(); when(project.getAnalysisType()).thenReturn(Project.AnalysisType.REUSE_REPORTS); - assertThat(new CoverageDecorator().shouldExecuteOnProject(project), is(true)); + assertThat(new CoverageDecorator().shouldExecuteOnProject(project)).isTrue(); when(project.getAnalysisType()).thenReturn(Project.AnalysisType.DYNAMIC); - assertThat(new CoverageDecorator().shouldExecuteOnProject(project), is(true)); + assertThat(new CoverageDecorator().shouldExecuteOnProject(project)).isTrue(); } @Test public void coverage() { DecoratorContext context = mockContext(50, 40, 10, 8); - new CoverageDecorator().decorate(project, context); + decorator.decorate(project, context); // (50-40 covered lines + 10-8 covered conditions) / (50 lines + 10 conditions) verify(context).saveMeasure(CoreMetrics.COVERAGE, 20.0); @@ -67,7 +69,8 @@ public class CoverageDecoratorTest { @Test public void coverageCanBe0() { DecoratorContext context = mockContext(50, 50, 5, 5); - new CoverageDecorator().decorate(project, context); + + decorator.decorate(project, context); verify(context).saveMeasure(CoreMetrics.COVERAGE, 0.0); } @@ -75,33 +78,27 @@ public class CoverageDecoratorTest { @Test public void coverageCanBe100() { DecoratorContext context = mockContext(50, 0, 5, 0); - new CoverageDecorator().decorate(project, context); + + decorator.decorate(project, context); verify(context).saveMeasure(CoreMetrics.COVERAGE, 100.0); } @Test public void noCoverageIfNoElements() { - DecoratorContext context = mockContext(null, null, null, null); - new CoverageDecorator().decorate(project, context); + DecoratorContext context = mock(DecoratorContext.class); + + decorator.decorate(project, context); verify(context, never()).saveMeasure(eq(CoreMetrics.COVERAGE), anyDouble()); } - private DecoratorContext mockContext(Integer lines, Integer uncoveredLines, Integer conditions, Integer uncoveredConditions) { + private static DecoratorContext mockContext(int lines, int uncoveredLines, int conditions, int uncoveredConditions) { DecoratorContext context = mock(DecoratorContext.class); - if (lines != null) { - when(context.getMeasure(CoreMetrics.LINES_TO_COVER)).thenReturn(new Measure(CoreMetrics.LINES_TO_COVER, lines.doubleValue())); - } - if (uncoveredLines != null) { - when(context.getMeasure(CoreMetrics.UNCOVERED_LINES)).thenReturn(new Measure(CoreMetrics.UNCOVERED_LINES, uncoveredLines.doubleValue())); - } - if (conditions != null) { - when(context.getMeasure(CoreMetrics.CONDITIONS_TO_COVER)).thenReturn(new Measure(CoreMetrics.CONDITIONS_TO_COVER, conditions.doubleValue())); - } - if (uncoveredConditions != null) { - when(context.getMeasure(CoreMetrics.UNCOVERED_CONDITIONS)).thenReturn(new Measure(CoreMetrics.UNCOVERED_CONDITIONS, uncoveredConditions.doubleValue())); - } + when(context.getMeasure(CoreMetrics.LINES_TO_COVER)).thenReturn(new Measure(CoreMetrics.LINES_TO_COVER, (double) lines)); + when(context.getMeasure(CoreMetrics.UNCOVERED_LINES)).thenReturn(new Measure(CoreMetrics.UNCOVERED_LINES, (double) uncoveredLines)); + when(context.getMeasure(CoreMetrics.CONDITIONS_TO_COVER)).thenReturn(new Measure(CoreMetrics.CONDITIONS_TO_COVER, (double) conditions)); + when(context.getMeasure(CoreMetrics.UNCOVERED_CONDITIONS)).thenReturn(new Measure(CoreMetrics.UNCOVERED_CONDITIONS, (double) uncoveredConditions)); return context; } } diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ItBranchCoverageDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ItBranchCoverageDecoratorTest.java new file mode 100644 index 00000000000..ee7e22f1c34 --- /dev/null +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ItBranchCoverageDecoratorTest.java @@ -0,0 +1,72 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2012 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.plugins.core.sensors; + +import org.junit.Before; +import org.junit.Test; +import org.sonar.api.batch.DecoratorContext; +import org.sonar.api.measures.CoreMetrics; +import org.sonar.api.measures.Measure; +import org.sonar.api.resources.Project; +import org.sonar.api.resources.Qualifiers; +import org.sonar.api.resources.Scopes; + +import static org.mockito.Matchers.anyDouble; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class ItBranchCoverageDecoratorTest { + private final ItBranchCoverageDecorator decorator = new ItBranchCoverageDecorator(); + private final Project resource = mock(Project.class); + + @Before + public void setUp() { + when(resource.getScope()).thenReturn(Scopes.PROJECT); + when(resource.getQualifier()).thenReturn(Qualifiers.PROJECT); + } + + @Test + public void shouldSaveBranchCoverage() { + DecoratorContext context = mockContext(20, 15); + + decorator.decorate(resource, context); + + verify(context).saveMeasure(CoreMetrics.IT_BRANCH_COVERAGE, 25.0); + } + + @Test + public void shouldNotSaveBranchCoverageIfMissingConditions() { + DecoratorContext context = mock(DecoratorContext.class); + + decorator.decorate(resource, context); + + verify(context, never()).saveMeasure(eq(CoreMetrics.IT_BRANCH_COVERAGE), anyDouble()); + } + + private static DecoratorContext mockContext(int conditions, int uncoveredConditions) { + DecoratorContext context = mock(DecoratorContext.class); + when(context.getMeasure(CoreMetrics.IT_CONDITIONS_TO_COVER)).thenReturn(new Measure(CoreMetrics.IT_CONDITIONS_TO_COVER, (double) conditions)); + when(context.getMeasure(CoreMetrics.IT_UNCOVERED_CONDITIONS)).thenReturn(new Measure(CoreMetrics.IT_UNCOVERED_CONDITIONS, (double) uncoveredConditions)); + return context; + } +} diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ItCoverageDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ItCoverageDecoratorTest.java new file mode 100644 index 00000000000..76e15386150 --- /dev/null +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ItCoverageDecoratorTest.java @@ -0,0 +1,104 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2012 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.plugins.core.sensors; + +import org.junit.Before; +import org.junit.Test; +import org.sonar.api.batch.DecoratorContext; +import org.sonar.api.measures.CoreMetrics; +import org.sonar.api.measures.Measure; +import org.sonar.api.resources.Project; +import org.sonar.api.resources.Scopes; + +import static org.fest.assertions.Assertions.assertThat; +import static org.mockito.Matchers.anyDouble; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class ItCoverageDecoratorTest { + private final ItCoverageDecorator decorator = new ItCoverageDecorator(); + private final Project project = mock(Project.class); + + @Before + public void before() { + when(project.getScope()).thenReturn(Scopes.PROJECT); + } + + @Test + public void noCoverageWhenStaticAnalysis() { + when(project.getAnalysisType()).thenReturn(Project.AnalysisType.STATIC); + assertThat(new CoverageDecorator().shouldExecuteOnProject(project)).isFalse(); + + when(project.getAnalysisType()).thenReturn(Project.AnalysisType.REUSE_REPORTS); + assertThat(new CoverageDecorator().shouldExecuteOnProject(project)).isTrue(); + + when(project.getAnalysisType()).thenReturn(Project.AnalysisType.DYNAMIC); + assertThat(new CoverageDecorator().shouldExecuteOnProject(project)).isTrue(); + } + + @Test + public void coverage() { + DecoratorContext context = mockContext(50, 40, 10, 8); + + decorator.decorate(project, context); + + // (50-40 covered lines + 10-8 covered conditions) / (50 lines + 10 conditions) + verify(context).saveMeasure(CoreMetrics.IT_COVERAGE, 20.0); + } + + @Test + public void coverageCanBe0() { + DecoratorContext context = mockContext(50, 50, 5, 5); + + decorator.decorate(project, context); + + verify(context).saveMeasure(CoreMetrics.IT_COVERAGE, 0.0); + } + + @Test + public void coverageCanBe100() { + DecoratorContext context = mockContext(50, 0, 5, 0); + + decorator.decorate(project, context); + + verify(context).saveMeasure(CoreMetrics.IT_COVERAGE, 100.0); + } + + @Test + public void noCoverageIfNoElements() { + DecoratorContext context = mock(DecoratorContext.class); + + decorator.decorate(project, context); + + verify(context, never()).saveMeasure(eq(CoreMetrics.IT_COVERAGE), anyDouble()); + } + + private static DecoratorContext mockContext(int lines, int uncoveredLines, int conditions, int uncoveredConditions) { + DecoratorContext context = mock(DecoratorContext.class); + when(context.getMeasure(CoreMetrics.IT_LINES_TO_COVER)).thenReturn(new Measure(CoreMetrics.IT_LINES_TO_COVER, (double) lines)); + when(context.getMeasure(CoreMetrics.IT_UNCOVERED_LINES)).thenReturn(new Measure(CoreMetrics.IT_UNCOVERED_LINES, (double) uncoveredLines)); + when(context.getMeasure(CoreMetrics.IT_CONDITIONS_TO_COVER)).thenReturn(new Measure(CoreMetrics.IT_CONDITIONS_TO_COVER, (double) conditions)); + when(context.getMeasure(CoreMetrics.IT_UNCOVERED_CONDITIONS)).thenReturn(new Measure(CoreMetrics.IT_UNCOVERED_CONDITIONS, (double) uncoveredConditions)); + return context; + } +} diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ItLineCoverageDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ItLineCoverageDecoratorTest.java new file mode 100644 index 00000000000..12b4941bade --- /dev/null +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ItLineCoverageDecoratorTest.java @@ -0,0 +1,112 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2012 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.plugins.core.sensors; + +import org.junit.Before; +import org.junit.Test; +import org.sonar.api.batch.DecoratorContext; +import org.sonar.api.measures.CoreMetrics; +import org.sonar.api.measures.Measure; +import org.sonar.api.measures.Metric; +import org.sonar.api.resources.Project; +import org.sonar.api.resources.Scopes; + +import java.util.List; + +import static org.fest.assertions.Assertions.assertThat; +import static org.mockito.Mockito.anyDouble; +import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class ItLineCoverageDecoratorTest { + private final ItLineCoverageDecorator decorator = new ItLineCoverageDecorator(); + private final Project project = mock(Project.class); + + @Before + public void before() { + when(project.getScope()).thenReturn(Scopes.PROJECT); + } + + @Test + public void should_depend_on_coverage_metrics() { + List metrics = decorator.dependsUponMetrics(); + + assertThat(metrics).containsOnly(CoreMetrics.IT_UNCOVERED_LINES, CoreMetrics.IT_LINES_TO_COVER, CoreMetrics.NEW_IT_UNCOVERED_LINES, CoreMetrics.NEW_IT_LINES_TO_COVER); + } + + @Test + public void noCoverageWhenStaticAnalysis() { + when(project.getAnalysisType()).thenReturn(Project.AnalysisType.STATIC); + assertThat(decorator.shouldExecuteOnProject(project)).isFalse(); + + when(project.getAnalysisType()).thenReturn(Project.AnalysisType.REUSE_REPORTS); + assertThat(decorator.shouldExecuteOnProject(project)).isTrue(); + + when(project.getAnalysisType()).thenReturn(Project.AnalysisType.DYNAMIC); + assertThat(decorator.shouldExecuteOnProject(project)).isTrue(); + } + + @Test + public void lineCoverage() { + DecoratorContext context = mockContext(50, 10); + + decorator.decorate(project, context); + + // 50-10 covered lines / 50 lines + verify(context).saveMeasure(CoreMetrics.IT_LINE_COVERAGE, 80.0); + } + + @Test + public void zeroCoveredLines() { + DecoratorContext context = mockContext(50, 50); + + decorator.decorate(project, context); + + verify(context).saveMeasure(CoreMetrics.IT_LINE_COVERAGE, 0.0); + } + + @Test + public void allCoveredLines() { + DecoratorContext context = mockContext(50, 00); + + decorator.decorate(project, context); + + verify(context).saveMeasure(CoreMetrics.IT_LINE_COVERAGE, 100.0); + } + + @Test + public void noLineCoverageIfNoLines() { + DecoratorContext context = mock(DecoratorContext.class); + + decorator.decorate(project, context); + + verify(context, never()).saveMeasure(eq(CoreMetrics.IT_LINE_COVERAGE), anyDouble()); + } + + private static DecoratorContext mockContext(int lines, int uncoveredLines) { + DecoratorContext context = mock(DecoratorContext.class); + when(context.getMeasure(CoreMetrics.IT_LINES_TO_COVER)).thenReturn(new Measure(CoreMetrics.IT_LINES_TO_COVER, (double) lines)); + when(context.getMeasure(CoreMetrics.IT_UNCOVERED_LINES)).thenReturn(new Measure(CoreMetrics.IT_UNCOVERED_LINES, (double) uncoveredLines)); + return context; + } +} diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/LineCoverageDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/LineCoverageDecoratorTest.java index fe54290362e..0a69958c06c 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/LineCoverageDecoratorTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/LineCoverageDecoratorTest.java @@ -19,63 +19,68 @@ */ package org.sonar.plugins.core.sensors; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -import org.sonar.api.resources.Resource; - import org.junit.Before; import org.junit.Test; -import static org.mockito.Mockito.*; import org.sonar.api.batch.DecoratorContext; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Measure; +import org.sonar.api.measures.Metric; import org.sonar.api.resources.Project; +import org.sonar.api.resources.Scopes; -public class LineCoverageDecoratorTest { +import java.util.List; - private Project project = null; +import static org.fest.assertions.Assertions.assertThat; +import static org.mockito.Mockito.anyDouble; +import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class LineCoverageDecoratorTest { + private final LineCoverageDecorator decorator = new LineCoverageDecorator(); + private final Project project = mock(Project.class); @Before public void before() { - project = mock(Project.class); - when(project.getScope()).thenReturn(Resource.SCOPE_SET); + when(project.getScope()).thenReturn(Scopes.PROJECT); + } + + @Test + public void should_depend_on_coverage_metrics() { + List metrics = decorator.dependsUponMetrics(); + + assertThat(metrics).containsOnly(CoreMetrics.UNCOVERED_LINES, CoreMetrics.LINES_TO_COVER, CoreMetrics.NEW_UNCOVERED_LINES, CoreMetrics.NEW_LINES_TO_COVER); } @Test public void noCoverageWhenStaticAnalysis() { when(project.getAnalysisType()).thenReturn(Project.AnalysisType.STATIC); - assertThat(new LineCoverageDecorator().shouldExecuteOnProject(project), is(false)); + assertThat(decorator.shouldExecuteOnProject(project)).isFalse(); when(project.getAnalysisType()).thenReturn(Project.AnalysisType.REUSE_REPORTS); - assertThat(new LineCoverageDecorator().shouldExecuteOnProject(project), is(true)); + assertThat(decorator.shouldExecuteOnProject(project)).isTrue(); when(project.getAnalysisType()).thenReturn(Project.AnalysisType.DYNAMIC); - assertThat(new LineCoverageDecorator().shouldExecuteOnProject(project), is(true)); + assertThat(decorator.shouldExecuteOnProject(project)).isTrue(); } @Test public void lineCoverage() { DecoratorContext context = mockContext(50, 10); - new LineCoverageDecorator().decorate(project, context); + + decorator.decorate(project, context); // 50-10 covered lines / 50 lines verify(context).saveMeasure(CoreMetrics.LINE_COVERAGE, 80.0); } - - @Test - public void noLineCoverageIfNoLines() { - DecoratorContext context = mockContext(null, null); - new LineCoverageDecorator().decorate(project, context); - - verify(context, never()).saveMeasure(eq(CoreMetrics.LINE_COVERAGE), anyDouble()); - } - @Test public void zeroCoveredLines() { DecoratorContext context = mockContext(50, 50); - new LineCoverageDecorator().decorate(project, context); + + decorator.decorate(project, context); verify(context).saveMeasure(CoreMetrics.LINE_COVERAGE, 0.0); } @@ -83,20 +88,25 @@ public class LineCoverageDecoratorTest { @Test public void allCoveredLines() { DecoratorContext context = mockContext(50, 00); - new LineCoverageDecorator().decorate(project, context); + + decorator.decorate(project, context); verify(context).saveMeasure(CoreMetrics.LINE_COVERAGE, 100.0); } - private DecoratorContext mockContext(Integer lines, Integer uncoveredLines) { + @Test + public void noLineCoverageIfNoLines() { + DecoratorContext context = mock(DecoratorContext.class); + + decorator.decorate(project, context); + + verify(context, never()).saveMeasure(eq(CoreMetrics.LINE_COVERAGE), anyDouble()); + } + + private static DecoratorContext mockContext(int lines, int uncoveredLines) { DecoratorContext context = mock(DecoratorContext.class); - if (lines != null) { - when(context.getMeasure(CoreMetrics.LINES_TO_COVER)).thenReturn(new Measure(CoreMetrics.LINES_TO_COVER, lines.doubleValue())); - } - if (uncoveredLines != null) { - when(context.getMeasure(CoreMetrics.UNCOVERED_LINES)).thenReturn(new Measure(CoreMetrics.UNCOVERED_LINES, uncoveredLines.doubleValue())); - } + when(context.getMeasure(CoreMetrics.LINES_TO_COVER)).thenReturn(new Measure(CoreMetrics.LINES_TO_COVER, (double) lines)); + when(context.getMeasure(CoreMetrics.UNCOVERED_LINES)).thenReturn(new Measure(CoreMetrics.UNCOVERED_LINES, (double) uncoveredLines)); return context; } - } diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/AllTestsCoverageWidgetTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/AllTestsCoverageWidgetTest.java new file mode 100644 index 00000000000..fc472d38cc5 --- /dev/null +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/AllTestsCoverageWidgetTest.java @@ -0,0 +1,41 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2012 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.plugins.core.widgets; + +import org.junit.Test; + +import static org.fest.assertions.Assertions.assertThat; + +public class AllTestsCoverageWidgetTest { + @Test + public void should_define_widget() { + AllTestsCoverageWidget widget = new AllTestsCoverageWidget(); + + assertThat(widget.getId()).isEqualTo("merged-coverage"); + assertThat(widget.getTitle()).isEqualTo("All Tests Coverage"); + } + + @Test + public void should_use_relative_path_for_template() { + AllTestsCoverageWidget widget = new AllTestsCoverageWidget(); + + assertThat(widget.getTemplatePath()).startsWith("/"); + } +} diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/CoverageWidgetTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/CoverageWidgetTest.java new file mode 100644 index 00000000000..8caa30430c0 --- /dev/null +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/CoverageWidgetTest.java @@ -0,0 +1,41 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2012 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.plugins.core.widgets; + +import org.junit.Test; + +import static org.fest.assertions.Assertions.assertThat; + +public class CoverageWidgetTest { + @Test + public void should_define_widget() { + CoverageWidget widget = new CoverageWidget(); + + assertThat(widget.getId()).isEqualTo("code_coverage"); + assertThat(widget.getTitle()).isEqualTo("Code coverage"); + } + + @Test + public void should_use_relative_path_for_template() { + CoverageWidget widget = new CoverageWidget(); + + assertThat(widget.getTemplatePath()).startsWith("/"); + } +} diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/ItCoverageWidgetTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/ItCoverageWidgetTest.java new file mode 100644 index 00000000000..7bf32fea1d2 --- /dev/null +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/ItCoverageWidgetTest.java @@ -0,0 +1,41 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2012 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.plugins.core.widgets; + +import org.junit.Test; + +import static org.fest.assertions.Assertions.assertThat; + +public class ItCoverageWidgetTest { + @Test + public void should_define_widget() { + ItCoverageWidget widget = new ItCoverageWidget(); + + assertThat(widget.getId()).isEqualTo("it-coverage"); + assertThat(widget.getTitle()).isEqualTo("Integration Test Coverage"); + } + + @Test + public void should_use_relative_path_for_template() { + ItCoverageWidget widget = new ItCoverageWidget(); + + assertThat(widget.getTemplatePath()).startsWith("/"); + } +} -- 2.39.5