]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2804 Add tests for merged coverage
authorDavid Gageot <david@gageot.net>
Wed, 3 Oct 2012 06:20:22 +0000 (08:20 +0200)
committerDavid Gageot <david@gageot.net>
Wed, 3 Oct 2012 07:12:57 +0000 (09:12 +0200)
16 files changed:
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AllTestsLineCoverageDecorator.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/AllTestsCoverageWidget.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/CoverageWidget.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/ItCoverageWidget.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/AllTestsBranchCoverageDecoratorTest.java [new file with mode: 0644]
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/AllTestsCoverageDecoratorTest.java [new file with mode: 0644]
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/AllTestsLineCoverageDecoratorTest.java [new file with mode: 0644]
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/BranchCoverageDecoratorTest.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CoverageDecoratorTest.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ItBranchCoverageDecoratorTest.java [new file with mode: 0644]
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ItCoverageDecoratorTest.java [new file with mode: 0644]
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ItLineCoverageDecoratorTest.java [new file with mode: 0644]
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/LineCoverageDecoratorTest.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/AllTestsCoverageWidgetTest.java [new file with mode: 0644]
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/CoverageWidgetTest.java [new file with mode: 0644]
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/ItCoverageWidgetTest.java [new file with mode: 0644]

index 6fb9a973994aca7cea19ebba418e042483a81523..969cc1cae1b84a3769e644ddc56577568e5771c6 100644 (file)
@@ -29,7 +29,6 @@ import java.util.Arrays;
 import java.util.List;
 
 public final class AllTestsLineCoverageDecorator extends AbstractCoverageDecorator {
-
   @DependsUpon
   public List<Metric> dependsUponMetrics() {
     return Arrays.asList(CoreMetrics.MERGED_UNCOVERED_LINES, CoreMetrics.MERGED_LINES_TO_COVER, CoreMetrics.NEW_MERGED_UNCOVERED_LINES,
index 8828ded647ab2401228a632a3436d60a75f03031..619352fd3fa9ddab264d0a823f5055f4ce09fbbc 100644 (file)
@@ -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
+}
index 3811df858729cfdf6c913e9239fe7a69f135790d..64c7718d62c1c245365aeb4c3fc1caea0ef5bc16 100644 (file)
@@ -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";
   }
index f1b85ce49d3f2aed1f52d3440d2dff598754746f..20219bcb9c21a66ae6ab69cd9a71cb237b9eead3 100644 (file)
@@ -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 (file)
index 0000000..58f79a7
--- /dev/null
@@ -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 (file)
index 0000000..0a51ab0
--- /dev/null
@@ -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 (file)
index 0000000..d9eb3f6
--- /dev/null
@@ -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<Metric> 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;
+  }
+}
index f20bc69ba8191a72d8832bdd86d938d670c06212..c49c38ee1f025c2f92077f9f9e694a0b0e80d3e0 100644 (file)
  */
 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;
   }
 }
index 30067c35fa71374af93895cca17a29e1f7a980d0..2821f94c407763539b66e2bad29816d2cd4bdaa8 100644 (file)
  */
 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 (file)
index 0000000..ee7e22f
--- /dev/null
@@ -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 (file)
index 0000000..76e1538
--- /dev/null
@@ -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 (file)
index 0000000..12b4941
--- /dev/null
@@ -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<Metric> 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;
+  }
+}
index fe54290362edf8876a957b4fc88e332defc58bba..0a69958c06c754b9e94a0a03231862640038c9bd 100644 (file)
  */
 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<Metric> 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 (file)
index 0000000..fc472d3
--- /dev/null
@@ -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 (file)
index 0000000..8caa304
--- /dev/null
@@ -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 (file)
index 0000000..7bf32fe
--- /dev/null
@@ -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("/");
+  }
+}