diff options
author | Fabrice Bellingard <bellingard@gmail.com> | 2012-04-02 12:09:03 +0200 |
---|---|---|
committer | Fabrice Bellingard <bellingard@gmail.com> | 2012-04-02 12:09:03 +0200 |
commit | 21fd3dd8ad5bb8868edc53c9b53bf30be8b2d748 (patch) | |
tree | 07a38a61766f6873e427d94d365a9ab6543a7e23 | |
parent | 3293e19f266b1ef48d6ffe4f4116be08d0603c1f (diff) | |
download | sonarqube-21fd3dd8ad5bb8868edc53c9b53bf30be8b2d748.tar.gz sonarqube-21fd3dd8ad5bb8868edc53c9b53bf30be8b2d748.zip |
Fix violation and refactoring
2 files changed, 71 insertions, 18 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/TimeMachineDashboard.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/TimeMachineDashboard.java index e57df8edb6f..257e17abe8f 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/TimeMachineDashboard.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/TimeMachineDashboard.java @@ -31,8 +31,6 @@ import org.sonar.api.web.DashboardTemplate; */ public final class TimeMachineDashboard extends DashboardTemplate { - private static final String TIME_MACHINE_ID = "time_machine"; - private static final String DISPLAY_SPARK_LINE = "displaySparkLine"; private static final String METRIC1 = "metric1"; private static final String METRIC2 = "metric2"; private static final String METRIC3 = "metric3"; @@ -60,9 +58,8 @@ public final class TimeMachineDashboard extends DashboardTemplate { timelineWidget.setProperty(METRIC1, "complexity"); timelineWidget.setProperty(METRIC2, "violations_density"); timelineWidget.setProperty(METRIC3, "coverage"); - - Widget sizeTimeMachineWidget = dashboard.addWidget(TIME_MACHINE_ID, 1); - sizeTimeMachineWidget.setProperty(DISPLAY_SPARK_LINE, "true"); + + Widget sizeTimeMachineWidget = addTimeMachineWidgetOnFirstColumn(dashboard); sizeTimeMachineWidget.setProperty(METRIC1, "ncloc"); sizeTimeMachineWidget.setProperty(METRIC2, "lines"); sizeTimeMachineWidget.setProperty(METRIC3, "statements"); @@ -70,16 +67,14 @@ public final class TimeMachineDashboard extends DashboardTemplate { sizeTimeMachineWidget.setProperty(METRIC5, "classes"); sizeTimeMachineWidget.setProperty(METRIC6, "functions"); sizeTimeMachineWidget.setProperty(METRIC7, "accessors"); - - Widget commentsTimeMachineWidget = dashboard.addWidget(TIME_MACHINE_ID, 1); - commentsTimeMachineWidget.setProperty(DISPLAY_SPARK_LINE, "true"); + + Widget commentsTimeMachineWidget = addTimeMachineWidgetOnFirstColumn(dashboard); commentsTimeMachineWidget.setProperty(METRIC1, "comment_lines_density"); commentsTimeMachineWidget.setProperty(METRIC2, "comment_lines"); commentsTimeMachineWidget.setProperty(METRIC3, "public_documented_api_density"); commentsTimeMachineWidget.setProperty(METRIC4, "public_undocumented_api"); - - Widget duplicationTimeMachineWidget = dashboard.addWidget(TIME_MACHINE_ID, 1); - duplicationTimeMachineWidget.setProperty(DISPLAY_SPARK_LINE, "true"); + + Widget duplicationTimeMachineWidget = addTimeMachineWidgetOnFirstColumn(dashboard); duplicationTimeMachineWidget.setProperty(METRIC1, "duplicated_lines_density"); duplicationTimeMachineWidget.setProperty(METRIC2, "duplicated_lines"); duplicationTimeMachineWidget.setProperty(METRIC3, "duplicated_blocks"); @@ -87,8 +82,7 @@ public final class TimeMachineDashboard extends DashboardTemplate { } private void addSecondColumn(Dashboard dashboard) { - Widget rulesTimeMachineWidget = dashboard.addWidget(TIME_MACHINE_ID, 2); - rulesTimeMachineWidget.setProperty(DISPLAY_SPARK_LINE, "true"); + Widget rulesTimeMachineWidget = addTimeMachineWidgetOnSecondColumn(dashboard); rulesTimeMachineWidget.setProperty(METRIC1, "violations"); rulesTimeMachineWidget.setProperty(METRIC2, "violation_density"); rulesTimeMachineWidget.setProperty(METRIC3, "blocker_violations"); @@ -98,15 +92,13 @@ public final class TimeMachineDashboard extends DashboardTemplate { rulesTimeMachineWidget.setProperty(METRIC7, "info_violations"); rulesTimeMachineWidget.setProperty(METRIC7, "weighted_violations"); - Widget complexityTimeMachineWidget = dashboard.addWidget(TIME_MACHINE_ID, 2); - complexityTimeMachineWidget.setProperty(DISPLAY_SPARK_LINE, "true"); + Widget complexityTimeMachineWidget = addTimeMachineWidgetOnSecondColumn(dashboard); complexityTimeMachineWidget.setProperty(METRIC1, "complexity"); complexityTimeMachineWidget.setProperty(METRIC2, "function_complexity"); complexityTimeMachineWidget.setProperty(METRIC3, "class_complexity"); complexityTimeMachineWidget.setProperty(METRIC4, "file_complexity"); - Widget testsTimeMachineWidget = dashboard.addWidget(TIME_MACHINE_ID, 2); - testsTimeMachineWidget.setProperty(DISPLAY_SPARK_LINE, "true"); + Widget testsTimeMachineWidget = addTimeMachineWidgetOnSecondColumn(dashboard); testsTimeMachineWidget.setProperty(METRIC1, "coverage"); testsTimeMachineWidget.setProperty(METRIC2, "line_coverage"); testsTimeMachineWidget.setProperty(METRIC3, "branch_coverage"); @@ -117,4 +109,18 @@ public final class TimeMachineDashboard extends DashboardTemplate { testsTimeMachineWidget.setProperty(METRIC7, "test_execution_time"); } -}
\ No newline at end of file + private Widget addTimeMachineWidgetOnFirstColumn(Dashboard dashboard) { + return addTimeMachineWidget(dashboard, 1); + } + + private Widget addTimeMachineWidgetOnSecondColumn(Dashboard dashboard) { + return addTimeMachineWidget(dashboard, 2); + } + + private Widget addTimeMachineWidget(Dashboard dashboard, int columnIndex) { + Widget widget = dashboard.addWidget("time_machine", columnIndex); + widget.setProperty("displaySparkLine", "true"); + return widget; + } + +} diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/TimeMachineDashboardTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/TimeMachineDashboardTest.java new file mode 100644 index 00000000000..59463ce21f3 --- /dev/null +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/TimeMachineDashboardTest.java @@ -0,0 +1,47 @@ +/* + * 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.dashboards; + +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +import java.util.Collection; + +import org.junit.Test; +import org.sonar.api.web.Dashboard; +import org.sonar.api.web.Dashboard.Widget; +import org.sonar.api.web.DashboardLayout; + +public class TimeMachineDashboardTest { + @Test + public void shouldCreateDashboard() { + TimeMachineDashboard template = new TimeMachineDashboard(); + Dashboard hotspots = template.createDashboard(); + assertThat(template.getName(), is("TimeMachine")); + assertThat(hotspots.getLayout(), is(DashboardLayout.TWO_COLUMNS)); + Collection<Widget> widgets = hotspots.getWidgets(); + assertThat(widgets.size(), is(7)); + for (Widget widget : widgets) { + if (widget.getId().equals("time_machine")) { + assertThat(widget.getProperty("displaySparkLine"), is("true")); + } + } + } +} |