aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-deprecated/src/test
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2014-10-02 23:09:52 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2014-10-02 23:09:52 +0200
commitee925d0a8d31556a37f98b6738e6f767b489e288 (patch)
tree28b2f547b2e8c55fcc469b051e0498979f39dcaa /sonar-deprecated/src/test
parent1b8bc4096ef135efe3bd303d4029536e825d37c8 (diff)
downloadsonarqube-ee925d0a8d31556a37f98b6738e6f767b489e288.tar.gz
sonarqube-ee925d0a8d31556a37f98b6738e6f767b489e288.zip
Code clean-up
* mark JFreechart as deprecated * complete some javadoc
Diffstat (limited to 'sonar-deprecated/src/test')
-rw-r--r--sonar-deprecated/src/test/java/org/sonar/api/charts/ChartParametersTest.java79
-rw-r--r--sonar-deprecated/src/test/java/org/sonar/api/checks/NoSonarFilterTest.java80
2 files changed, 159 insertions, 0 deletions
diff --git a/sonar-deprecated/src/test/java/org/sonar/api/charts/ChartParametersTest.java b/sonar-deprecated/src/test/java/org/sonar/api/charts/ChartParametersTest.java
new file mode 100644
index 00000000000..7ef39e3b730
--- /dev/null
+++ b/sonar-deprecated/src/test/java/org/sonar/api/charts/ChartParametersTest.java
@@ -0,0 +1,79 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.api.charts;
+
+import org.junit.Test;
+
+import java.util.Locale;
+
+import static org.junit.Assert.*;
+
+public class ChartParametersTest {
+ @Test
+ public void shouldForbidHighSizeForSecurityReasons() {
+ String url = ChartParameters.PARAM_WIDTH + "=100000&" + ChartParameters.PARAM_HEIGHT + "=9999999";
+ ChartParameters params = new ChartParameters(url);
+ assertEquals(ChartParameters.MAX_WIDTH, params.getWidth());
+ assertEquals(ChartParameters.MAX_HEIGHT, params.getHeight());
+ }
+
+ @Test
+ public void shouldReadImageSizeFromParameters() {
+ String url = ChartParameters.PARAM_WIDTH + "=200&" + ChartParameters.PARAM_HEIGHT + "=300";
+ ChartParameters params = new ChartParameters(url);
+ assertEquals(200, params.getWidth());
+ assertEquals(300, params.getHeight());
+ }
+
+ @Test
+ public void shouldGetDefaultSizesIfNoParameters() {
+ ChartParameters params = new ChartParameters("foo=bar");
+ assertEquals(ChartParameters.DEFAULT_WIDTH, params.getWidth());
+ assertEquals(ChartParameters.DEFAULT_HEIGHT, params.getHeight());
+ }
+
+ @Test
+ public void shouldDecodeValue() {
+ ChartParameters params = new ChartParameters("foo=0%3D10,3%3D8");
+ assertEquals("0=10,3=8", params.getValue("foo", "", true));
+ assertEquals("0%3D10,3%3D8", params.getValue("foo"));
+ assertNull(params.getValue("bar", null, true));
+ }
+
+ @Test
+ public void shouldDecodeValues() {
+ ChartParameters params = new ChartParameters("foo=0%3D10,3%3D8|5%3D5,7%3D17");
+ assertArrayEquals(new String[]{"0%3D10,3%3D8", "5%3D5,7%3D17"}, params.getValues("foo", "|"));
+ assertArrayEquals(new String[]{"0=10,3=8", "5=5,7=17"}, params.getValues("foo", "|", true));
+ assertArrayEquals(new String[0], params.getValues("bar", "|", true));
+ }
+
+ @Test
+ public void getLocale() {
+ ChartParameters params = new ChartParameters("foo=0&locale=fr");
+ assertEquals(Locale.FRENCH, params.getLocale());
+
+ params = new ChartParameters("foo=0&locale=fr-CH");
+ assertEquals("fr-ch", params.getLocale().getLanguage());
+
+ params = new ChartParameters("foo=0");
+ assertEquals(Locale.ENGLISH, params.getLocale());
+ }
+}
diff --git a/sonar-deprecated/src/test/java/org/sonar/api/checks/NoSonarFilterTest.java b/sonar-deprecated/src/test/java/org/sonar/api/checks/NoSonarFilterTest.java
new file mode 100644
index 00000000000..7f4793b77cd
--- /dev/null
+++ b/sonar-deprecated/src/test/java/org/sonar/api/checks/NoSonarFilterTest.java
@@ -0,0 +1,80 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.api.checks;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.batch.SensorContext;
+import org.sonar.api.resources.File;
+import org.sonar.api.rules.Rule;
+import org.sonar.api.rules.Violation;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class NoSonarFilterTest {
+
+ private SensorContext sensorContext = mock(SensorContext.class);
+ NoSonarFilter filter = new NoSonarFilter(sensorContext);
+ private File javaFile;
+
+ @Before
+ public void prepare() {
+ javaFile = new File("org.foo.Bar");
+ when(sensorContext.getResource(javaFile)).thenReturn(javaFile);
+ }
+
+ @Test
+ public void ignoreLinesCommentedWithNoSonar() {
+ Set<Integer> noSonarLines = new HashSet<Integer>();
+ noSonarLines.add(31);
+ noSonarLines.add(55);
+ filter.addResource(javaFile, noSonarLines);
+
+ // violation on class
+ assertThat(filter.isIgnored(new Violation(null, javaFile))).isFalse();
+
+ // violation on lines
+ assertThat(filter.isIgnored(new Violation(null, javaFile).setLineId(30))).isFalse();
+ assertThat(filter.isIgnored(new Violation(null, javaFile).setLineId(31))).isTrue();
+ }
+
+ @Test
+ public void doNotIgnoreWhenNotFoundInSquid() {
+ assertThat(filter.isIgnored(new Violation(null, javaFile).setLineId(30))).isFalse();
+ }
+
+ @Test
+ public void should_accept_violations_from_no_sonar_rules() throws Exception {
+ // The "No Sonar" rule logs violations on the lines that are flagged with "NOSONAR" !!
+
+ Set<Integer> noSonarLines = new HashSet<Integer>();
+ noSonarLines.add(31);
+ filter.addResource(javaFile, noSonarLines);
+
+ Rule noSonarRule = new Rule("squid", "NoSonarCheck");
+ assertThat(filter.isIgnored(new Violation(noSonarRule, javaFile).setLineId(31))).isFalse();
+
+ }
+}