Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline most {BugCheckerRefactoring,Compilation}TestHelper fields #442

Merged
merged 4 commits into from
Jan 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
@@ -1,22 +1,15 @@
package tech.picnic.errorprone.bugpatterns;

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 +66,7 @@ void identification() {

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

@Test
void replacementSecondSuggestedFix() {
refactoringTestHelper
BugCheckerRefactoringTestHelper.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