--- /dev/null
+/*
+ * 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.fs.internal;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.io.File;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class DefaultInputDirTest {
+
+ @Rule
+ public TemporaryFolder temp = new TemporaryFolder();
+
+ @Test
+ public void test() throws Exception {
+ File dir = temp.newFolder("src");
+ DefaultInputDir inputDir = new DefaultInputDir("src")
+ .setFile(dir)
+ .setKey("ABCDE");
+
+ assertThat(inputDir.key()).isEqualTo("ABCDE");
+ assertThat(inputDir.file().getAbsolutePath()).isEqualTo(dir.getAbsolutePath());
+ assertThat(inputDir.relativePath()).isEqualTo("src");
+ assertThat(new File(inputDir.relativePath())).isRelative();
+ assertThat(inputDir.absolutePath()).endsWith("src");
+ assertThat(new File(inputDir.absolutePath())).isAbsolute();
+ }
+
+ @Test
+ public void testEqualsAndHashCode() throws Exception {
+ File dir1 = temp.newFolder("src");
+ DefaultInputDir inputDir1 = new DefaultInputDir("src")
+ .setFile(dir1)
+ .setKey("ABCDE");
+
+ File dir2 = temp.newFolder("src2");
+ DefaultInputDir inputDir2 = new DefaultInputDir("src")
+ .setFile(dir2)
+ .setKey("ABCDE");
+
+ assertThat(inputDir1.equals(inputDir1)).isTrue();
+ assertThat(inputDir1.equals(inputDir2)).isTrue();
+ assertThat(inputDir1.equals("foo")).isFalse();
+
+ assertThat(inputDir1.hashCode()).isEqualTo(114148);
+
+ assertThat(inputDir1.toString()).contains("[relative=src, abs=");
+
+ }
+
+}
--- /dev/null
+/*
+ * 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 java.util.List;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class DefaultDuplicationBuilderTest {
+
+ @Test
+ public void test() {
+ DefaultDuplicationBuilder builder = new DefaultDuplicationBuilder(new DefaultInputFile("foo.php").setKey("foo:foo.php"));
+
+ List<DuplicationGroup> duplicationGroup = builder.originBlock(1, 11)
+ .isDuplicatedBy(new DefaultInputFile("foo.php"), 40, 50)
+ .isDuplicatedBy(new DefaultInputFile("foo2.php"), 1, 10)
+ .originBlock(20, 30)
+ .isDuplicatedBy(new DefaultInputFile("foo3.php"), 30, 40)
+ .build();
+
+ assertThat(duplicationGroup).hasSize(2);
+ assertThat(duplicationGroup.get(0).originBlock().resourceKey()).isEqualTo("foo:foo.php");
+ assertThat(duplicationGroup.get(0).originBlock().startLine()).isEqualTo(1);
+ assertThat(duplicationGroup.get(0).originBlock().length()).isEqualTo(11);
+ assertThat(duplicationGroup.get(0).duplicates()).hasSize(2);
+ }
+
+}