Skip to content

Commit

Permalink
Inline all CompilationTestHelpers and BugCheckerRefactoringTestHelpers
Browse files Browse the repository at this point in the history
  • Loading branch information
rickie committed Jan 6, 2023
1 parent 5989b6b commit d4ce9e6
Show file tree
Hide file tree
Showing 38 changed files with 164 additions and 324 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,16 @@
import static com.google.common.base.Predicates.containsPattern;

import com.google.errorprone.BugCheckerRefactoringTestHelper;
import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode;
import com.google.errorprone.CompilationTestHelper;
import org.junit.jupiter.api.Test;

final class AmbiguousJsonCreatorTest {
private final CompilationTestHelper compilationTestHelper =
CompilationTestHelper.newInstance(AmbiguousJsonCreator.class, getClass())
.expectErrorMessage(
"X",
containsPattern("`JsonCreator.Mode` should be set for single-argument creators"));
private final BugCheckerRefactoringTestHelper refactoringTestHelper =
BugCheckerRefactoringTestHelper.newInstance(AmbiguousJsonCreator.class, getClass());

@Test
void identification() {
compilationTestHelper
CompilationTestHelper.newInstance(AmbiguousJsonCreator.class, getClass())
.expectErrorMessage(
"X", containsPattern("`JsonCreator.Mode` should be set for single-argument creators"))
.addSourceLines(
"Container.java",
"import com.fasterxml.jackson.annotation.JsonCreator;",
Expand Down Expand Up @@ -118,7 +113,7 @@ void identification() {

@Test
void replacement() {
refactoringTestHelper
BugCheckerRefactoringTestHelper.newInstance(AmbiguousJsonCreator.class, getClass())
.addInputLines(
"A.java",
"import com.fasterxml.jackson.annotation.JsonCreator;",
Expand All @@ -143,6 +138,6 @@ void replacement() {
" return FOO;",
" }",
"}")
.doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH);
.doTest(TestMode.TEXT_MATCH);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@
import org.junit.jupiter.api.Test;

final class AssertJIsNullTest {
private final CompilationTestHelper compilationTestHelper =
CompilationTestHelper.newInstance(AssertJIsNull.class, getClass());
private final BugCheckerRefactoringTestHelper refactoringTestHelper =
BugCheckerRefactoringTestHelper.newInstance(AssertJIsNull.class, getClass());

@Test
void identification() {
compilationTestHelper
CompilationTestHelper.newInstance(AssertJIsNull.class, getClass())
.addSourceLines(
"A.java",
"import static org.assertj.core.api.Assertions.assertThat;",
Expand All @@ -38,7 +33,7 @@ void identification() {

@Test
void replacement() {
refactoringTestHelper
BugCheckerRefactoringTestHelper.newInstance(AssertJIsNull.class, getClass())
.addInputLines(
"A.java",
"import static org.assertj.core.api.Assertions.assertThat;",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@
import org.junit.jupiter.api.Test;

final class AutowiredConstructorTest {
private final CompilationTestHelper compilationTestHelper =
CompilationTestHelper.newInstance(AutowiredConstructor.class, getClass());
private final BugCheckerRefactoringTestHelper refactoringTestHelper =
BugCheckerRefactoringTestHelper.newInstance(AutowiredConstructor.class, getClass());

@Test
void identification() {
compilationTestHelper
CompilationTestHelper.newInstance(AutowiredConstructor.class, getClass())
.addSourceLines(
"Container.java",
"import com.google.errorprone.annotations.Immutable;",
Expand Down Expand Up @@ -71,7 +66,7 @@ void identification() {

@Test
void replacement() {
refactoringTestHelper
BugCheckerRefactoringTestHelper.newInstance(AutowiredConstructor.class, getClass())
.addInputLines(
"Container.java",
"import org.springframework.beans.factory.annotation.Autowired;",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@
import org.junit.jupiter.api.Test;

final class CanonicalAnnotationSyntaxTest {
private final CompilationTestHelper compilationTestHelper =
CompilationTestHelper.newInstance(CanonicalAnnotationSyntax.class, getClass());
private final BugCheckerRefactoringTestHelper refactoringTestHelper =
BugCheckerRefactoringTestHelper.newInstance(CanonicalAnnotationSyntax.class, getClass());

@Test
void identification() {
compilationTestHelper
CompilationTestHelper.newInstance(CanonicalAnnotationSyntax.class, getClass())
.addSourceLines(
"pkg/A.java",
"package pkg;",
Expand Down Expand Up @@ -133,7 +128,7 @@ void identification() {

@Test
void replacement() {
refactoringTestHelper
BugCheckerRefactoringTestHelper.newInstance(CanonicalAnnotationSyntax.class, getClass())
.addInputLines(
"pkg/A.java",
"package pkg;",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,9 @@
import org.junit.jupiter.api.Test;

final class CollectorMutabilityTest {
private final CompilationTestHelper compilationTestHelper =
CompilationTestHelper.newInstance(CollectorMutability.class, getClass());
private final BugCheckerRefactoringTestHelper refactoringTestHelper =
BugCheckerRefactoringTestHelper.newInstance(CollectorMutability.class, getClass());

@Test
void identification() {
compilationTestHelper
CompilationTestHelper.newInstance(CollectorMutability.class, getClass())
.addSourceLines(
"A.java",
"import static com.google.common.collect.ImmutableList.toImmutableList;",
Expand Down Expand Up @@ -67,7 +62,7 @@ void identification() {

@Test
void identificationWithoutGuavaOnClasspath() {
compilationTestHelper
CompilationTestHelper.newInstance(CollectorMutability.class, getClass())
.withClasspath()
.addSourceLines(
"A.java",
Expand All @@ -84,7 +79,7 @@ void identificationWithoutGuavaOnClasspath() {

@Test
void replacementFirstSuggestedFix() {
refactoringTestHelper
BugCheckerRefactoringTestHelper.newInstance(CollectorMutability.class, getClass())
.addInputLines(
"A.java",
"import static java.util.stream.Collectors.toList;",
Expand Down Expand Up @@ -141,7 +136,7 @@ void replacementFirstSuggestedFix() {

@Test
void replacementSecondSuggestedFix() {
refactoringTestHelper
BugCheckerRefactoringTestHelper.newInstance(CollectorMutability.class, getClass())
.setFixChooser(SECOND)
.addInputLines(
"A.java",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@
import org.junit.jupiter.api.Test;

final class EmptyMethodTest {
private final CompilationTestHelper compilationTestHelper =
CompilationTestHelper.newInstance(EmptyMethod.class, getClass());
private final BugCheckerRefactoringTestHelper refactoringTestHelper =
BugCheckerRefactoringTestHelper.newInstance(EmptyMethod.class, getClass());

@Test
void identification() {
compilationTestHelper
CompilationTestHelper.newInstance(EmptyMethod.class, getClass())
.addSourceLines(
"A.java",
"class A {",
Expand Down Expand Up @@ -69,7 +64,7 @@ void identification() {

@Test
void replacement() {
refactoringTestHelper
BugCheckerRefactoringTestHelper.newInstance(EmptyMethod.class, getClass())
.addInputLines(
"A.java",
"final class A {",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,9 @@
import org.junit.jupiter.api.Test;

final class ErrorProneTestHelperSourceFormatTest {
private final CompilationTestHelper compilationTestHelper =
CompilationTestHelper.newInstance(ErrorProneTestHelperSourceFormat.class, getClass());
private final BugCheckerRefactoringTestHelper refactoringTestHelper =
BugCheckerRefactoringTestHelper.newInstance(
ErrorProneTestHelperSourceFormat.class, getClass());

@Test
void identification() {
compilationTestHelper
CompilationTestHelper.newInstance(ErrorProneTestHelperSourceFormat.class, getClass())
.addSourceLines(
"A.java",
"import com.google.errorprone.BugCheckerRefactoringTestHelper;",
Expand Down Expand Up @@ -63,7 +57,7 @@ void replacement() {
* Verifies that import sorting and code formatting is performed unconditionally, while unused
* imports are removed unless part of a `BugCheckerRefactoringTestHelper` expected output file.
*/
refactoringTestHelper
BugCheckerRefactoringTestHelper.newInstance(ErrorProneTestHelperSourceFormat.class, getClass())
.addInputLines(
"A.java",
"import com.google.errorprone.BugCheckerRefactoringTestHelper;",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
import org.junit.jupiter.api.Test;

final class ExplicitEnumOrderingTest {
private final CompilationTestHelper compilationTestHelper =
CompilationTestHelper.newInstance(ExplicitEnumOrdering.class, getClass());

@Test
void identification() {
compilationTestHelper
CompilationTestHelper.newInstance(ExplicitEnumOrdering.class, getClass())
.addSourceLines(
"A.java",
"import static java.lang.annotation.RetentionPolicy.CLASS;",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@

import static com.google.errorprone.BugCheckerRefactoringTestHelper.newInstance;

import com.google.errorprone.BugCheckerRefactoringTestHelper;
import com.google.errorprone.BugCheckerRefactoringTestHelper.FixChoosers;
import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode;
import com.google.errorprone.CompilationTestHelper;
import org.junit.jupiter.api.Test;

final class FluxFlatMapUsageTest {
private final CompilationTestHelper compilationTestHelper =
CompilationTestHelper.newInstance(FluxFlatMapUsage.class, getClass());
private final BugCheckerRefactoringTestHelper refactoringTestHelper =
newInstance(FluxFlatMapUsage.class, getClass());

@Test
void identification() {
compilationTestHelper
CompilationTestHelper.newInstance(FluxFlatMapUsage.class, getClass())
.addSourceLines(
"A.java",
"import java.util.function.BiFunction;",
Expand Down Expand Up @@ -73,7 +67,7 @@ void identification() {

@Test
void replacementFirstSuggestedFix() {
refactoringTestHelper
newInstance(FluxFlatMapUsage.class, getClass())
.setFixChooser(FixChoosers.FIRST)
.addInputLines(
"A.java",
Expand Down Expand Up @@ -108,7 +102,7 @@ void replacementFirstSuggestedFix() {

@Test
void replacementSecondSuggestedFix() {
refactoringTestHelper
newInstance(FluxFlatMapUsage.class, getClass())
.setFixChooser(FixChoosers.SECOND)
.addInputLines(
"A.java",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@
import org.junit.jupiter.api.Test;

final class FormatStringConcatenationTest {
private final CompilationTestHelper compilationTestHelper =
CompilationTestHelper.newInstance(FormatStringConcatenation.class, getClass());
private final BugCheckerRefactoringTestHelper refactoringTestHelper =
BugCheckerRefactoringTestHelper.newInstance(FormatStringConcatenation.class, getClass());

@Test
void identification() {
compilationTestHelper
CompilationTestHelper.newInstance(FormatStringConcatenation.class, getClass())
.addSourceLines(
"A.java",
"import static com.google.common.base.Preconditions.checkArgument;",
Expand Down Expand Up @@ -309,7 +304,7 @@ void identification() {

@Test
void replacement() {
refactoringTestHelper
BugCheckerRefactoringTestHelper.newInstance(FormatStringConcatenation.class, getClass())
.addInputLines(
"A.java",
"import static com.google.common.base.Preconditions.checkArgument;",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@
import org.junit.jupiter.api.Test;

final class IdentityConversionTest {
private final CompilationTestHelper compilationTestHelper =
CompilationTestHelper.newInstance(IdentityConversion.class, getClass());
private final BugCheckerRefactoringTestHelper refactoringTestHelper =
BugCheckerRefactoringTestHelper.newInstance(IdentityConversion.class, getClass());

@Test
void identification() {
compilationTestHelper
CompilationTestHelper.newInstance(IdentityConversion.class, getClass())
.addSourceLines(
"A.java",
"import static com.google.errorprone.matchers.Matchers.instanceMethod;",
Expand Down Expand Up @@ -184,7 +179,7 @@ void identification() {

@Test
void replacementFirstSuggestedFix() {
refactoringTestHelper
BugCheckerRefactoringTestHelper.newInstance(IdentityConversion.class, getClass())
.setFixChooser(FixChoosers.FIRST)
.addInputLines(
"A.java",
Expand Down Expand Up @@ -291,7 +286,7 @@ void replacementFirstSuggestedFix() {

@Test
void replacementSecondSuggestedFix() {
refactoringTestHelper
BugCheckerRefactoringTestHelper.newInstance(IdentityConversion.class, getClass())
.setFixChooser(FixChoosers.SECOND)
.addInputLines(
"A.java",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@
import org.junit.jupiter.api.Test;

final class ImmutablesSortedSetComparatorTest {
private final CompilationTestHelper compilationTestHelper =
CompilationTestHelper.newInstance(ImmutablesSortedSetComparator.class, getClass());
private final BugCheckerRefactoringTestHelper refactoringTestHelper =
BugCheckerRefactoringTestHelper.newInstance(ImmutablesSortedSetComparator.class, getClass());

@Test
void identification() {
compilationTestHelper
CompilationTestHelper.newInstance(ImmutablesSortedSetComparator.class, getClass())
.addSourceLines(
"A.java",
"import com.google.common.collect.ContiguousSet;",
Expand Down Expand Up @@ -109,7 +104,7 @@ void identification() {

@Test
void replacement() {
refactoringTestHelper
BugCheckerRefactoringTestHelper.newInstance(ImmutablesSortedSetComparator.class, getClass())
.addInputLines(
"A.java",
"import com.google.common.collect.ImmutableSortedSet;",
Expand Down Expand Up @@ -147,7 +142,7 @@ void replacement() {

@Test
void replacementWithImportClash() {
refactoringTestHelper
BugCheckerRefactoringTestHelper.newInstance(ImmutablesSortedSetComparator.class, getClass())
.addInputLines(
"MySpringService.java",
"import com.google.common.collect.ImmutableSortedSet;",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@
import org.junit.jupiter.api.Test;

final class IsInstanceLambdaUsageTest {
private final CompilationTestHelper compilationTestHelper =
CompilationTestHelper.newInstance(IsInstanceLambdaUsage.class, getClass());
private final BugCheckerRefactoringTestHelper refactoringTestHelper =
BugCheckerRefactoringTestHelper.newInstance(IsInstanceLambdaUsage.class, getClass());

@Test
void identification() {
compilationTestHelper
CompilationTestHelper.newInstance(IsInstanceLambdaUsage.class, getClass())
.addSourceLines(
"A.java",
"import java.util.stream.Stream;",
Expand Down Expand Up @@ -46,7 +41,7 @@ void identification() {

@Test
void replacement() {
refactoringTestHelper
BugCheckerRefactoringTestHelper.newInstance(IsInstanceLambdaUsage.class, getClass())
.addInputLines(
"A.java",
"import java.util.stream.Stream;",
Expand Down
Loading

0 comments on commit d4ce9e6

Please sign in to comment.