diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2015-12-01 11:26:45 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2015-12-01 16:38:08 +0100 |
commit | a70899910e2448abda0ec8c76aff2000318dce49 (patch) | |
tree | 7db055f0637463ed6a9ab32dbbef100632ae0cef /sonar-plugin-api/src | |
parent | ba7e2918528cba02496907a81d730079953c28ce (diff) | |
download | sonarqube-a70899910e2448abda0ec8c76aff2000318dce49.tar.gz sonarqube-a70899910e2448abda0ec8c76aff2000318dce49.zip |
SONAR-6933 Drop newDuplication() beta API
Diffstat (limited to 'sonar-plugin-api/src')
11 files changed, 6 insertions, 516 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java index 87a98418dff..0ae851463ce 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java @@ -20,12 +20,11 @@ package org.sonar.api.batch.sensor; import com.google.common.annotations.Beta; +import java.io.Serializable; import org.sonar.api.batch.AnalysisMode; -import org.sonar.api.batch.CpdMapping; import org.sonar.api.batch.fs.FileSystem; import org.sonar.api.batch.rule.ActiveRules; import org.sonar.api.batch.sensor.coverage.NewCoverage; -import org.sonar.api.batch.sensor.duplication.NewDuplication; import org.sonar.api.batch.sensor.highlighting.NewHighlighting; import org.sonar.api.batch.sensor.internal.SensorContextTester; import org.sonar.api.batch.sensor.issue.Issue; @@ -34,8 +33,6 @@ import org.sonar.api.batch.sensor.measure.Measure; import org.sonar.api.batch.sensor.measure.NewMeasure; import org.sonar.api.config.Settings; -import java.io.Serializable; - /** * See {@link Sensor#execute(SensorContext)} * In order to write unit tests you can use {@link SensorContextTester} @@ -89,14 +86,6 @@ public interface SensorContext { // TODO - // ------------ DUPLICATIONS ------------ - - /** - * Builder to manually register duplication in a file. This can be used in addition to {@link CpdMapping} extension point. - * Don't forget to call {@link NewDuplication#save()}. - */ - NewDuplication newDuplication(); - // ------------ TESTS ------------ /** diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/duplication/Duplication.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/duplication/Duplication.java deleted file mode 100644 index e445d5ce498..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/duplication/Duplication.java +++ /dev/null @@ -1,106 +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 com.google.common.annotations.Beta; -import org.apache.commons.lang.builder.EqualsBuilder; -import org.apache.commons.lang.builder.HashCodeBuilder; -import org.apache.commons.lang.builder.ToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; -import org.sonar.api.batch.sensor.SensorContext; - -import java.util.List; - -/** - * <p/> - * A {@link Duplication} is a list of duplicated {@link Block}s. One block - * is considered as the original code and all others are duplicates. - * Use {@link SensorContext#newDuplication()} to manually create a duplication. Use {@link SensorContext#duplicationTokenBuilder(org.sonar.api.batch.fs.InputFile)} - * to feed tokens and let the core compute duplications. - * @since 5.1 - */ -@Beta -public interface Duplication { - - class Block { - private final String resourceKey; - private final int startLine; - private final int length; - - public Block(String resourceKey, int startLine, int length) { - this.resourceKey = resourceKey; - this.startLine = startLine; - this.length = length; - } - - public String resourceKey() { - return resourceKey; - } - - public int startLine() { - return startLine; - } - - public int length() { - return length; - } - - // Just for unit tests - @Override - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (obj == this) { - return true; - } - if (obj.getClass() != getClass()) { - return false; - } - Block rhs = (Block) obj; - return new EqualsBuilder() - .append(resourceKey, rhs.resourceKey) - .append(startLine, rhs.startLine) - .append(length, rhs.length).isEquals(); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(13, 43) - .append(resourceKey) - .append(startLine) - .append(length).toHashCode(); - } - - @Override - public String toString() { - return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE). - append("resourceKey", resourceKey). - append("startLine", startLine). - append("length", length). - toString(); - } - } - - Block originBlock(); - - List<Block> duplicates(); - -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/duplication/NewDuplication.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/duplication/NewDuplication.java deleted file mode 100644 index d4d06ba600f..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/duplication/NewDuplication.java +++ /dev/null @@ -1,56 +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 com.google.common.annotations.Beta; -import org.sonar.api.batch.fs.InputFile; - -/** - * <p/> - * This builder is used to declare duplications on files of the project. - * Usage: - * <code><pre> - * context.newDuplication(); - * .originBlock(inputFile, 2, 10) - * .isDuplicatedBy(inputFile, 14, 22) - * .isDuplicatedBy(anotherInputFile, 3, 11) - * .save(); - * </pre></code> - * @since 5.1 - */ -@Beta -public interface NewDuplication { - - /** - * Declare duplication origin block. Then call {@link #isDuplicatedBy(InputFile, int, int)} to reference all duplicates of this block. - */ - NewDuplication originBlock(InputFile originFile, int startLine, int endLine); - - /** - * Declare duplicate block of the previously declared {@link #originBlock(int, int)}. Can be called several times. - * @param sameOrOtherFile duplicate can be in the same file or in another file. - */ - NewDuplication isDuplicatedBy(InputFile sameOrOtherFile, int startLine, int endLine); - - /** - * Save the duplication. - */ - void save(); -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/duplication/internal/DefaultDuplication.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/duplication/internal/DefaultDuplication.java deleted file mode 100644 index 6c00e8ba33a..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/duplication/internal/DefaultDuplication.java +++ /dev/null @@ -1,145 +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.sonar.api.batch.sensor.internal.SensorStorage; - -import com.google.common.base.Preconditions; -import org.apache.commons.lang.builder.EqualsBuilder; -import org.apache.commons.lang.builder.HashCodeBuilder; -import org.apache.commons.lang.builder.ToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.batch.sensor.duplication.Duplication; -import org.sonar.api.batch.sensor.duplication.NewDuplication; -import org.sonar.api.batch.sensor.internal.DefaultStorable; - -import javax.annotation.Nullable; - -import java.util.LinkedList; -import java.util.List; - -public class DefaultDuplication extends DefaultStorable implements NewDuplication, Duplication { - - private Block originBlock; - private List<Block> duplicates = new LinkedList<>(); - - public DefaultDuplication() { - super(); - } - - public DefaultDuplication(@Nullable SensorStorage storage) { - super(storage); - } - - @Override - public DefaultDuplication originBlock(InputFile inputFile, int startLine, int endLine) { - Preconditions.checkArgument(inputFile != null, "InputFile can't be null"); - validateLineArgument(inputFile, startLine, "startLine"); - validateLineArgument(inputFile, endLine, "endLine"); - originBlock = new Duplication.Block(((DefaultInputFile) inputFile).key(), startLine, endLine - startLine + 1); - return this; - } - - @Override - public DefaultDuplication isDuplicatedBy(InputFile sameOrOtherFile, int startLine, int endLine) { - Preconditions.checkArgument(sameOrOtherFile != null, "InputFile can't be null"); - validateLineArgument(sameOrOtherFile, startLine, "startLine"); - validateLineArgument(sameOrOtherFile, endLine, "endLine"); - return isDuplicatedBy(((DefaultInputFile) sameOrOtherFile).key(), startLine, endLine); - } - - /** - * For internal use. Global duplications are referencing files outside of current project so - * no way to manipulate an InputFile. - */ - public DefaultDuplication isDuplicatedBy(String fileKey, int startLine, int endLine) { - Preconditions.checkNotNull(originBlock, "Call originBlock() first"); - duplicates.add(new Duplication.Block(fileKey, startLine, endLine - startLine + 1)); - return this; - } - - @Override - public void doSave() { - Preconditions.checkNotNull(originBlock, "Call originBlock() first"); - Preconditions.checkState(!duplicates.isEmpty(), "No duplicates. Call isDuplicatedBy()"); - storage.store(this); - } - - @Override - public Block originBlock() { - return originBlock; - } - - public DefaultDuplication setOriginBlock(Block originBlock) { - this.originBlock = originBlock; - return this; - } - - @Override - public List<Block> duplicates() { - return duplicates; - } - - // Just for unit tests - @Override - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (obj == this) { - return true; - } - if (obj.getClass() != getClass()) { - return false; - } - DefaultDuplication rhs = (DefaultDuplication) obj; - EqualsBuilder equalsBuilder = new EqualsBuilder() - .append(originBlock, rhs.originBlock) - .append(duplicates.size(), rhs.duplicates.size()); - if (duplicates.size() == rhs.duplicates.size()) { - for (int i = 0; i < duplicates.size(); i++) { - equalsBuilder.append(duplicates.get(i), rhs.duplicates.get(i)); - } - } - return equalsBuilder.isEquals(); - } - - @Override - public int hashCode() { - HashCodeBuilder hcBuilder = new HashCodeBuilder(17, 37) - .append(originBlock) - .append(duplicates.size()); - for (int i = 0; i < duplicates.size(); i++) { - hcBuilder.append(duplicates.get(i)); - } - return hcBuilder.toHashCode(); - } - - @Override - public String toString() { - return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE). - append("origin", originBlock). - append("duplicates", duplicates, true). - toString(); - } - -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/duplication/internal/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/duplication/internal/package-info.java deleted file mode 100644 index 229366c3e9d..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/duplication/internal/package-info.java +++ /dev/null @@ -1,21 +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. - */ -@javax.annotation.ParametersAreNonnullByDefault -package org.sonar.api.batch.sensor.duplication.internal; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/duplication/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/duplication/package-info.java deleted file mode 100644 index 4973316830a..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/duplication/package-info.java +++ /dev/null @@ -1,21 +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. - */ -@javax.annotation.ParametersAreNonnullByDefault -package org.sonar.api.batch.sensor.duplication; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java index df0e22ab041..11030102a8b 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java @@ -42,9 +42,6 @@ import org.sonar.api.batch.sensor.SensorContext; import org.sonar.api.batch.sensor.coverage.CoverageType; import org.sonar.api.batch.sensor.coverage.NewCoverage; import org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage; -import org.sonar.api.batch.sensor.duplication.Duplication; -import org.sonar.api.batch.sensor.duplication.NewDuplication; -import org.sonar.api.batch.sensor.duplication.internal.DefaultDuplication; import org.sonar.api.batch.sensor.highlighting.NewHighlighting; import org.sonar.api.batch.sensor.highlighting.TypeOfText; import org.sonar.api.batch.sensor.highlighting.internal.DefaultHighlighting; @@ -206,15 +203,6 @@ public class SensorContextTester implements SensorContext { return result; } - @Override - public NewDuplication newDuplication() { - return new DefaultDuplication(sensorStorage); - } - - public Collection<Duplication> duplications() { - return sensorStorage.duplications; - } - public static class MockAnalysisMode implements AnalysisMode { private boolean isPreview = false; private boolean isIssues = false; @@ -252,8 +240,6 @@ public class SensorContextTester implements SensorContext { private Map<String, DefaultHighlighting> highlightingByComponent = new HashMap<>(); private Map<String, Map<CoverageType, DefaultCoverage>> coverageByComponent = new HashMap<>(); - private List<Duplication> duplications = new ArrayList<>(); - @Override public void store(Measure measure) { measuresByComponentAndMetric.row(measure.inputComponent().key()).put(measure.metric().key(), measure); @@ -265,11 +251,6 @@ public class SensorContextTester implements SensorContext { } @Override - public void store(Duplication duplication) { - duplications.add(duplication); - } - - @Override public void store(DefaultHighlighting highlighting) { highlightingByComponent.put(highlighting.inputFile().key(), highlighting); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorStorage.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorStorage.java index 60609262b7a..c9955399506 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorStorage.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorStorage.java @@ -21,7 +21,6 @@ package org.sonar.api.batch.sensor.internal; import org.sonar.api.batch.BatchSide; import org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage; -import org.sonar.api.batch.sensor.duplication.Duplication; import org.sonar.api.batch.sensor.highlighting.internal.DefaultHighlighting; import org.sonar.api.batch.sensor.issue.Issue; import org.sonar.api.batch.sensor.measure.Measure; @@ -37,8 +36,6 @@ public interface SensorStorage { void store(Issue issue); - void store(Duplication duplication); - void store(DefaultHighlighting highlighting); /** 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 deleted file mode 100644 index 45b5346130c..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/duplication/DuplicationTest.java +++ /dev/null @@ -1,43 +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 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/DefaultDuplicationTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/duplication/internal/DefaultDuplicationTest.java deleted file mode 100644 index efee043ee98..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/duplication/internal/DefaultDuplicationTest.java +++ /dev/null @@ -1,72 +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.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); - } - -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/internal/SensorContextTesterTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/internal/SensorContextTesterTest.java index 7895ab3f3ee..5e146870ea7 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/internal/SensorContextTesterTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/internal/SensorContextTesterTest.java @@ -19,16 +19,12 @@ */ package org.sonar.api.batch.sensor.internal; -import org.sonar.api.batch.sensor.coverage.NewCoverage; - -import org.junit.rules.ExpectedException; - import java.io.File; import java.io.StringReader; - import org.junit.Before; import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; import org.sonar.api.batch.fs.internal.DefaultFileSystem; import org.sonar.api.batch.fs.internal.DefaultInputFile; @@ -37,11 +33,13 @@ import org.sonar.api.batch.fs.internal.FileMetadata; import org.sonar.api.batch.rule.ActiveRules; import org.sonar.api.batch.rule.internal.ActiveRulesBuilder; import org.sonar.api.batch.sensor.coverage.CoverageType; +import org.sonar.api.batch.sensor.coverage.NewCoverage; import org.sonar.api.batch.sensor.highlighting.TypeOfText; import org.sonar.api.batch.sensor.issue.NewIssue; import org.sonar.api.config.Settings; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.rule.RuleKey; + import static org.assertj.core.api.Assertions.assertThat; public class SensorContextTesterTest { @@ -148,28 +146,17 @@ public class SensorContextTesterTest { } @Test - public void testDuplication() { - assertThat(tester.duplications()).isEmpty(); - tester.newDuplication() - .originBlock(new DefaultInputFile("foo", "src/Foo.java").setLines(40), 1, 30) - .isDuplicatedBy(new DefaultInputFile("foo", "src/Foo2.java").setLines(40), 3, 33) - .isDuplicatedBy(new DefaultInputFile("foo", "src/Foo3.java").setLines(40), 4, 34) - .save(); - assertThat(tester.duplications()).hasSize(1); - } - - @Test public void testCoverageAtLineZero() { assertThat(tester.lineHits("foo:src/Foo.java", CoverageType.UNIT, 1)).isNull(); assertThat(tester.lineHits("foo:src/Foo.java", CoverageType.UNIT, 4)).isNull(); - + exception.expect(IllegalStateException.class); NewCoverage coverage = tester.newCoverage() .onFile(new DefaultInputFile("foo", "src/Foo.java").initMetadata(new FileMetadata().readMetadata(new StringReader("annot dsf fds foo bar")))) .ofType(CoverageType.UNIT) .lineHits(0, 3); } - + @Test public void testCoverageAtLineOutOfRange() { assertThat(tester.lineHits("foo:src/Foo.java", CoverageType.UNIT, 1)).isNull(); |