aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api/src/test
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2015-07-22 09:10:50 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2015-07-22 09:10:50 +0200
commit255d7243980180740c6e4e276cc6413209921596 (patch)
tree9fa29844632ebe747e04ac284c9924a5f003dca0 /sonar-plugin-api/src/test
parent24d686a58de32655ab4a324b26075f6d226767a3 (diff)
downloadsonarqube-255d7243980180740c6e4e276cc6413209921596.tar.gz
sonarqube-255d7243980180740c6e4e276cc6413209921596.zip
Revert deletion of CountDistributionBuilder
Diffstat (limited to 'sonar-plugin-api/src/test')
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/measures/CountDistributionBuilderTest.java87
1 files changed, 87 insertions, 0 deletions
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/measures/CountDistributionBuilderTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/measures/CountDistributionBuilderTest.java
new file mode 100644
index 00000000000..2a832c77bce
--- /dev/null
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/measures/CountDistributionBuilderTest.java
@@ -0,0 +1,87 @@
+/*
+ * 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.measures;
+
+import org.junit.Test;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class CountDistributionBuilderTest {
+ @Test
+ public void buildDistribution() {
+ CountDistributionBuilder builder = new CountDistributionBuilder(CoreMetrics.CLASS_COMPLEXITY_DISTRIBUTION);
+ Measure measure = builder
+ .add("foo")
+ .add("bar")
+ .add("foo")
+ .add("hello")
+ .build();
+
+ assertThat(measure.getData(), is("bar=1;foo=2;hello=1"));
+ }
+
+ @Test
+ public void addZeroValues() {
+ CountDistributionBuilder builder = new CountDistributionBuilder(CoreMetrics.CLASS_COMPLEXITY_DISTRIBUTION);
+ Measure measure = builder
+ .addZero("foo")
+ .add("bar")
+ .add("foo")
+ .addZero("hello")
+ .build();
+
+ assertThat(measure.getData(), is("bar=1;foo=1;hello=0"));
+ }
+
+ @Test
+ public void addDistributionMeasureAsStrings() {
+ Measure measureToAdd = mock(Measure.class);
+ when(measureToAdd.getData()).thenReturn("foo=3;hello=5;none=0");
+
+ CountDistributionBuilder builder = new CountDistributionBuilder(CoreMetrics.CLASS_COMPLEXITY_DISTRIBUTION);
+ Measure measure = builder
+ .add("bar")
+ .add("foo")
+ .add(measureToAdd)
+ .build();
+
+ assertThat(measure.getData(), is("bar=1;foo=4;hello=5;none=0"));
+ }
+
+ @Test
+ public void intervalsAreSorted() {
+ Measure measureToAdd = mock(Measure.class);
+ when(measureToAdd.getData()).thenReturn("10=5;3=2;1=3");
+
+ CountDistributionBuilder builder = new CountDistributionBuilder(CoreMetrics.CLASS_COMPLEXITY_DISTRIBUTION);
+ Measure measure = builder
+ .add(10)
+ .add(measureToAdd)
+ .add(1)
+ .build();
+
+ assertThat(measure.getData(), is("1=4;3=2;10=6"));
+ }
+
+}