use of com.google.errorprone.matchers.Description in project error-prone by google.
the class DescriptionBasedDiffTest method overlappingDiffs_throws.
@Test
public void overlappingDiffs_throws() {
DescriptionBasedDiff diff = createDescriptionBasedDiff();
assertThrows(IllegalArgumentException.class, () -> diff.onDescribed(new Description(null, "message", SuggestedFix.builder().replace(137, 140, "baz").replace(137, 140, "bar").build(), SeverityLevel.SUGGESTION)));
DescriptionBasedDiff diff2 = createDescriptionBasedDiff();
diff2.onDescribed(new Description(null, "bah", SuggestedFix.builder().replace(137, 140, "baz").build(), SeverityLevel.SUGGESTION));
assertThrows(IllegalArgumentException.class, () -> diff2.onDescribed(new Description(null, "message", SuggestedFix.builder().replace(137, 140, "bar").build(), SeverityLevel.SUGGESTION)));
DescriptionBasedDiff diff3 = DescriptionBasedDiff.createIgnoringOverlaps(compilationUnit, ImportOrganizer.STATIC_FIRST_ORGANIZER);
diff3.onDescribed(new Description(null, "bah", SuggestedFix.builder().replace(137, 140, "baz").build(), SeverityLevel.SUGGESTION));
// No throw, since it's lenient. Refactors to the first "baz" replacement and ignores this.
diff3.onDescribed(new Description(null, "message", SuggestedFix.builder().replace(137, 140, "bar").build(), SeverityLevel.SUGGESTION));
diff3.applyDifferences(sourceFile);
assertThat(sourceFile.getLines()).containsExactly("package foo.bar;", "import org.bar.Baz;", "import com.foo.Bar;", "", "class Foo {", " public static void main(String[] args) {", " System.out.println(\"baz\");", " }", "}").inOrder();
}
use of com.google.errorprone.matchers.Description in project error-prone by google.
the class DescriptionBasedDiffTest method twoDiffs.
@Test
public void twoDiffs() {
DescriptionBasedDiff diff = createDescriptionBasedDiff();
diff.onDescribed(new Description(null, "message", SuggestedFix.builder().replace(124, 127, "longer").replace(137, 140, "bar").build(), SeverityLevel.SUGGESTION));
diff.applyDifferences(sourceFile);
assertThat(sourceFile.getLines()).containsExactly("package foo.bar;", "import org.bar.Baz;", "import com.foo.Bar;", "", "class Foo {", " public static void main(String[] args) {", " System.longer.println(\"bar\");", " }", "}").inOrder();
}
use of com.google.errorprone.matchers.Description in project error-prone by google.
the class DescriptionBasedDiffTest method applyDifferences_addsImportAndSorts_whenAddingNewImport.
@Test
public void applyDifferences_addsImportAndSorts_whenAddingNewImport() {
DescriptionBasedDiff diff = createDescriptionBasedDiff();
diff.onDescribed(new Description(null, "message", SuggestedFix.builder().addImport("com.google.foo.Bar").build(), SeverityLevel.SUGGESTION));
diff.applyDifferences(sourceFile);
assertThat(sourceFile.getLines()).containsExactly("package foo.bar;", "import com.foo.Bar;", "import com.google.foo.Bar;", "import org.bar.Baz;", "", "class Foo {", " public static void main(String[] args) {", " System.out.println(\"foo\");", " }", "}").inOrder();
}
use of com.google.errorprone.matchers.Description in project error-prone by google.
the class DescriptionBasedDiffTest method twoDiffsWithImport.
@Test
public void twoDiffsWithImport() {
DescriptionBasedDiff diff = createDescriptionBasedDiff();
diff.onDescribed(new Description(null, "message", SuggestedFix.builder().replace(124, 127, "longer").replace(137, 140, "bar").addImport("com.google.foo.Bar").build(), SeverityLevel.SUGGESTION));
diff.applyDifferences(sourceFile);
assertThat(sourceFile.getLines()).containsExactly("package foo.bar;", "import com.foo.Bar;", "import com.google.foo.Bar;", "import org.bar.Baz;", "", "class Foo {", " public static void main(String[] args) {", " System.longer.println(\"bar\");", " }", "}").inOrder();
}
use of com.google.errorprone.matchers.Description in project error-prone by google.
the class DescriptionBasedDiffTest method removeImport.
@Test
public void removeImport() {
DescriptionBasedDiff diff = createDescriptionBasedDiff();
diff.onDescribed(new Description(null, "message", SuggestedFix.builder().removeImport("com.foo.Bar").removeImport("org.bar.Baz").build(), SeverityLevel.SUGGESTION));
diff.applyDifferences(sourceFile);
assertThat(sourceFile.getLines()).containsExactly("package foo.bar;", "", "", "class Foo {", " public static void main(String[] args) {", " System.out.println(\"foo\");", " }", "}").inOrder();
}
Aggregations