summaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api/src/test
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2015-02-16 18:31:16 +0100
committerJulien HENRY <julien.henry@sonarsource.com>2015-02-16 18:32:32 +0100
commit85877295a7db169742f56bc6c44b883267923cf7 (patch)
tree60d502f4b3673c7295d2dd3961f38bdff1abb916 /sonar-plugin-api/src/test
parent2660b61c7d0c0aee191ab719bf672f7902e78c5e (diff)
downloadsonarqube-85877295a7db169742f56bc6c44b883267923cf7.tar.gz
sonarqube-85877295a7db169742f56bc6c44b883267923cf7.zip
SONAR-6000 Try to decrease size of duplications in persistit
Diffstat (limited to 'sonar-plugin-api/src/test')
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/duplication/DuplicationGroupTest.java62
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/duplication/DuplicationTest.java43
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/duplication/internal/DefaultDuplicationBuilderTest.java52
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/duplication/internal/DefaultDuplicationTest.java72
4 files changed, 115 insertions, 114 deletions
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/duplication/DuplicationGroupTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/duplication/DuplicationGroupTest.java
deleted file mode 100644
index 1d969645fbb..00000000000
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/duplication/DuplicationGroupTest.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * 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.batch.sensor.duplication;
-
-import org.junit.Test;
-
-import java.util.Arrays;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class DuplicationGroupTest {
-
- @Test
- public void testBlockEqualsAndCo() {
- DuplicationGroup.Block b1 = new DuplicationGroup.Block("foo", 1, 10);
- DuplicationGroup.Block b2 = new DuplicationGroup.Block("foo", 1, 10);
- assertThat(b1).isEqualTo(b1);
- assertThat(b1).isEqualTo(b2);
- assertThat(b1).isNotEqualTo("");
- assertThat(b1).isNotEqualTo(new DuplicationGroup.Block("foo1", 1, 10));
- assertThat(b1).isNotEqualTo(new DuplicationGroup.Block("foo", 2, 10));
- assertThat(b1).isNotEqualTo(new DuplicationGroup.Block("foo", 1, 11));
-
- assertThat(b1.hashCode()).isEqualTo(188843970);
- assertThat(b1.toString()).isEqualTo("DuplicationGroup.Block[resourceKey=foo,startLine=1,length=10]");
- }
-
- @Test
- public void testDuplicationGroupEqualsAndCo() {
- DuplicationGroup d1 = new DuplicationGroup(new DuplicationGroup.Block("foo", 1, 10));
- d1.setDuplicates(Arrays.asList(new DuplicationGroup.Block("foo", 20, 10), new DuplicationGroup.Block("foo2", 1, 10)));
- DuplicationGroup d2 = new DuplicationGroup(new DuplicationGroup.Block("foo", 1, 10));
- d2.setDuplicates(Arrays.asList(new DuplicationGroup.Block("foo", 20, 10), new DuplicationGroup.Block("foo2", 1, 10)));
- assertThat(d1).isEqualTo(d1);
- assertThat(d1).isEqualTo(d2);
- assertThat(d1).isNotEqualTo("");
- assertThat(d1).isNotEqualTo(new DuplicationGroup(new DuplicationGroup.Block("foo", 1, 10)));
-
- assertThat(d1.hashCode()).isEqualTo(578909124);
- assertThat(d1.toString()).contains("origin=DuplicationGroup.Block[resourceKey=foo,startLine=1,length=10]");
- assertThat(d1.toString()).contains(
- "duplicates=[DuplicationGroup.Block[resourceKey=foo,startLine=20,length=10], DuplicationGroup.Block[resourceKey=foo2,startLine=1,length=10]]");
- }
-
-}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/duplication/DuplicationTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/duplication/DuplicationTest.java
new file mode 100644
index 00000000000..45b5346130c
--- /dev/null
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/duplication/DuplicationTest.java
@@ -0,0 +1,43 @@
+/*
+ * 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.batch.sensor.duplication;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class DuplicationTest {
+
+ @Test
+ public void testBlockEqualsAndCo() {
+ Duplication.Block b1 = new Duplication.Block("foo", 1, 10);
+ Duplication.Block b2 = new Duplication.Block("foo", 1, 10);
+ assertThat(b1).isEqualTo(b1);
+ assertThat(b1).isEqualTo(b2);
+ assertThat(b1).isNotEqualTo("");
+ assertThat(b1).isNotEqualTo(new Duplication.Block("foo1", 1, 10));
+ assertThat(b1).isNotEqualTo(new Duplication.Block("foo", 2, 10));
+ assertThat(b1).isNotEqualTo(new Duplication.Block("foo", 1, 11));
+
+ assertThat(b1.hashCode()).isEqualTo(188843970);
+ assertThat(b1.toString()).isEqualTo("Duplication.Block[resourceKey=foo,startLine=1,length=10]");
+ }
+
+}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/duplication/internal/DefaultDuplicationBuilderTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/duplication/internal/DefaultDuplicationBuilderTest.java
deleted file mode 100644
index dd3f3989095..00000000000
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/duplication/internal/DefaultDuplicationBuilderTest.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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.batch.sensor.duplication.internal;
-
-import org.junit.Test;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.batch.sensor.duplication.DuplicationGroup;
-import org.sonar.api.batch.sensor.duplication.DuplicationGroup.Block;
-
-import java.util.List;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class DefaultDuplicationBuilderTest {
-
- @Test
- public void test() {
- DefaultDuplicationBuilder builder = new DefaultDuplicationBuilder(new DefaultInputFile("foo", "foo.php"));
-
- List<DuplicationGroup> duplicationGroup = builder.originBlock(1, 11)
- .isDuplicatedBy(new DefaultInputFile("foo", "foo.php"), 40, 50)
- .isDuplicatedBy(new DefaultInputFile("foo", "foo2.php"), 1, 10)
- .originBlock(20, 30)
- .isDuplicatedBy(new DefaultInputFile("foo", "foo3.php"), 30, 40)
- .build();
-
- assertThat(duplicationGroup).hasSize(2);
- Block originBlock = duplicationGroup.get(0).originBlock();
- assertThat(originBlock.resourceKey()).isEqualTo("foo:foo.php");
- assertThat(originBlock.startLine()).isEqualTo(1);
- assertThat(originBlock.length()).isEqualTo(11);
- assertThat(duplicationGroup.get(0).duplicates()).hasSize(2);
- }
-
-}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/duplication/internal/DefaultDuplicationTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/duplication/internal/DefaultDuplicationTest.java
new file mode 100644
index 00000000000..efee043ee98
--- /dev/null
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/duplication/internal/DefaultDuplicationTest.java
@@ -0,0 +1,72 @@
+/*
+ * 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.batch.sensor.duplication.internal;
+
+import org.junit.Test;
+import org.sonar.api.batch.fs.internal.DefaultInputFile;
+import org.sonar.api.batch.sensor.duplication.Duplication.Block;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class DefaultDuplicationTest {
+
+ @Test
+ public void testDuplicationEqualsAndCo() {
+ DefaultInputFile file1 = new DefaultInputFile("foo", "bar.txt").setLines(50);
+ DefaultInputFile file2 = new DefaultInputFile("foo", "bar2.txt").setLines(50);
+ DefaultDuplication d1 = new DefaultDuplication()
+ .originBlock(file1, 1, 10)
+ .isDuplicatedBy(file1, 20, 29)
+ .isDuplicatedBy(file2, 1, 10);
+ DefaultDuplication d2 = new DefaultDuplication()
+ .originBlock(file1, 1, 10)
+ .isDuplicatedBy(file1, 20, 29)
+ .isDuplicatedBy(file2, 1, 10);
+ DefaultDuplication d3 = new DefaultDuplication()
+ .originBlock(file1, 1, 10);
+ assertThat(d1).isEqualTo(d1);
+ assertThat(d1).isEqualTo(d2);
+ assertThat(d1).isNotEqualTo("");
+ assertThat(d1).isNotEqualTo(d3);
+
+ assertThat(d1.hashCode()).isNotNull();
+ assertThat(d1.toString()).contains("origin=Duplication.Block[resourceKey=foo:bar.txt,startLine=1,length=10]");
+ assertThat(d1.toString()).contains(
+ "duplicates=[Duplication.Block[resourceKey=foo:bar.txt,startLine=20,length=10], Duplication.Block[resourceKey=foo:bar2.txt,startLine=1,length=10]]");
+ }
+
+ @Test
+ public void test() {
+
+ DefaultInputFile file1 = new DefaultInputFile("foo", "foo.php").setLines(50);
+ DefaultInputFile file2 = new DefaultInputFile("foo", "foo2.php").setLines(50);
+
+ DefaultDuplication dup = new DefaultDuplication().originBlock(file1, 1, 11)
+ .isDuplicatedBy(file1, 40, 50)
+ .isDuplicatedBy(file2, 1, 10);
+
+ Block originBlock = dup.originBlock();
+ assertThat(originBlock.resourceKey()).isEqualTo("foo:foo.php");
+ assertThat(originBlock.startLine()).isEqualTo(1);
+ assertThat(originBlock.length()).isEqualTo(11);
+ assertThat(dup.duplicates()).hasSize(2);
+ }
+
+}