From b8a10bff3b6ba19648a6d199390235157db2989b Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Tue, 4 Dec 2012 14:55:16 +0100 Subject: [PATCH] Add unit tests to widgets --- .../core/widgets/MeasureFilterListWidget.java | 2 +- .../plugins/core/widgets/TreemapWidget.java | 2 +- .../plugins/core/widgets/welcome.html.erb | 10 +--- .../core/filters/MyFavouritesFilterTest.java | 6 +++ .../core/filters/ProjectFilterTest.java | 8 +++- .../core/widgets/CoverageWidgetTest.java | 9 +++- .../core/widgets/ItCoverageWidgetTest.java | 10 +++- .../core/widgets/TreemapWidgetTest.java | 46 +++++++++++++++++++ .../core/widgets/WelcomeWidgetTest.java | 46 +++++++++++++++++++ 9 files changed, 123 insertions(+), 16 deletions(-) create mode 100644 plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/TreemapWidgetTest.java create mode 100644 plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/WelcomeWidgetTest.java diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/MeasureFilterListWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/MeasureFilterListWidget.java index 15ac89497cc..2c4615362e7 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/MeasureFilterListWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/MeasureFilterListWidget.java @@ -33,7 +33,7 @@ import static org.sonar.api.web.WidgetScope.GLOBAL; @WidgetScope(GLOBAL) @WidgetProperties({ @WidgetProperty(key = MeasureFilterListWidget.FILTER_PROPERTY, type = WidgetPropertyType.FILTER, optional = false), - @WidgetProperty(key = MeasureFilterListWidget.PAGE_SIZE_PROPERTY, type = WidgetPropertyType.INTEGER, optional = true) + @WidgetProperty(key = MeasureFilterListWidget.PAGE_SIZE_PROPERTY, type = WidgetPropertyType.INTEGER, defaultValue = "30") } ) public class MeasureFilterListWidget extends AbstractRubyTemplate implements RubyRailsWidget { diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TreemapWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TreemapWidget.java index 5ac71e2f661..79d44b52137 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TreemapWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TreemapWidget.java @@ -34,7 +34,7 @@ public class TreemapWidget extends AbstractRubyTemplate implements RubyRailsWidg } public String getTitle() { - return "Treemap of components"; + return "Treemap of Components"; } @Override diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/welcome.html.erb b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/welcome.html.erb index e97c37e8b77..a3e651d4f03 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/welcome.html.erb +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/welcome.html.erb @@ -1,9 +1 @@ -

Welcome to Sonar Dashboard

-

Since you are able to read this, it means that you have successfully started your Sonar server. Well done!

-

If you have not removed this text, it also means that you have not yet played much with Sonar. So here are a few pointers for your next step:

