diff options
author | Julien Lancelot <julien.lancelot@gmail.com> | 2013-01-30 16:39:55 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@gmail.com> | 2013-01-30 16:40:11 +0100 |
commit | 5c9ee1b4ed291f2cd2465769b9a4d57dec25976c (patch) | |
tree | 8c89fd9b440359271ec76eb4e7996d49d39de798 | |
parent | 9ad5d28cfd7d94d81f7132e61e04c828f108a8cd (diff) | |
download | sonarqube-5c9ee1b4ed291f2cd2465769b9a4d57dec25976c.tar.gz sonarqube-5c9ee1b4ed291f2cd2465769b9a4d57dec25976c.zip |
SONAR-4093 Display a tooltip that contains number of tests for the current line
6 files changed, 18 insertions, 3 deletions
diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties index 1ec039bb182..81d6e8faa43 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties @@ -1085,6 +1085,7 @@ violations_drilldown.no_violations=No violations #------------------------------------------------------------------------------ resource_viewer.resource_deleted=This resource has been deleted. +number_of_tests_covering_line=Number of tests covering this line : {0} #------------------------------------------------------------------------------ diff --git a/sonar-core/src/main/java/org/sonar/core/test/DefaultTestCase.java b/sonar-core/src/main/java/org/sonar/core/test/DefaultTestCase.java index 5b6bb74405d..d14fddd3fe0 100644 --- a/sonar-core/src/main/java/org/sonar/core/test/DefaultTestCase.java +++ b/sonar-core/src/main/java/org/sonar/core/test/DefaultTestCase.java @@ -101,7 +101,8 @@ public class DefaultTestCase extends BeanVertex implements MutableTestCase { } public void covers(Testable testable, List<Integer> lines) { - beanGraph().getUnderlyingGraph().addEdge(null, element(), ((BeanVertex) testable).element(), "covers").setProperty("lines", lines); + BeanVertex testableVertex = ((BeanVertex) testable); + beanGraph().getUnderlyingGraph().addEdge(null, element(), testableVertex.element(), "covers").setProperty("lines", lines); } public TestPlan testPlan() { diff --git a/sonar-core/src/main/java/org/sonar/core/test/DefaultTestable.java b/sonar-core/src/main/java/org/sonar/core/test/DefaultTestable.java index 7a5db14987b..74a232fb4ad 100644 --- a/sonar-core/src/main/java/org/sonar/core/test/DefaultTestable.java +++ b/sonar-core/src/main/java/org/sonar/core/test/DefaultTestable.java @@ -54,6 +54,16 @@ public class DefaultTestable extends BeanVertex implements MutableTestable { return testCases; } + public int countTestCasesOfLine(int line) { + int number = 0; + for (Edge edge : getCovers()) { + if (Iterables.contains(testedLines(edge), Long.valueOf(line))) { + number++; + } + } + return number; + } + public Collection<TestCase> testCasesOfLine(int line) { ImmutableList.Builder<TestCase> cases = ImmutableList.builder(); for (Edge edge : getCovers()) { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/test/Testable.java b/sonar-plugin-api/src/main/java/org/sonar/api/test/Testable.java index 67522ea2135..78a96edcb14 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/test/Testable.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/test/Testable.java @@ -28,6 +28,8 @@ public interface Testable extends Perspective { Collection<TestCase> testCases(); + int countTestCasesOfLine(int line); + Collection<TestCase> testCasesOfLine(int line); SortedSet<Long> testedLines(); diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb index d70648b3c21..d8608ee50c3 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb @@ -195,7 +195,8 @@ class ResourceController < ApplicationController @hits_by_line.each_pair do |line_id, hits| line = @lines[line_id-1] if line - line.covered_lines = testable.testCasesOfLine(line_id).size if testable && testable.testCasesOfLine(line_id).size > 0 + line.covered_lines = 0 + line.covered_lines = testable.countTestCasesOfLine(line_id) if testable line.hits = hits.to_i line.conditions = @conditions_by_line[line_id].to_i line.covered_conditions = @covered_conditions_by_line[line_id].to_i diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/index.html.erb index c4366994cb4..7a36aa2ac67 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/index.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/index.html.erb @@ -99,7 +99,7 @@ <% if @display_coverage %> <% if line.highlighted? %> - <td class="ind <%= hits_status -%>"><%= line.covered_lines if line.covered_lines -%></td> + <td class="ind <%= hits_status -%>" title="<%= message("number_of_tests_covering_line", {:params => line.covered_lines.to_s}) if line.covered_lines > 0 -%>"><%= line.covered_lines if line.covered_lines > 0 -%></td> <td class="ind <%= conditions_status -%>"> <% if line.deprecated_conditions_label -%> <%= line.deprecated_conditions_label -%> |