- \ No newline at end of file +<%= message('widget.welcome.html') -%> \ No newline at end of file diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/filters/MyFavouritesFilterTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/filters/MyFavouritesFilterTest.java index 78ceaf77c70..e9faed66f21 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/filters/MyFavouritesFilterTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/filters/MyFavouritesFilterTest.java @@ -21,6 +21,7 @@ package org.sonar.plugins.core.filters; import org.junit.Test; import org.sonar.api.web.Filter; +import org.sonar.plugins.core.CorePlugin; import static org.fest.assertions.Assertions.assertThat; @@ -37,4 +38,9 @@ public class MyFavouritesFilterTest { assertThat(filter.getCriteria()).isEmpty(); assertThat(filter.getColumns()).hasSize(3); } + + @Test + public void should_be_registered_as_an_extension() { + assertThat(new CorePlugin().getExtensions()).contains(MyFavouritesFilter.class); + } } diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/filters/ProjectFilterTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/filters/ProjectFilterTest.java index e918d19f36a..32d46c9455f 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/filters/ProjectFilterTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/filters/ProjectFilterTest.java @@ -21,6 +21,7 @@ package org.sonar.plugins.core.filters; import org.junit.Test; import org.sonar.api.web.Filter; +import org.sonar.plugins.core.CorePlugin; import static org.fest.assertions.Assertions.assertThat; @@ -28,7 +29,7 @@ public class ProjectFilterTest { @Test public void should_create_filter() { ProjectFilter template = new ProjectFilter(); - + Filter filter = template.createFilter(); assertThat(template.getName()).isEqualTo("Projects"); @@ -36,4 +37,9 @@ public class ProjectFilterTest { assertThat(filter.getCriteria()).hasSize(1); assertThat(filter.getColumns()).hasSize(7); } + + @Test + public void should_be_registered_as_an_extension() { + assertThat(new CorePlugin().getExtensions()).contains(ProjectFilter.class); + } } 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 index 8caa30430c0..5c666d2d58b 100644 --- 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 @@ -20,6 +20,7 @@ package org.sonar.plugins.core.widgets; import org.junit.Test; +import org.sonar.plugins.core.CorePlugin; import static org.fest.assertions.Assertions.assertThat; @@ -33,9 +34,13 @@ public class CoverageWidgetTest { } @Test - public void should_use_relative_path_for_template() { + public void should_find_template() { CoverageWidget widget = new CoverageWidget(); + assertThat(WelcomeWidget.class.getResource(widget.getTemplatePath())).isNotNull(); + } - assertThat(widget.getTemplatePath()).startsWith("/"); + @Test + public void should_be_registered_as_an_extension() { + assertThat(new CorePlugin().getExtensions()).contains(CoverageWidget.class); } } 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 index 7bf32fea1d2..ffde53f41a8 100644 --- 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 @@ -19,7 +19,9 @@ */ package org.sonar.plugins.core.widgets; +import com.google.common.io.Resources; import org.junit.Test; +import org.sonar.plugins.core.CorePlugin; import static org.fest.assertions.Assertions.assertThat; @@ -33,9 +35,13 @@ public class ItCoverageWidgetTest { } @Test - public void should_use_relative_path_for_template() { + public void should_find_template() { ItCoverageWidget widget = new ItCoverageWidget(); + assertThat(ItCoverageWidget.class.getResource(widget.getTemplatePath())).isNotNull(); + } - assertThat(widget.getTemplatePath()).startsWith("/"); + @Test + public void should_be_registered_as_an_extension() { + assertThat(new CorePlugin().getExtensions()).contains(ItCoverageWidget.class); } } diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/TreemapWidgetTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/TreemapWidgetTest.java new file mode 100644 index 00000000000..5337fae9fd0 --- /dev/null +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/TreemapWidgetTest.java @@ -0,0 +1,46 @@ +/* + * 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 org.sonar.plugins.core.CorePlugin; + +import static org.fest.assertions.Assertions.assertThat; + +public class TreemapWidgetTest { + @Test + public void should_define_widget() { + TreemapWidget widget = new TreemapWidget(); + + assertThat(widget.getId()).isEqualTo("treemap-widget"); + assertThat(widget.getTitle()).isEqualTo("Treemap of Components"); + } + + @Test + public void should_find_template() { + TreemapWidget widget = new TreemapWidget(); + assertThat(WelcomeWidget.class.getResource(widget.getTemplatePath())).isNotNull(); + } + + @Test + public void should_be_registered_as_an_extension() { + assertThat(new CorePlugin().getExtensions()).contains(TreemapWidget.class); + } +} diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/WelcomeWidgetTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/WelcomeWidgetTest.java new file mode 100644 index 00000000000..dbe5d45e85e --- /dev/null +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/WelcomeWidgetTest.java @@ -0,0 +1,46 @@ +/* + * 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 org.sonar.plugins.core.CorePlugin; + +import static org.fest.assertions.Assertions.assertThat; + +public class WelcomeWidgetTest { + @Test + public void should_define_widget() { + WelcomeWidget widget = new WelcomeWidget(); + + assertThat(widget.getId()).isEqualTo("welcome"); + assertThat(widget.getTitle()).isEqualTo("Welcome"); + } + + @Test + public void should_find_template() { + WelcomeWidget widget = new WelcomeWidget(); + assertThat(WelcomeWidget.class.getResource(widget.getTemplatePath())).isNotNull(); + } + + @Test + public void should_be_registered_as_an_extension() { + assertThat(new CorePlugin().getExtensions()).contains(WelcomeWidget.class); + } +} -- 2.39.5