From b06945b833c36cf7a1889af6b040f1726726bef8 Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Wed, 10 Aug 2022 14:40:07 +0200 Subject: [PATCH] Introduce utilities to validate Refaster template collections (#43) The `Refaster` check is now located in the new `refaster-runner` Maven module. The new `refaster-test-support` module exposes `RefasterTemplateCollection#validate`, which for a given template collection validates: - That there exist corresponding `*Test{Input,Output}.java` files. - That each template is exercised by precisely one method in these files. --- error-prone-contrib/pom.xml | 17 +- .../refastertemplates/OptionalTemplates.java | 4 +- .../errorprone/bugpatterns/RefasterTest.java | 191 ----------- .../RefasterTemplatesTest.java | 81 +++++ .../AssertJBigDecimalTemplatesTestInput.java | 1 + .../AssertJBigDecimalTemplatesTestOutput.java | 1 + .../AssertJBigIntegerTemplatesTestInput.java | 1 + .../AssertJBigIntegerTemplatesTestOutput.java | 1 + .../AssertJBooleanTemplatesTestInput.java | 1 + .../AssertJBooleanTemplatesTestOutput.java | 1 + .../AssertJByteTemplatesTestInput.java | 1 + .../AssertJByteTemplatesTestOutput.java | 1 + ...AssertJCharSequenceTemplatesTestInput.java | 1 + ...ssertJCharSequenceTemplatesTestOutput.java | 1 + .../AssertJDoubleTemplatesTestInput.java | 1 + .../AssertJDoubleTemplatesTestOutput.java | 1 + .../AssertJEnumerableTemplatesTestInput.java | 1 + .../AssertJEnumerableTemplatesTestOutput.java | 1 + .../AssertJFloatTemplatesTestInput.java | 1 + .../AssertJFloatTemplatesTestOutput.java | 1 + .../AssertJIntegerTemplatesTestInput.java | 1 + .../AssertJIntegerTemplatesTestOutput.java | 1 + .../AssertJLongTemplatesTestInput.java | 1 + .../AssertJLongTemplatesTestOutput.java | 1 + .../AssertJMapTemplatesTestInput.java | 1 + .../AssertJMapTemplatesTestOutput.java | 1 + .../AssertJNumberTemplatesTestInput.java | 1 + .../AssertJNumberTemplatesTestOutput.java | 1 + .../AssertJObjectTemplatesTestInput.java | 1 + .../AssertJObjectTemplatesTestOutput.java | 1 + .../AssertJOptionalTemplatesTestInput.java | 1 + .../AssertJOptionalTemplatesTestOutput.java | 1 + .../AssertJShortTemplatesTestInput.java | 1 + .../AssertJShortTemplatesTestOutput.java | 1 + .../AssertJStringTemplatesTestInput.java | 1 + .../AssertJStringTemplatesTestOutput.java | 1 + ...rtJThrowingCallableTemplatesTestInput.java | 1 + ...tJThrowingCallableTemplatesTestOutput.java | 1 + .../AssortedTemplatesTestInput.java | 1 + .../AssortedTemplatesTestOutput.java | 1 + .../BigDecimalTemplatesTestInput.java | 1 + .../BigDecimalTemplatesTestOutput.java | 1 + .../CollectionTemplatesTestInput.java | 1 + .../CollectionTemplatesTestOutput.java | 1 + .../ComparatorTemplatesTestInput.java | 1 + .../ComparatorTemplatesTestOutput.java | 1 + .../DoubleStreamTemplatesTestInput.java | 1 + .../DoubleStreamTemplatesTestOutput.java | 1 + .../EqualityTemplatesTestInput.java | 1 + .../EqualityTemplatesTestOutput.java | 1 + ...mutableListMultimapTemplatesTestInput.java | 1 + ...utableListMultimapTemplatesTestOutput.java | 1 + .../ImmutableListTemplatesTestInput.java | 1 + .../ImmutableListTemplatesTestOutput.java | 1 + .../ImmutableMapTemplatesTestInput.java | 1 + .../ImmutableMapTemplatesTestOutput.java | 1 + .../ImmutableMultisetTemplatesTestInput.java | 1 + .../ImmutableMultisetTemplatesTestOutput.java | 1 + ...mmutableSetMultimapTemplatesTestInput.java | 1 + ...mutableSetMultimapTemplatesTestOutput.java | 1 + .../ImmutableSetTemplatesTestInput.java | 1 + .../ImmutableSetTemplatesTestOutput.java | 1 + .../ImmutableSortedMapTemplatesTestInput.java | 1 + ...ImmutableSortedMapTemplatesTestOutput.java | 1 + ...tableSortedMultisetTemplatesTestInput.java | 1 + ...ableSortedMultisetTemplatesTestOutput.java | 1 + .../ImmutableSortedSetTemplatesTestInput.java | 1 + ...ImmutableSortedSetTemplatesTestOutput.java | 1 + .../IntStreamTemplatesTestInput.java | 1 + .../IntStreamTemplatesTestOutput.java | 1 + .../JUnitTemplatesTestInput.java | 1 + .../JUnitTemplatesTestOutput.java | 1 + .../LongStreamTemplatesTestInput.java | 1 + .../LongStreamTemplatesTestOutput.java | 1 + .../MapEntryTemplatesTestInput.java | 1 + .../MapEntryTemplatesTestOutput.java | 1 + .../MockitoTemplatesTestInput.java | 1 + .../MockitoTemplatesTestOutput.java | 1 + .../MultimapTemplatesTestInput.java | 1 + .../MultimapTemplatesTestOutput.java | 1 + .../NullTemplatesTestInput.java | 1 + .../NullTemplatesTestOutput.java | 1 + .../OptionalTemplatesTestInput.java | 1 + .../OptionalTemplatesTestOutput.java | 1 + .../PrimitiveTemplatesTestInput.java | 1 + .../PrimitiveTemplatesTestOutput.java | 1 + .../ReactorTemplatesTestInput.java | 1 + .../ReactorTemplatesTestOutput.java | 1 + .../RxJava2AdapterTemplatesTestInput.java | 1 + .../RxJava2AdapterTemplatesTestOutput.java | 1 + .../StreamTemplatesTestInput.java | 1 + .../StreamTemplatesTestOutput.java | 1 + .../StringTemplatesTestInput.java | 1 + .../StringTemplatesTestOutput.java | 1 + .../TestNGToAssertJTemplatesTestInput.java | 1 + .../TestNGToAssertJTemplatesTestOutput.java | 1 + .../TimeTemplatesTestInput.java | 1 + .../TimeTemplatesTestOutput.java | 1 + .../WebClientTemplatesTestInput.java | 1 + .../WebClientTemplatesTestOutput.java | 1 + pom.xml | 20 ++ refaster-runner/pom.xml | 99 ++++++ .../refaster/runner/CodeTransformers.java | 98 ++++++ .../errorprone/refaster/runner}/Refaster.java | 78 +---- .../refaster/runner/package-info.java | 4 + .../refaster/runner/CodeTransformersTest.java | 17 + .../refaster/runner/FooTemplates.java | 22 ++ refaster-test-support/README.md | 82 +++++ refaster-test-support/pom.xml | 96 ++++++ .../test/RefasterTemplateCollection.java | 298 ++++++++++++++++++ .../test}/RefasterTemplateTestCase.java | 11 +- .../refaster/test/package-info.java | 4 + .../test/MatchInWrongMethodTemplates.java | 23 ++ .../test/MethodWithoutPrefixTemplates.java | 25 ++ .../MissingTestAndWrongTestTemplates.java | 31 ++ .../test/PartialTestMatchTemplates.java | 36 +++ .../test/RefasterTemplateCollectionTest.java | 30 ++ .../test/TemplateWithoutTestTemplates.java | 35 ++ .../refaster/test/ValidTemplates.java | 62 ++++ .../MatchInWrongMethodTemplatesTestInput.java | 10 + ...MatchInWrongMethodTemplatesTestOutput.java | 16 + ...MethodWithoutPrefixTemplatesTestInput.java | 21 ++ ...ethodWithoutPrefixTemplatesTestOutput.java | 23 ++ ...ingTestAndWrongTestTemplatesTestInput.java | 10 + ...ngTestAndWrongTestTemplatesTestOutput.java | 20 ++ .../PartialTestMatchTemplatesTestInput.java | 9 + .../PartialTestMatchTemplatesTestOutput.java | 13 + ...TemplateWithoutTestTemplatesTestInput.java | 8 + ...emplateWithoutTestTemplatesTestOutput.java | 13 + .../test/ValidTemplatesTestInput.java | 32 ++ .../test/ValidTemplatesTestOutput.java | 33 ++ 131 files changed, 1387 insertions(+), 281 deletions(-) delete mode 100644 error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RefasterTest.java create mode 100644 error-prone-contrib/src/test/java/tech/picnic/errorprone/refastertemplates/RefasterTemplatesTest.java create mode 100644 refaster-runner/pom.xml create mode 100644 refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/CodeTransformers.java rename {error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns => refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner}/Refaster.java (70%) create mode 100644 refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/package-info.java create mode 100644 refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/CodeTransformersTest.java create mode 100644 refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/FooTemplates.java create mode 100644 refaster-test-support/README.md create mode 100644 refaster-test-support/pom.xml create mode 100644 refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterTemplateCollection.java rename {error-prone-contrib/src/test/java/tech/picnic/errorprone/refastertemplates => refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test}/RefasterTemplateTestCase.java (71%) create mode 100644 refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/package-info.java create mode 100644 refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/MatchInWrongMethodTemplates.java create mode 100644 refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/MethodWithoutPrefixTemplates.java create mode 100644 refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/MissingTestAndWrongTestTemplates.java create mode 100644 refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/PartialTestMatchTemplates.java create mode 100644 refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/RefasterTemplateCollectionTest.java create mode 100644 refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/TemplateWithoutTestTemplates.java create mode 100644 refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/ValidTemplates.java create mode 100644 refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/MatchInWrongMethodTemplatesTestInput.java create mode 100644 refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/MatchInWrongMethodTemplatesTestOutput.java create mode 100644 refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/MethodWithoutPrefixTemplatesTestInput.java create mode 100644 refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/MethodWithoutPrefixTemplatesTestOutput.java create mode 100644 refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/MissingTestAndWrongTestTemplatesTestInput.java create mode 100644 refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/MissingTestAndWrongTestTemplatesTestOutput.java create mode 100644 refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/PartialTestMatchTemplatesTestInput.java create mode 100644 refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/PartialTestMatchTemplatesTestOutput.java create mode 100644 refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/TemplateWithoutTestTemplatesTestInput.java create mode 100644 refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/TemplateWithoutTestTemplatesTestOutput.java create mode 100644 refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/ValidTemplatesTestInput.java create mode 100644 refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/ValidTemplatesTestOutput.java diff --git a/error-prone-contrib/pom.xml b/error-prone-contrib/pom.xml index 4fd14a1f28..311dd58319 100644 --- a/error-prone-contrib/pom.xml +++ b/error-prone-contrib/pom.xml @@ -41,15 +41,13 @@ ${project.groupId} - refaster-compiler - + refaster-support provided ${project.groupId} - refaster-support + refaster-test-support + test com.fasterxml.jackson.core @@ -205,15 +203,6 @@ - - com.spotify.fmt - fmt-maven-plugin - - - ${basedir}/src/test/resources - - - org.apache.maven.plugins maven-compiler-plugin diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/OptionalTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/OptionalTemplates.java index b33ddf3b16..f84351a1e8 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/OptionalTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/OptionalTemplates.java @@ -113,7 +113,7 @@ Optional after(Iterator it) { /** Prefer {@link Optional#filter(Predicate)} over usage of the ternary operator. */ // XXX: This rule may introduce a compilation error: the `test` expression may reference a // non-effectively final variable, which is not allowed in the replacement lambda expression. - // Maybe our RefasterCheck should test `compilesWithFix`? + // Maybe our `Refaster` checker should test `compilesWithFix`? abstract static class TernaryOperatorOptionalPositiveFiltering { @Placeholder abstract boolean test(T value); @@ -133,7 +133,7 @@ Optional after(T input) { /** Prefer {@link Optional#filter(Predicate)} over usage of the ternary operator. */ // XXX: This rule may introduce a compilation error: the `test` expression may reference a // non-effectively final variable, which is not allowed in the replacement lambda expression. - // Maybe our RefasterCheck should test `compilesWithFix`? + // Maybe our `Refaster` checker should test `compilesWithFix`? abstract static class TernaryOperatorOptionalNegativeFiltering { @Placeholder abstract boolean test(T value); diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RefasterTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RefasterTest.java deleted file mode 100644 index a72ac27840..0000000000 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RefasterTest.java +++ /dev/null @@ -1,191 +0,0 @@ -package tech.picnic.errorprone.bugpatterns; - -import static com.google.common.collect.ImmutableSetMultimap.toImmutableSetMultimap; -import static java.util.function.Function.identity; -import static java.util.function.Predicate.not; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatCode; -import static org.junit.jupiter.params.provider.Arguments.arguments; - -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.ImmutableSetMultimap; -import com.google.errorprone.BugCheckerRefactoringTestHelper; -import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode; -import java.util.regex.Pattern; -import java.util.stream.Stream; -import org.junit.ComparisonFailure; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; - -final class RefasterTest { - /** The names of all Refaster template groups defined in this module. */ - private static final ImmutableSet TEMPLATE_GROUPS = - ImmutableSet.of( - "AssertJ", - "AssertJBigDecimal", - "AssertJBigInteger", - "AssertJBoolean", - "AssertJByte", - "AssertJCharSequence", - "AssertJDouble", - "AssertJEnumerable", - "AssertJFloat", - "AssertJInteger", - "AssertJLong", - "AssertJNumber", - "AssertJMap", - "AssertJObject", - "AssertJOptional", - "AssertJShort", - "AssertJString", - "AssertJThrowingCallable", - "Assorted", - "BigDecimal", - "Collection", - "Comparator", - "DoubleStream", - "Equality", - "ImmutableList", - "ImmutableListMultimap", - "ImmutableMap", - "ImmutableMultiset", - "ImmutableSet", - "ImmutableSetMultimap", - "ImmutableSortedMap", - "ImmutableSortedMultiset", - "ImmutableSortedSet", - "IntStream", - "JUnit", - "LongStream", - "MapEntry", - "Mockito", - "Multimap", - "Null", - "Optional", - "Primitive", - "Reactor", - "RxJava2Adapter", - "Stream", - "String", - "TestNGToAssertJ", - "Time", - "WebClient"); - /** - * Matches the parts of the fully-qualified name of a template class that should be removed in - * order to produce the associated {@link #TEMPLATE_GROUPS template group name}. - */ - private static final Pattern TEMPLATE_FQCN_TRIM_FOR_GROUP_NAME = - Pattern.compile(".*\\.|Templates\\$.*"); - /** - * A mapping from template group names to associated template names. - * - *

In effect, the values correspond to nested classes that represent individual Refaster - * templates, while the keys correspond to the associated top-level "aggregator" classes. - */ - private static final ImmutableSetMultimap TEMPLATES_BY_GROUP = - indexTemplateNamesByGroup(Refaster.ALL_CODE_TRANSFORMERS.get().keySet()); - - /** Returns every known template group name as a parameterized test argument. */ - @SuppressWarnings("UnusedMethod" /* Used as a `@MethodSource`. */) - private static Stream templateGroupsUnderTest() { - // XXX: Drop the filter once we have added tests for AssertJ! - return TEMPLATES_BY_GROUP.keySet().stream().filter(not("AssertJ"::equals)).map(Arguments::of); - } - - /** - * Returns every known (template group name, template name) pair as a parameterized test argument. - */ - @SuppressWarnings("UnusedMethod" /* Used as a `@MethodSource`. */) - private static Stream templatesUnderTest() { - // XXX: Drop the filter once we have added tests for AssertJ! - return TEMPLATES_BY_GROUP.entries().stream() - .filter(e -> !"AssertJ".equals(e.getKey())) - .map(e -> arguments(e.getKey(), e.getValue())); - } - - /** - * Verifies that {@link Refaster#loadAllCodeTransformers} finds at least one code transformer for - * all of the {@link #TEMPLATE_GROUPS}. - * - *

This test is just as much about ensuring that {@link #TEMPLATE_GROUPS} is exhaustive, so - * that in turn {@link #replacement}'s coverage is exhaustive. - */ - @Test - void loadAllCodeTransformers() { - assertThat(TEMPLATES_BY_GROUP.keySet()).hasSameElementsAs(TEMPLATE_GROUPS); - } - - /** - * Verifies for each of the {@link #TEMPLATE_GROUPS} that the associated code transformers have - * the desired effect. - */ - @MethodSource("templateGroupsUnderTest") - @ParameterizedTest - void replacement(String group) { - verifyRefactoring(group, namePattern(group)); - } - - /** - * Verifies that all loaded Refaster templates are covered by at least one test. - * - *

Note that this doesn't guarantee full coverage: this test cannot ascertain that all {@link - * com.google.errorprone.refaster.Refaster#anyOf} branches are tested. Idem for {@link - * com.google.errorprone.refaster.annotation.BeforeTemplate} methods in case there are multiple . - */ - @MethodSource("templatesUnderTest") - @ParameterizedTest - void coverage(String group, String template) { - assertThatCode(() -> verifyRefactoring(group, namePattern(group, template))) - .withFailMessage( - "Template %s does not affect the tests for group %s; is it tested?", template, group) - .isInstanceOf(ComparisonFailure.class); - } - - private static ImmutableSetMultimap indexTemplateNamesByGroup( - ImmutableSet templateNames) { - return templateNames.stream() - .collect( - toImmutableSetMultimap( - n -> TEMPLATE_FQCN_TRIM_FOR_GROUP_NAME.matcher(n).replaceAll(""), identity())); - } - - private static String namePattern(String groupName, String excludedTemplate) { - return "(?!" + Pattern.quote(excludedTemplate) + ')' + namePattern(groupName); - } - - private static String namePattern(String groupName) { - return Pattern.compile(Pattern.quote(groupName)) + "Templates.*"; - } - - private void verifyRefactoring(String groupName, String templateNamePattern) { - createRestrictedRefactoringTestHelper(templateNamePattern) - .addInput(groupName + "TemplatesTestInput.java") - .addOutput(groupName + "TemplatesTestOutput.java") - .doTest(TestMode.TEXT_MATCH); - } - - private BugCheckerRefactoringTestHelper createRestrictedRefactoringTestHelper( - String namePattern) { - return BugCheckerRefactoringTestHelper.newInstance( - Refaster.class, getRefasterTemplateCollectionClass()) - .setArgs("-XepOpt:Refaster:NamePattern=" + namePattern); - } - - /** - * Returns an arbitrary Refaster template collection class inside the {@code - * tech.picnic.errorprone.refastertemplates} package, enabling {@link - * BugCheckerRefactoringTestHelper} to load test resources from said package. - */ - private Class getRefasterTemplateCollectionClass() { - try { - return Class.forName( - "tech.picnic.errorprone.refastertemplates.AssortedTemplates", - /* initialize= */ false, - getClass().getClassLoader()); - } catch (ClassNotFoundException e) { - throw new IllegalStateException("Failed to load Refaster template collection class", e); - } - } -} diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/refastertemplates/RefasterTemplatesTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/refastertemplates/RefasterTemplatesTest.java new file mode 100644 index 0000000000..7b78e49475 --- /dev/null +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/refastertemplates/RefasterTemplatesTest.java @@ -0,0 +1,81 @@ +package tech.picnic.errorprone.refastertemplates; + +import static java.util.function.Predicate.not; + +import com.google.common.collect.ImmutableSet; +import java.util.stream.Stream; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import tech.picnic.errorprone.refaster.test.RefasterTemplateCollection; + +final class RefasterTemplatesTest { + /** The names of all Refaster template groups defined in this module. */ + private static final ImmutableSet> TEMPLATE_COLLECTIONS = + ImmutableSet.of( + AssertJTemplates.class, + AssertJBigDecimalTemplates.class, + AssertJBigIntegerTemplates.class, + AssertJBooleanTemplates.class, + AssertJByteTemplates.class, + AssertJCharSequenceTemplates.class, + AssertJDoubleTemplates.class, + AssertJEnumerableTemplates.class, + AssertJFloatTemplates.class, + AssertJIntegerTemplates.class, + AssertJLongTemplates.class, + AssertJNumberTemplates.class, + AssertJMapTemplates.class, + AssertJObjectTemplates.class, + AssertJOptionalTemplates.class, + AssertJShortTemplates.class, + AssertJStringTemplates.class, + AssertJThrowingCallableTemplates.class, + AssortedTemplates.class, + BigDecimalTemplates.class, + CollectionTemplates.class, + ComparatorTemplates.class, + DoubleStreamTemplates.class, + EqualityTemplates.class, + ImmutableListTemplates.class, + ImmutableListMultimapTemplates.class, + ImmutableMapTemplates.class, + ImmutableMultisetTemplates.class, + ImmutableSetTemplates.class, + ImmutableSetMultimapTemplates.class, + ImmutableSortedMapTemplates.class, + ImmutableSortedMultisetTemplates.class, + ImmutableSortedSetTemplates.class, + IntStreamTemplates.class, + JUnitTemplates.class, + LongStreamTemplates.class, + MapEntryTemplates.class, + MockitoTemplates.class, + MultimapTemplates.class, + NullTemplates.class, + OptionalTemplates.class, + PrimitiveTemplates.class, + ReactorTemplates.class, + RxJava2AdapterTemplates.class, + StreamTemplates.class, + StringTemplates.class, + TestNGToAssertJTemplates.class, + TimeTemplates.class, + WebClientTemplates.class); + + // XXX: Create a JUnit extension to automatically discover the template collections in a given + // context to make sure the list is exhaustive. + private static Stream validateTemplateCollectionTestCases() { + // XXX: Drop the filter once we have added tests for AssertJ! We can then also replace this + // method with `@ValueSource(classes = {...})`. + return TEMPLATE_COLLECTIONS.stream() + .filter(not(AssertJTemplates.class::equals)) + .map(Arguments::arguments); + } + + @MethodSource("validateTemplateCollectionTestCases") + @ParameterizedTest + void validateTemplateCollection(Class clazz) { + RefasterTemplateCollection.validate(clazz); + } +} diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBigDecimalTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBigDecimalTemplatesTestInput.java index 370a6cf13b..c8ecc2ecb8 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBigDecimalTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBigDecimalTemplatesTestInput.java @@ -7,6 +7,7 @@ import com.google.common.collect.ImmutableSet; import java.math.BigDecimal; import org.assertj.core.api.AbstractBigDecimalAssert; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssertJBigDecimalTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBigDecimalTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBigDecimalTemplatesTestOutput.java index c3cb6e3f25..9807aa5488 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBigDecimalTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBigDecimalTemplatesTestOutput.java @@ -7,6 +7,7 @@ import com.google.common.collect.ImmutableSet; import java.math.BigDecimal; import org.assertj.core.api.AbstractBigDecimalAssert; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssertJBigDecimalTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBigIntegerTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBigIntegerTemplatesTestInput.java index 7aab3da716..3bbbcf0380 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBigIntegerTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBigIntegerTemplatesTestInput.java @@ -7,6 +7,7 @@ import com.google.common.collect.ImmutableSet; import java.math.BigInteger; import org.assertj.core.api.AbstractBigIntegerAssert; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssertJBigIntegerTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBigIntegerTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBigIntegerTemplatesTestOutput.java index 9106ecdcb2..9674b649dd 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBigIntegerTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBigIntegerTemplatesTestOutput.java @@ -7,6 +7,7 @@ import com.google.common.collect.ImmutableSet; import java.math.BigInteger; import org.assertj.core.api.AbstractBigIntegerAssert; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssertJBigIntegerTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBooleanTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBooleanTemplatesTestInput.java index 1193dc6f0d..9181a58247 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBooleanTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBooleanTemplatesTestInput.java @@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableSet; import org.assertj.core.api.AbstractBooleanAssert; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssertJBooleanTemplatesTest implements RefasterTemplateTestCase { AbstractBooleanAssert testAbstractBooleanAssertIsEqualTo() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBooleanTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBooleanTemplatesTestOutput.java index 110a421c28..da458b13b9 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBooleanTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBooleanTemplatesTestOutput.java @@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableSet; import org.assertj.core.api.AbstractBooleanAssert; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssertJBooleanTemplatesTest implements RefasterTemplateTestCase { AbstractBooleanAssert testAbstractBooleanAssertIsEqualTo() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJByteTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJByteTemplatesTestInput.java index 5c0e7a7834..f9a7b2607e 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJByteTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJByteTemplatesTestInput.java @@ -6,6 +6,7 @@ import com.google.common.collect.ImmutableSet; import org.assertj.core.api.AbstractByteAssert; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssertJByteTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJByteTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJByteTemplatesTestOutput.java index 6bf3250142..ea274127a4 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJByteTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJByteTemplatesTestOutput.java @@ -6,6 +6,7 @@ import com.google.common.collect.ImmutableSet; import org.assertj.core.api.AbstractByteAssert; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssertJByteTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJCharSequenceTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJCharSequenceTemplatesTestInput.java index 5a71e7a6a8..3cad90b1a0 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJCharSequenceTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJCharSequenceTemplatesTestInput.java @@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableSet; import org.assertj.core.api.AbstractAssert; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssertJCharSequenceTemplatesTest implements RefasterTemplateTestCase { void testAssertThatCharSequenceIsEmpty() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJCharSequenceTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJCharSequenceTemplatesTestOutput.java index 6395d7258a..9d0fc29bb3 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJCharSequenceTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJCharSequenceTemplatesTestOutput.java @@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableSet; import org.assertj.core.api.AbstractAssert; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssertJCharSequenceTemplatesTest implements RefasterTemplateTestCase { void testAssertThatCharSequenceIsEmpty() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJDoubleTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJDoubleTemplatesTestInput.java index 95fb107dbf..04eb0c7206 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJDoubleTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJDoubleTemplatesTestInput.java @@ -6,6 +6,7 @@ import com.google.common.collect.ImmutableSet; import org.assertj.core.api.AbstractDoubleAssert; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssertJDoubleTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJDoubleTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJDoubleTemplatesTestOutput.java index d657c3dde8..12ec9c93be 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJDoubleTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJDoubleTemplatesTestOutput.java @@ -6,6 +6,7 @@ import com.google.common.collect.ImmutableSet; import org.assertj.core.api.AbstractDoubleAssert; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssertJDoubleTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJEnumerableTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJEnumerableTemplatesTestInput.java index 693fd1c4af..7374a993eb 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJEnumerableTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJEnumerableTemplatesTestInput.java @@ -5,6 +5,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import org.assertj.core.api.EnumerableAssert; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssertJEnumableTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJEnumerableTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJEnumerableTemplatesTestOutput.java index 5b7e9013e4..598a38168f 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJEnumerableTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJEnumerableTemplatesTestOutput.java @@ -5,6 +5,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import org.assertj.core.api.EnumerableAssert; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssertJEnumableTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJFloatTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJFloatTemplatesTestInput.java index 88ced7b924..54b4fac623 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJFloatTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJFloatTemplatesTestInput.java @@ -6,6 +6,7 @@ import com.google.common.collect.ImmutableSet; import org.assertj.core.api.AbstractFloatAssert; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssertJFloatTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJFloatTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJFloatTemplatesTestOutput.java index 01dc692db7..40b9626372 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJFloatTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJFloatTemplatesTestOutput.java @@ -6,6 +6,7 @@ import com.google.common.collect.ImmutableSet; import org.assertj.core.api.AbstractFloatAssert; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssertJFloatTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJIntegerTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJIntegerTemplatesTestInput.java index 320496d205..6b4b7a38c3 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJIntegerTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJIntegerTemplatesTestInput.java @@ -6,6 +6,7 @@ import com.google.common.collect.ImmutableSet; import org.assertj.core.api.AbstractIntegerAssert; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssertJIntegerTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJIntegerTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJIntegerTemplatesTestOutput.java index da912f04e3..87613912ff 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJIntegerTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJIntegerTemplatesTestOutput.java @@ -6,6 +6,7 @@ import com.google.common.collect.ImmutableSet; import org.assertj.core.api.AbstractIntegerAssert; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssertJIntegerTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJLongTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJLongTemplatesTestInput.java index cee37b2227..b55a52774f 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJLongTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJLongTemplatesTestInput.java @@ -6,6 +6,7 @@ import com.google.common.collect.ImmutableSet; import org.assertj.core.api.AbstractLongAssert; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssertJLongTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJLongTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJLongTemplatesTestOutput.java index 5a54440edf..1c7a851983 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJLongTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJLongTemplatesTestOutput.java @@ -6,6 +6,7 @@ import com.google.common.collect.ImmutableSet; import org.assertj.core.api.AbstractLongAssert; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssertJLongTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJMapTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJMapTemplatesTestInput.java index 020b18a476..84d9fb02d3 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJMapTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJMapTemplatesTestInput.java @@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableMap; import org.assertj.core.api.AbstractMapAssert; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssertJMapTemplatesTest implements RefasterTemplateTestCase { AbstractMapAssert diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJMapTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJMapTemplatesTestOutput.java index ff2a771151..65d1a3b4cb 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJMapTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJMapTemplatesTestOutput.java @@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableMap; import org.assertj.core.api.AbstractMapAssert; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssertJMapTemplatesTest implements RefasterTemplateTestCase { AbstractMapAssert diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJNumberTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJNumberTemplatesTestInput.java index 22193c9dcd..d92b1cdf14 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJNumberTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJNumberTemplatesTestInput.java @@ -6,6 +6,7 @@ import java.math.BigDecimal; import java.math.BigInteger; import org.assertj.core.api.NumberAssert; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssertJNumberTemplatesTest implements RefasterTemplateTestCase { ImmutableSet> testNumberAssertIsPositive() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJNumberTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJNumberTemplatesTestOutput.java index a01f1b490f..72b9f27ce4 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJNumberTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJNumberTemplatesTestOutput.java @@ -6,6 +6,7 @@ import java.math.BigDecimal; import java.math.BigInteger; import org.assertj.core.api.NumberAssert; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssertJNumberTemplatesTest implements RefasterTemplateTestCase { ImmutableSet> testNumberAssertIsPositive() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJObjectTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJObjectTemplatesTestInput.java index 521143a501..391c6b1228 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJObjectTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJObjectTemplatesTestInput.java @@ -3,6 +3,7 @@ import static org.assertj.core.api.Assertions.assertThat; import org.assertj.core.api.AbstractAssert; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssertJObjectTemplatesTest implements RefasterTemplateTestCase { AbstractAssert testAssertThatIsInstanceOf() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJObjectTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJObjectTemplatesTestOutput.java index 35a273a7d0..3e68603b4a 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJObjectTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJObjectTemplatesTestOutput.java @@ -3,6 +3,7 @@ import static org.assertj.core.api.Assertions.assertThat; import org.assertj.core.api.AbstractAssert; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssertJObjectTemplatesTest implements RefasterTemplateTestCase { AbstractAssert testAssertThatIsInstanceOf() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJOptionalTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJOptionalTemplatesTestInput.java index 86f91856b5..ca6be8ec0b 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJOptionalTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJOptionalTemplatesTestInput.java @@ -6,6 +6,7 @@ import java.util.Optional; import org.assertj.core.api.AbstractAssert; import org.assertj.core.api.OptionalAssert; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssertJOptionalTemplatesTest implements RefasterTemplateTestCase { AbstractAssert testAssertThatOptional() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJOptionalTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJOptionalTemplatesTestOutput.java index 29bb84d576..df5f706c31 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJOptionalTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJOptionalTemplatesTestOutput.java @@ -6,6 +6,7 @@ import java.util.Optional; import org.assertj.core.api.AbstractAssert; import org.assertj.core.api.OptionalAssert; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssertJOptionalTemplatesTest implements RefasterTemplateTestCase { AbstractAssert testAssertThatOptional() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJShortTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJShortTemplatesTestInput.java index c79f5d2f8f..e4fc739373 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJShortTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJShortTemplatesTestInput.java @@ -6,6 +6,7 @@ import com.google.common.collect.ImmutableSet; import org.assertj.core.api.AbstractShortAssert; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssertJShortTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJShortTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJShortTemplatesTestOutput.java index d051c08034..58beb71e24 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJShortTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJShortTemplatesTestOutput.java @@ -6,6 +6,7 @@ import com.google.common.collect.ImmutableSet; import org.assertj.core.api.AbstractShortAssert; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssertJShortTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJStringTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJStringTemplatesTestInput.java index 4023eb1f60..e699740a83 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJStringTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJStringTemplatesTestInput.java @@ -4,6 +4,7 @@ import org.assertj.core.api.AbstractAssert; import org.assertj.core.api.AbstractStringAssert; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssertJStringTemplatesTest implements RefasterTemplateTestCase { void testAbstractStringAssertStringIsEmpty() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJStringTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJStringTemplatesTestOutput.java index 759b00f0cb..1e048f94a2 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJStringTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJStringTemplatesTestOutput.java @@ -4,6 +4,7 @@ import org.assertj.core.api.AbstractAssert; import org.assertj.core.api.AbstractStringAssert; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssertJStringTemplatesTest implements RefasterTemplateTestCase { void testAbstractStringAssertStringIsEmpty() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJThrowingCallableTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJThrowingCallableTemplatesTestInput.java index 4101c67f75..b4c202ec09 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJThrowingCallableTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJThrowingCallableTemplatesTestInput.java @@ -10,6 +10,7 @@ import com.google.common.collect.ImmutableSet; import org.assertj.core.api.AbstractObjectAssert; import org.assertj.core.api.AbstractThrowableAssert; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssertJThrowingCallableTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJThrowingCallableTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJThrowingCallableTemplatesTestOutput.java index 5b65c5f6c4..eed84befbb 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJThrowingCallableTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJThrowingCallableTemplatesTestOutput.java @@ -11,6 +11,7 @@ import java.io.IOException; import org.assertj.core.api.AbstractObjectAssert; import org.assertj.core.api.AbstractThrowableAssert; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssertJThrowingCallableTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssortedTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssortedTemplatesTestInput.java index efa49a9753..d4023e4546 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssortedTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssortedTemplatesTestInput.java @@ -17,6 +17,7 @@ import java.util.HashSet; import java.util.Map; import java.util.stream.Stream; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssortedTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssortedTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssortedTemplatesTestOutput.java index ea92986131..10809a7134 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssortedTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssortedTemplatesTestOutput.java @@ -21,6 +21,7 @@ import java.util.Map; import java.util.Objects; import java.util.stream.Stream; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class AssortedTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/BigDecimalTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/BigDecimalTemplatesTestInput.java index 8ccae257f3..878b1bac28 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/BigDecimalTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/BigDecimalTemplatesTestInput.java @@ -2,6 +2,7 @@ import com.google.common.collect.ImmutableSet; import java.math.BigDecimal; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class BigDecimalTemplatesTest implements RefasterTemplateTestCase { ImmutableSet testBigDecimalZero() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/BigDecimalTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/BigDecimalTemplatesTestOutput.java index e92630e76a..1a379ce9f7 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/BigDecimalTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/BigDecimalTemplatesTestOutput.java @@ -2,6 +2,7 @@ import com.google.common.collect.ImmutableSet; import java.math.BigDecimal; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class BigDecimalTemplatesTest implements RefasterTemplateTestCase { ImmutableSet testBigDecimalZero() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/CollectionTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/CollectionTemplatesTestInput.java index 33421b1e7f..b2509efd1b 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/CollectionTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/CollectionTemplatesTestInput.java @@ -12,6 +12,7 @@ import java.util.Optional; import java.util.TreeSet; import java.util.stream.Stream; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class CollectionTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/CollectionTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/CollectionTemplatesTestOutput.java index 0ae34afdb2..cbbf3dbdae 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/CollectionTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/CollectionTemplatesTestOutput.java @@ -12,6 +12,7 @@ import java.util.Optional; import java.util.TreeSet; import java.util.stream.Stream; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class CollectionTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ComparatorTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ComparatorTemplatesTestInput.java index 406b1da7b3..39c10f8add 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ComparatorTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ComparatorTemplatesTestInput.java @@ -8,6 +8,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.Comparator; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class ComparatorTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ComparatorTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ComparatorTemplatesTestOutput.java index 77da76b222..366da20139 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ComparatorTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ComparatorTemplatesTestOutput.java @@ -10,6 +10,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.Comparator; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class ComparatorTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/DoubleStreamTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/DoubleStreamTemplatesTestInput.java index fe20205972..37bd64f8f7 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/DoubleStreamTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/DoubleStreamTemplatesTestInput.java @@ -6,6 +6,7 @@ import java.util.function.DoublePredicate; import java.util.stream.DoubleStream; import java.util.stream.Stream; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class DoubleStreamTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/DoubleStreamTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/DoubleStreamTemplatesTestOutput.java index 75b0e8993f..de39e49000 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/DoubleStreamTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/DoubleStreamTemplatesTestOutput.java @@ -6,6 +6,7 @@ import java.util.function.DoublePredicate; import java.util.stream.DoubleStream; import java.util.stream.Stream; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class DoubleStreamTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/EqualityTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/EqualityTemplatesTestInput.java index f331f88586..f8299fc8ad 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/EqualityTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/EqualityTemplatesTestInput.java @@ -5,6 +5,7 @@ import java.math.RoundingMode; import java.util.Objects; import java.util.stream.Stream; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class EqualityTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/EqualityTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/EqualityTemplatesTestOutput.java index c5ac531191..f142f465f1 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/EqualityTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/EqualityTemplatesTestOutput.java @@ -5,6 +5,7 @@ import java.math.RoundingMode; import java.util.Objects; import java.util.stream.Stream; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class EqualityTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableListMultimapTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableListMultimapTemplatesTestInput.java index be01cdaf0e..f840b67d17 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableListMultimapTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableListMultimapTemplatesTestInput.java @@ -16,6 +16,7 @@ import com.google.common.collect.TreeMultimap; import java.util.Map; import java.util.stream.Stream; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class ImmutableListMultimapTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableListMultimapTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableListMultimapTemplatesTestOutput.java index cdbb663ea8..7f7e7888b0 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableListMultimapTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableListMultimapTemplatesTestOutput.java @@ -16,6 +16,7 @@ import com.google.common.collect.TreeMultimap; import java.util.Map; import java.util.stream.Stream; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class ImmutableListMultimapTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableListTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableListTemplatesTestInput.java index 1a93261fd8..0afd20b0e1 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableListTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableListTemplatesTestInput.java @@ -11,6 +11,7 @@ import java.util.Comparator; import java.util.List; import java.util.stream.Stream; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class ImmutableListTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableListTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableListTemplatesTestOutput.java index 1ba66ba42e..915ab1e1df 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableListTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableListTemplatesTestOutput.java @@ -12,6 +12,7 @@ import java.util.Comparator; import java.util.List; import java.util.stream.Stream; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class ImmutableListTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableMapTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableMapTemplatesTestInput.java index 5995d955d7..b2667b9f58 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableMapTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableMapTemplatesTestInput.java @@ -12,6 +12,7 @@ import java.util.Collections; import java.util.Map; import java.util.stream.Stream; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class ImmutableMapTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableMapTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableMapTemplatesTestOutput.java index 36d7b5bdae..77153c7466 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableMapTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableMapTemplatesTestOutput.java @@ -12,6 +12,7 @@ import java.util.Collections; import java.util.Map; import java.util.stream.Stream; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class ImmutableMapTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableMultisetTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableMultisetTemplatesTestInput.java index ef50b18791..92f4ed84f1 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableMultisetTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableMultisetTemplatesTestInput.java @@ -8,6 +8,7 @@ import com.google.common.collect.Streams; import java.util.Arrays; import java.util.stream.Stream; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class ImmutableMultisetTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableMultisetTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableMultisetTemplatesTestOutput.java index 6004eafaf4..84f5122d84 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableMultisetTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableMultisetTemplatesTestOutput.java @@ -8,6 +8,7 @@ import com.google.common.collect.Streams; import java.util.Arrays; import java.util.stream.Stream; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class ImmutableMultisetTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSetMultimapTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSetMultimapTemplatesTestInput.java index 3d3ac31850..2f2cd08f0c 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSetMultimapTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSetMultimapTemplatesTestInput.java @@ -13,6 +13,7 @@ import com.google.common.collect.TreeMultimap; import java.util.Map; import java.util.stream.Stream; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class ImmutableSetMultimapTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSetMultimapTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSetMultimapTemplatesTestOutput.java index 647d9b96b3..f887977a8b 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSetMultimapTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSetMultimapTemplatesTestOutput.java @@ -13,6 +13,7 @@ import com.google.common.collect.TreeMultimap; import java.util.Map; import java.util.stream.Stream; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class ImmutableSetMultimapTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSetTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSetTemplatesTestInput.java index 29891c942b..d2b38ad2ac 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSetTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSetTemplatesTestInput.java @@ -10,6 +10,7 @@ import java.util.Collections; import java.util.Set; import java.util.stream.Stream; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class ImmutableSetTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSetTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSetTemplatesTestOutput.java index 3943f5908f..e6ad2e44ad 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSetTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSetTemplatesTestOutput.java @@ -10,6 +10,7 @@ import java.util.Collections; import java.util.Set; import java.util.stream.Stream; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class ImmutableSetTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedMapTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedMapTemplatesTestInput.java index 1443707ece..a2df4ae2b0 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedMapTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedMapTemplatesTestInput.java @@ -10,6 +10,7 @@ import java.util.Comparator; import java.util.Map; import java.util.stream.Stream; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class ImmutableSortedMapTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedMapTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedMapTemplatesTestOutput.java index 98c212f89f..7f394fa1f1 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedMapTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedMapTemplatesTestOutput.java @@ -10,6 +10,7 @@ import java.util.Comparator; import java.util.Map; import java.util.stream.Stream; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class ImmutableSortedMapTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedMultisetTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedMultisetTemplatesTestInput.java index f42fd53211..085fb1e8c6 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedMultisetTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedMultisetTemplatesTestInput.java @@ -11,6 +11,7 @@ import java.util.Arrays; import java.util.Comparator; import java.util.stream.Stream; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class ImmutableSortedMultisetTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedMultisetTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedMultisetTemplatesTestOutput.java index 818a933154..843c2922e6 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedMultisetTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedMultisetTemplatesTestOutput.java @@ -11,6 +11,7 @@ import java.util.Arrays; import java.util.Comparator; import java.util.stream.Stream; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class ImmutableSortedMultisetTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedSetTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedSetTemplatesTestInput.java index 02181575c0..4a90a87457 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedSetTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedSetTemplatesTestInput.java @@ -10,6 +10,7 @@ import java.util.Arrays; import java.util.Comparator; import java.util.stream.Stream; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class ImmutableSortedSetTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedSetTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedSetTemplatesTestOutput.java index 2d696c95fe..b944a2ef31 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedSetTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedSetTemplatesTestOutput.java @@ -10,6 +10,7 @@ import java.util.Arrays; import java.util.Comparator; import java.util.stream.Stream; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class ImmutableSortedSetTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/IntStreamTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/IntStreamTemplatesTestInput.java index fe7d93763d..03cf380352 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/IntStreamTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/IntStreamTemplatesTestInput.java @@ -6,6 +6,7 @@ import java.util.function.IntPredicate; import java.util.stream.IntStream; import java.util.stream.Stream; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class IntStreamTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/IntStreamTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/IntStreamTemplatesTestOutput.java index 30260b53d6..c40930f27a 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/IntStreamTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/IntStreamTemplatesTestOutput.java @@ -6,6 +6,7 @@ import java.util.function.IntPredicate; import java.util.stream.IntStream; import java.util.stream.Stream; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class IntStreamTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/JUnitTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/JUnitTemplatesTestInput.java index 88d26b05f4..77c83e8916 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/JUnitTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/JUnitTemplatesTestInput.java @@ -2,6 +2,7 @@ import com.google.common.collect.ImmutableSet; import org.junit.jupiter.params.provider.Arguments; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class JUnitTemplatesTest implements RefasterTemplateTestCase { ImmutableSet testArgumentsEnumeration() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/JUnitTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/JUnitTemplatesTestOutput.java index 6e8e77582c..13151144b2 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/JUnitTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/JUnitTemplatesTestOutput.java @@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableSet; import org.junit.jupiter.params.provider.Arguments; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class JUnitTemplatesTest implements RefasterTemplateTestCase { ImmutableSet testArgumentsEnumeration() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/LongStreamTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/LongStreamTemplatesTestInput.java index fd284c65fe..51a32a1d3a 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/LongStreamTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/LongStreamTemplatesTestInput.java @@ -6,6 +6,7 @@ import java.util.function.LongPredicate; import java.util.stream.LongStream; import java.util.stream.Stream; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class LongStreamTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/LongStreamTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/LongStreamTemplatesTestOutput.java index 6b1b54229a..c87219b7fd 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/LongStreamTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/LongStreamTemplatesTestOutput.java @@ -6,6 +6,7 @@ import java.util.function.LongPredicate; import java.util.stream.LongStream; import java.util.stream.Stream; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class LongStreamTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MapEntryTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MapEntryTemplatesTestInput.java index c9203ab5ee..e829d26833 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MapEntryTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MapEntryTemplatesTestInput.java @@ -5,6 +5,7 @@ import java.util.AbstractMap; import java.util.Comparator; import java.util.Map; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class MapEntryTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MapEntryTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MapEntryTemplatesTestOutput.java index bf1327aeb7..056bb169ee 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MapEntryTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MapEntryTemplatesTestOutput.java @@ -8,6 +8,7 @@ import java.util.AbstractMap; import java.util.Comparator; import java.util.Map; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class MapEntryTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MockitoTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MockitoTemplatesTestInput.java index 676a15f5c1..f48eec9c48 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MockitoTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MockitoTemplatesTestInput.java @@ -6,6 +6,7 @@ import com.google.common.collect.ImmutableSet; import org.mockito.verification.VerificationMode; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class MockitoTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MockitoTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MockitoTemplatesTestOutput.java index 258fab726a..367ffba744 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MockitoTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MockitoTemplatesTestOutput.java @@ -7,6 +7,7 @@ import com.google.common.collect.ImmutableSet; import org.mockito.verification.VerificationMode; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class MockitoTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MultimapTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MultimapTemplatesTestInput.java index 5528056bbd..3348249ba7 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MultimapTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MultimapTemplatesTestInput.java @@ -6,6 +6,7 @@ import com.google.common.collect.Multimaps; import java.util.Collection; import java.util.Set; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class MultimapTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MultimapTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MultimapTemplatesTestOutput.java index 5c027237fb..0aeab3fc01 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MultimapTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MultimapTemplatesTestOutput.java @@ -6,6 +6,7 @@ import com.google.common.collect.Multimaps; import java.util.Collection; import java.util.Set; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class MultimapTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/NullTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/NullTemplatesTestInput.java index 7b28ad4ae0..ac02a7b084 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/NullTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/NullTemplatesTestInput.java @@ -3,6 +3,7 @@ import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableSet; import java.util.stream.Stream; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class NullTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/NullTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/NullTemplatesTestOutput.java index cda3ab9634..617aa31dbc 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/NullTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/NullTemplatesTestOutput.java @@ -6,6 +6,7 @@ import com.google.common.collect.ImmutableSet; import java.util.Objects; import java.util.stream.Stream; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class NullTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/OptionalTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/OptionalTemplatesTestInput.java index a954478eb0..d32ba426d2 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/OptionalTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/OptionalTemplatesTestInput.java @@ -5,6 +5,7 @@ import java.util.Optional; import java.util.function.Function; import java.util.stream.Stream; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class OptionalTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/OptionalTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/OptionalTemplatesTestOutput.java index 100d8aca28..d7e4f8573f 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/OptionalTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/OptionalTemplatesTestOutput.java @@ -7,6 +7,7 @@ import java.util.Optional; import java.util.function.Function; import java.util.stream.Stream; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class OptionalTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/PrimitiveTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/PrimitiveTemplatesTestInput.java index 1580b6063a..d41931b501 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/PrimitiveTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/PrimitiveTemplatesTestInput.java @@ -2,6 +2,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.primitives.Ints; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class PrimitiveTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/PrimitiveTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/PrimitiveTemplatesTestOutput.java index 91caf7c011..ba2647ad83 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/PrimitiveTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/PrimitiveTemplatesTestOutput.java @@ -2,6 +2,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.primitives.Ints; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class PrimitiveTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ReactorTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ReactorTemplatesTestInput.java index ca0bd1d486..0fc64f7670 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ReactorTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ReactorTemplatesTestInput.java @@ -11,6 +11,7 @@ import reactor.core.publisher.Mono; import reactor.test.StepVerifier; import reactor.test.publisher.PublisherProbe; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class ReactorTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ReactorTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ReactorTemplatesTestOutput.java index 90f73ae0ba..18fd8b92b9 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ReactorTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ReactorTemplatesTestOutput.java @@ -12,6 +12,7 @@ import reactor.core.publisher.Mono; import reactor.test.StepVerifier; import reactor.test.publisher.PublisherProbe; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class ReactorTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/RxJava2AdapterTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/RxJava2AdapterTemplatesTestInput.java index 7169ebfb98..42fc8b73c6 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/RxJava2AdapterTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/RxJava2AdapterTemplatesTestInput.java @@ -12,6 +12,7 @@ import reactor.adapter.rxjava.RxJava2Adapter; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class RxJava2AdapterTemplatesTest implements RefasterTemplateTestCase { ImmutableSet> testCompletableToMono() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/RxJava2AdapterTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/RxJava2AdapterTemplatesTestOutput.java index 4a523d60e6..6ad2980890 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/RxJava2AdapterTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/RxJava2AdapterTemplatesTestOutput.java @@ -12,6 +12,7 @@ import reactor.adapter.rxjava.RxJava2Adapter; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class RxJava2AdapterTemplatesTest implements RefasterTemplateTestCase { ImmutableSet> testCompletableToMono() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/StreamTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/StreamTemplatesTestInput.java index 2384fa9409..f59538c6b0 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/StreamTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/StreamTemplatesTestInput.java @@ -11,6 +11,7 @@ import java.util.Optional; import java.util.function.Predicate; import java.util.stream.Stream; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class StreamTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/StreamTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/StreamTemplatesTestOutput.java index 071f789045..c41746138d 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/StreamTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/StreamTemplatesTestOutput.java @@ -13,6 +13,7 @@ import java.util.Optional; import java.util.function.Predicate; import java.util.stream.Stream; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class StreamTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/StringTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/StringTemplatesTestInput.java index 3d2b50ec31..bbf600371a 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/StringTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/StringTemplatesTestInput.java @@ -12,6 +12,7 @@ import java.util.Arrays; import java.util.Optional; import java.util.stream.Stream; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class StringTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/StringTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/StringTemplatesTestOutput.java index 4f9067c88c..b37280462f 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/StringTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/StringTemplatesTestOutput.java @@ -13,6 +13,7 @@ import java.util.Arrays; import java.util.Optional; import java.util.stream.Stream; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class StringTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/TestNGToAssertJTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/TestNGToAssertJTemplatesTestInput.java index 67bc31e03c..34d0a9fd48 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/TestNGToAssertJTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/TestNGToAssertJTemplatesTestInput.java @@ -17,6 +17,7 @@ import com.google.common.collect.Iterators; import java.util.ArrayList; import java.util.Collections; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class TestNGToAssertJTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/TestNGToAssertJTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/TestNGToAssertJTemplatesTestOutput.java index 8e10a5ef06..496620306b 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/TestNGToAssertJTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/TestNGToAssertJTemplatesTestOutput.java @@ -22,6 +22,7 @@ import com.google.common.collect.Iterators; import java.util.ArrayList; import java.util.Collections; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class TestNGToAssertJTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/TimeTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/TimeTemplatesTestInput.java index f212564c56..09060a69b1 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/TimeTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/TimeTemplatesTestInput.java @@ -13,6 +13,7 @@ import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.time.temporal.ChronoUnit; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class TimeTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/TimeTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/TimeTemplatesTestOutput.java index b4215e599b..215c93fe8c 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/TimeTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/TimeTemplatesTestOutput.java @@ -13,6 +13,7 @@ import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.time.temporal.ChronoUnit; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class TimeTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/WebClientTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/WebClientTemplatesTestInput.java index fd33f65edb..323899bb31 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/WebClientTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/WebClientTemplatesTestInput.java @@ -11,6 +11,7 @@ import com.google.common.collect.ImmutableSet; import org.springframework.test.web.reactive.server.WebTestClient; import org.springframework.web.reactive.function.client.WebClient; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class WebClientTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/WebClientTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/WebClientTemplatesTestOutput.java index 4f3685963d..9e0d57831d 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/WebClientTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/WebClientTemplatesTestOutput.java @@ -11,6 +11,7 @@ import com.google.common.collect.ImmutableSet; import org.springframework.test.web.reactive.server.WebTestClient; import org.springframework.web.reactive.function.client.WebClient; +import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; final class WebClientTemplatesTest implements RefasterTemplateTestCase { @Override diff --git a/pom.xml b/pom.xml index cdc945dbdd..123f638701 100644 --- a/pom.xml +++ b/pom.xml @@ -41,7 +41,9 @@ error-prone-contrib refaster-compiler + refaster-runner refaster-support + refaster-test-support @@ -196,11 +198,21 @@ refaster-compiler ${project.version} + + ${project.groupId} + refaster-runner + ${project.version} + ${project.groupId} refaster-support ${project.version} + + ${project.groupId} + refaster-test-support + ${project.version} + com.fasterxml.jackson jackson-bom @@ -453,6 +465,9 @@ fmt-maven-plugin 2.19 + + ${basedir}/src/test/resources + never false @@ -1353,6 +1368,11 @@ error-prone-contrib ${project.version} + + ${project.groupId} + refaster-runner + ${project.version} + diff --git a/refaster-runner/pom.xml b/refaster-runner/pom.xml new file mode 100644 index 0000000000..1fd6e0fdd8 --- /dev/null +++ b/refaster-runner/pom.xml @@ -0,0 +1,99 @@ + + + 4.0.0 + + + tech.picnic.error-prone-support + error-prone-support + 0.0.1-SNAPSHOT + + + refaster-runner + + Picnic :: Error Prone Support :: Refaster Runner + Exposes Refaster templates found on the classpath through a regular Error Prone check. + + + + ${groupId.error-prone} + error_prone_annotation + provided + + + ${groupId.error-prone} + error_prone_annotations + provided + + + ${groupId.error-prone} + error_prone_check_api + provided + + + ${project.groupId} + refaster-compiler + + provided + + + com.google.auto.service + auto-service-annotations + provided + + + com.google.code.findbugs + jsr305 + provided + + + com.google.errorprone + javac + provided + + + com.google.guava + guava + provided + + + org.assertj + assertj-core + test + + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + ${project.groupId} + refaster-compiler + ${project.version} + + + + -Xplugin:RefasterRuleCompiler + + + + + + + diff --git a/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/CodeTransformers.java b/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/CodeTransformers.java new file mode 100644 index 0000000000..f3bde9fd0c --- /dev/null +++ b/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/CodeTransformers.java @@ -0,0 +1,98 @@ +package tech.picnic.errorprone.refaster.runner; + +import com.google.common.base.Suppliers; +import com.google.common.collect.ImmutableListMultimap; +import com.google.common.collect.ImmutableSet; +import com.google.common.reflect.ClassPath; +import com.google.common.reflect.ClassPath.ResourceInfo; +import com.google.errorprone.CodeTransformer; +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.io.UncheckedIOException; +import java.util.NoSuchElementException; +import java.util.Optional; +import java.util.function.Supplier; + +/** + * Scans the classpath for {@value #REFASTER_TEMPLATE_SUFFIX} files and loads them as {@link + * CodeTransformer}s. + */ +public final class CodeTransformers { + private static final String REFASTER_TEMPLATE_SUFFIX = ".refaster"; + private static final Supplier> + ALL_CODE_TRANSFORMERS = Suppliers.memoize(CodeTransformers::loadAllCodeTransformers); + + private CodeTransformers() {} + + /** + * Returns all Refaster {@link CodeTransformer}s found on the classpath. + * + *

This method returns a cached view; all invocations except the first are very cheap. + * + * @return A mapping from Refaster template names to associated {@link CodeTransformer}s. + */ + public static ImmutableListMultimap getAllCodeTransformers() { + return ALL_CODE_TRANSFORMERS.get(); + } + + /** + * Scans the classpath for compiled Refaster templates and returns the associated deserialized + * {@link CodeTransformer}s, indexed by their name. + * + * @return A mapping from Refaster template names to associated {@link CodeTransformer}s. + */ + private static ImmutableListMultimap loadAllCodeTransformers() { + ImmutableListMultimap.Builder transformers = + ImmutableListMultimap.builder(); + + for (ResourceInfo resource : getClassPathResources()) { + getRefasterTemplateName(resource) + .ifPresent( + templateName -> + loadCodeTransformer(resource) + .ifPresent(transformer -> transformers.put(templateName, transformer))); + } + + return transformers.build(); + } + + private static ImmutableSet getClassPathResources() { + try { + return ClassPath.from(CodeTransformers.class.getClassLoader()).getResources(); + } catch (IOException e) { + throw new UncheckedIOException("Failed to scan classpath for resources", e); + } + } + + private static Optional getRefasterTemplateName(ResourceInfo resource) { + String resourceName = resource.getResourceName(); + if (!resourceName.endsWith(REFASTER_TEMPLATE_SUFFIX)) { + return Optional.empty(); + } + + int lastPathSeparator = resourceName.lastIndexOf('/'); + int beginIndex = lastPathSeparator < 0 ? 0 : lastPathSeparator + 1; + int endIndex = resourceName.length() - REFASTER_TEMPLATE_SUFFIX.length(); + return Optional.of(resourceName.substring(beginIndex, endIndex)); + } + + private static Optional loadCodeTransformer(ResourceInfo resource) { + try (InputStream in = resource.url().openStream(); + ObjectInputStream ois = new ObjectInputStream(in)) { + @SuppressWarnings("BanSerializableRead" /* Part of the Refaster API. */) + CodeTransformer codeTransformer = (CodeTransformer) ois.readObject(); + return Optional.of(codeTransformer); + } catch (NoSuchElementException e) { + /* For some reason we can't load the resource. Skip it. */ + // XXX: Should we log this? + return Optional.empty(); + } catch (ClassCastException e) { + /* This resource does not appear to be compatible with the current classpath. */ + // XXX: Should we log this? + return Optional.empty(); + } catch (ClassNotFoundException | IOException e) { + throw new IllegalStateException("Can't load `CodeTransformer` from " + resource, e); + } + } +} diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/Refaster.java b/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/Refaster.java similarity index 70% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/Refaster.java rename to refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/Refaster.java index 6be7d2a506..b6e7d19600 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/Refaster.java +++ b/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/Refaster.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.bugpatterns; +package tech.picnic.errorprone.refaster.runner; import static com.google.common.collect.ImmutableList.toImmutableList; import static com.google.common.collect.ImmutableRangeSet.toImmutableRangeSet; @@ -8,24 +8,20 @@ import static java.util.function.Predicate.not; import com.google.auto.service.AutoService; -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableCollection; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableListMultimap; import com.google.common.collect.ImmutableRangeSet; -import com.google.common.collect.ImmutableSet; import com.google.common.collect.Range; import com.google.common.collect.RangeSet; import com.google.common.collect.TreeRangeSet; -import com.google.common.reflect.ClassPath; -import com.google.common.reflect.ClassPath.ResourceInfo; import com.google.errorprone.BugPattern; import com.google.errorprone.CodeTransformer; import com.google.errorprone.CompositeCodeTransformer; import com.google.errorprone.ErrorProneFlags; import com.google.errorprone.SubContext; import com.google.errorprone.VisitorState; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.errorprone.bugpatterns.BugChecker; import com.google.errorprone.bugpatterns.BugChecker.CompilationUnitTreeMatcher; import com.google.errorprone.fixes.Replacement; @@ -33,17 +29,10 @@ import com.sun.source.tree.CompilationUnitTree; import com.sun.tools.javac.tree.EndPosTable; import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; -import java.io.IOException; -import java.io.InputStream; -import java.io.ObjectInputStream; -import java.io.UncheckedIOException; import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.Map; -import java.util.NoSuchElementException; -import java.util.Optional; -import java.util.function.Supplier; import java.util.regex.Pattern; import java.util.stream.Stream; @@ -62,13 +51,10 @@ severity = SUGGESTION, tags = SIMPLIFICATION) public final class Refaster extends BugChecker implements CompilationUnitTreeMatcher { - private static final long serialVersionUID = 1L; - private static final String REFASTER_TEMPLATE_SUFFIX = ".refaster"; - private static final String INCLUDED_TEMPLATES_PATTERN_FLAG = "Refaster:NamePattern"; + /** Flag to pass a pattern that restricts which Refaster templates are loaded. */ + public static final String INCLUDED_TEMPLATES_PATTERN_FLAG = "Refaster:NamePattern"; - @VisibleForTesting - static final Supplier> ALL_CODE_TRANSFORMERS = - Suppliers.memoize(Refaster::loadAllCodeTransformers); + private static final long serialVersionUID = 1L; private final CodeTransformer codeTransformer; @@ -86,6 +72,7 @@ public Refaster(ErrorProneFlags flags) { codeTransformer = createCompositeCodeTransformer(flags); } + @CanIgnoreReturnValue @Override public Description matchCompilationUnit(CompilationUnitTree tree, VisitorState state) { /* First, collect all matches. */ @@ -160,7 +147,8 @@ private static Stream getReplacements( } private static CodeTransformer createCompositeCodeTransformer(ErrorProneFlags flags) { - ImmutableListMultimap allTransformers = ALL_CODE_TRANSFORMERS.get(); + ImmutableListMultimap allTransformers = + CodeTransformers.getAllCodeTransformers(); return CompositeCodeTransformer.compose( flags .get(INCLUDED_TEMPLATES_PATTERN_FLAG) @@ -177,54 +165,4 @@ private static ImmutableList filterCodeTransformers( .map(Map.Entry::getValue) .collect(toImmutableList()); } - - private static ImmutableListMultimap loadAllCodeTransformers() { - ImmutableListMultimap.Builder transformers = - ImmutableListMultimap.builder(); - - for (ResourceInfo resource : getClassPathResources()) { - getRefasterTemplateName(resource) - .ifPresent( - templateName -> - loadCodeTransformer(resource) - .ifPresent(transformer -> transformers.put(templateName, transformer))); - } - - return transformers.build(); - } - - private static ImmutableSet getClassPathResources() { - try { - return ClassPath.from(Refaster.class.getClassLoader()).getResources(); - } catch (IOException e) { - throw new UncheckedIOException("Failed to scan classpath for resources", e); - } - } - - private static Optional getRefasterTemplateName(ResourceInfo resource) { - String resourceName = resource.getResourceName(); - if (!resourceName.endsWith(REFASTER_TEMPLATE_SUFFIX)) { - return Optional.empty(); - } - - int lastPathSeparator = resourceName.lastIndexOf('/'); - int beginIndex = lastPathSeparator < 0 ? 0 : lastPathSeparator + 1; - int endIndex = resourceName.length() - REFASTER_TEMPLATE_SUFFIX.length(); - return Optional.of(resourceName.substring(beginIndex, endIndex)); - } - - private static Optional loadCodeTransformer(ResourceInfo resource) { - try (InputStream in = resource.url().openStream(); - ObjectInputStream ois = new ObjectInputStream(in)) { - @SuppressWarnings("BanSerializableRead" /* Part of the Refaster API. */) - CodeTransformer codeTransformer = (CodeTransformer) ois.readObject(); - return Optional.of(codeTransformer); - } catch (NoSuchElementException e) { - /* For some reason we can't load the resource. Skip it. */ - // XXX: Should we log this? - return Optional.empty(); - } catch (IOException | ClassNotFoundException e) { - throw new IllegalStateException("Can't load `CodeTransformer` from " + resource, e); - } - } } diff --git a/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/package-info.java b/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/package-info.java new file mode 100644 index 0000000000..dc08a789c6 --- /dev/null +++ b/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/package-info.java @@ -0,0 +1,4 @@ +/** Exposes Refaster templates found on the classpath through a regular Error Prone check. */ +@com.google.errorprone.annotations.CheckReturnValue +@javax.annotation.ParametersAreNonnullByDefault +package tech.picnic.errorprone.refaster.runner; diff --git a/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/CodeTransformersTest.java b/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/CodeTransformersTest.java new file mode 100644 index 0000000000..b4a2732102 --- /dev/null +++ b/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/CodeTransformersTest.java @@ -0,0 +1,17 @@ +package tech.picnic.errorprone.refaster.runner; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + +final class CodeTransformersTest { + /** + * Verifies that {@link CodeTransformers#getAllCodeTransformers()} finds the code transformer + * compiled from {@link FooTemplates} on the classpath. + */ + @Test + void getAllCodeTransformers() { + assertThat(CodeTransformers.getAllCodeTransformers().keySet()) + .containsExactly("FooTemplates$SimpleTemplate"); + } +} diff --git a/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/FooTemplates.java b/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/FooTemplates.java new file mode 100644 index 0000000000..0625275d9f --- /dev/null +++ b/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/FooTemplates.java @@ -0,0 +1,22 @@ +package tech.picnic.errorprone.refaster.runner; + +import com.google.errorprone.refaster.annotation.AfterTemplate; +import com.google.errorprone.refaster.annotation.BeforeTemplate; + +/** An example template collection used to test {@link CodeTransformers}. */ +final class FooTemplates { + private FooTemplates() {} + + /** Simple template for testing purposes. */ + static final class SimpleTemplate { + @BeforeTemplate + boolean before(String string) { + return string.toCharArray().length == 0; + } + + @AfterTemplate + boolean after(String string) { + return string.isEmpty(); + } + } +} diff --git a/refaster-test-support/README.md b/refaster-test-support/README.md new file mode 100644 index 0000000000..7c74158215 --- /dev/null +++ b/refaster-test-support/README.md @@ -0,0 +1,82 @@ +# Refaster test support + +This module provides utilities to validate _Refaster template collections_. A +template collection is a set of Refaster templates represented as static nested +classes, all located in a shared top-level class. + +## What does this module do? + +These utilities allow for validating the rewrites (or absence of rewrites) +performed by Refaster templates. Each collection of Refaster templates defined +in a single top-level class is applied to an input file, and the resulting +rewrites should match the associated output file. + +The validation performed by this module ensures that each Refaster template is +tested, making sure that it matches and transforms code as intended. If a +Refaster template is not covered by a test, if it influences unrelated test +code, or if the associated test doesn't follow certain established standards, +then this irregularity will be reported, and the associated template collection +test will fail. This way, developers receive guidance on how to write Refaster +template tests and assurance that every template is properly tested. + +## How to test a collection of Refaster templates + +In a nutshell, to test a Refaster template collection using the +`RefasterTemplateCollection` class, one should create suitably named input and +output source code files. The collection's Refaster templates are applied to +the input file, and the generated patches must exactly produce the contents of +the associated output file. + +To test Refaster templates, one can create a (parameterized) test for every +class that contains Refaster templates and invoke +`RefasterTemplateCollection#validate`. This test utility applies the Refaster +templates in the collection to a provided input file, and expects the result to +exactly match the contents of a provided output file. + +To adopt this setup, the following requirements must be met: + +- Each Refaster template collection must match the naming convention + `Templates.java`. +- There is a test class with a (parameterized) test method that invokes + `RefasterTemplateCollection#validate` on the template collection(s) to be + validated. +- For every template collection there is an input file matching the naming + convention `TemplatesTestInput.java`. +- For every template collection there is an output file matching the naming + convention `TemplatesTestOutput.java`. +- For every Refaster template in a collection, the associated input and output + files must contain a method that validates the template's behavior. The name + of this method must be derived from the name of the Refaster template it aims + to validate, prefixed with `test` (i.e. `test`). +- Each such method contains at least one expression that matches the + `@BeforeTemplate` of the corresponding Refaster template. As a result, the + output file must contain the same method with an updated expression, in + accordance with the associated `@AfterTemplate`. +- Such methods must not match any _other_ Refaster templates. + +An example directory structure for such a setup is as follows: +``` +src/ + main/ + java/ + tech.picnic.errorprone.refastertemplates + └── ExampleTemplates.java -- Contains multiple Refaster templates. + └── Example1Template + └── Example2Template + test/ + java/ + tech.picnic.errorprone.refastertemplates + └── RefasterCollectionTest.java + -- This test class invokes + -- `RefasterTemplateCollection#validate`. + resources/ + tech.picnic.errorprone.refastertemplates + └── ExampleTemplatesTestInput.java + -- Contains a class named `ExampleTemplatesTest` and + -- two methods named `testExample1Template` and + -- `testExample2Template`. + └── ExampleTemplatesTestOutput.java + -- Contains a class named `ExampleTemplatesTest` and + -- two methods named `testExample1Template` and + -- `testExample2Template`. +``` diff --git a/refaster-test-support/pom.xml b/refaster-test-support/pom.xml new file mode 100644 index 0000000000..b97f3204c7 --- /dev/null +++ b/refaster-test-support/pom.xml @@ -0,0 +1,96 @@ + + + 4.0.0 + + + tech.picnic.error-prone-support + error-prone-support + 0.0.1-SNAPSHOT + + + refaster-test-support + + Picnic :: Error Prone Support :: Refaster Test Support + Opinionated utilities for the testing of Refaster templates. + + + + ${groupId.error-prone} + error_prone_annotation + + + ${groupId.error-prone} + error_prone_annotations + provided + + + ${groupId.error-prone} + error_prone_check_api + + + ${groupId.error-prone} + error_prone_core + test + + + ${groupId.error-prone} + error_prone_test_helpers + + + ${project.groupId} + refaster-runner + + + com.google.auto.service + auto-service-annotations + provided + + + com.google.code.findbugs + jsr305 + provided + + + com.google.errorprone + javac + provided + + + com.google.guava + guava + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.junit.jupiter + junit-jupiter-params + test + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + ${project.groupId} + refaster-compiler + ${project.version} + + + + -Xplugin:RefasterRuleCompiler + + + + + + + diff --git a/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterTemplateCollection.java b/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterTemplateCollection.java new file mode 100644 index 0000000000..63c4b9e104 --- /dev/null +++ b/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterTemplateCollection.java @@ -0,0 +1,298 @@ +package tech.picnic.errorprone.refaster.test; + +import static com.google.common.base.Preconditions.checkState; +import static com.google.common.collect.ImmutableListMultimap.toImmutableListMultimap; +import static com.google.common.collect.ImmutableSet.toImmutableSet; +import static com.google.common.collect.ImmutableSortedSet.toImmutableSortedSet; +import static com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH; +import static com.google.errorprone.BugPattern.SeverityLevel.ERROR; +import static java.util.Comparator.naturalOrder; +import static tech.picnic.errorprone.refaster.runner.Refaster.INCLUDED_TEMPLATES_PATTERN_FLAG; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableListMultimap; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableRangeMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSortedSet; +import com.google.common.collect.Iterables; +import com.google.common.collect.Range; +import com.google.common.collect.Sets; +import com.google.errorprone.BugCheckerRefactoringTestHelper; +import com.google.errorprone.BugPattern; +import com.google.errorprone.ErrorProneFlags; +import com.google.errorprone.SubContext; +import com.google.errorprone.VisitorState; +import com.google.errorprone.bugpatterns.BugChecker; +import com.google.errorprone.bugpatterns.BugChecker.CompilationUnitTreeMatcher; +import com.google.errorprone.fixes.Replacement; +import com.google.errorprone.fixes.SuggestedFix; +import com.google.errorprone.matchers.Description; +import com.google.errorprone.util.ASTHelpers; +import com.sun.source.tree.CompilationUnitTree; +import com.sun.source.tree.LineMap; +import com.sun.source.tree.MethodTree; +import com.sun.source.tree.Tree; +import com.sun.source.util.TreeScanner; +import com.sun.tools.javac.tree.EndPosTable; +import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; +import com.sun.tools.javac.util.Position; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.regex.Pattern; +import javax.annotation.Nullable; +import tech.picnic.errorprone.refaster.runner.CodeTransformers; +import tech.picnic.errorprone.refaster.runner.Refaster; + +/** + * A {@link BugChecker} that applies a Refaster template collection to an associated test input file + * by delegating to the {@link Refaster} checker, and subsequently validates that each template + * modifies exactly one distinct method, as indicated by each method's name. + * + *

The test input and output files must be classpath resources located in the same package as the + * template collection class. Their names are derived from the template collection class by + * suffixing {@code TestInput.java} and {@code TestOutput.java}, respectively. Each test method's + * name must be derived from the template that modifies said method by prefixing {@code test}. + */ +// XXX: This check currently only validates that one `Refaster.anyOf` branch in one +// `@BeforeTemplate` method is covered by a test. Review how we can make sure that _all_ +// `@BeforeTemplate` methods and `Refaster.anyOf` branches are covered. +@BugPattern(summary = "Exercises a Refaster template collection", severity = ERROR) +public final class RefasterTemplateCollection extends BugChecker + implements CompilationUnitTreeMatcher { + private static final long serialVersionUID = 1L; + private static final String TEMPLATE_COLLECTION_FLAG = + "RefasterTemplateCollection:TemplateCollection"; + private static final String TEST_METHOD_NAME_PREFIX = "test"; + + private final ImmutableSortedSet templatesUnderTest; + private final Refaster delegate; + + /** + * Instantiates a {@link RefasterTemplateCollection} instance. + * + * @param flags Any provided command line flags. + */ + public RefasterTemplateCollection(ErrorProneFlags flags) { + String templateCollectionUnderTest = getTemplateCollectionUnderTest(flags); + delegate = createRefasterChecker(templateCollectionUnderTest); + templatesUnderTest = getTemplatesUnderTest(templateCollectionUnderTest); + } + + private static String getTemplateCollectionUnderTest(ErrorProneFlags flags) { + return flags + .get(TEMPLATE_COLLECTION_FLAG) + .orElseThrow( + () -> + new IllegalStateException( + String.format( + "Error Prone flag `%s` must be specified", TEMPLATE_COLLECTION_FLAG))); + } + + private static Refaster createRefasterChecker(String templateCollectionUnderTest) { + return new Refaster( + ErrorProneFlags.fromMap( + ImmutableMap.of( + INCLUDED_TEMPLATES_PATTERN_FLAG, + Pattern.quote(templateCollectionUnderTest) + ".*"))); + } + + private static ImmutableSortedSet getTemplatesUnderTest( + String templateCollectionUnderTest) { + return CodeTransformers.getAllCodeTransformers().keySet().stream() + .filter(k -> k.startsWith(templateCollectionUnderTest)) + .map(k -> k.replace(templateCollectionUnderTest + '$', "")) + .collect(toImmutableSortedSet(naturalOrder())); + } + + /** + * Verifies that all Refaster templates in the given collection class are covered by precisely one + * test method, defined explicitly for the purpose of exercising that template. + * + *

Note that a passing test does not guarantee full coverage: this test does not ascertain that + * all {@code com.google.errorprone.refaster.Refaster#anyOf} branches are tested. Likewise for + * {@code com.google.errorprone.refaster.annotation.BeforeTemplate} methods in case there are + * multiple. + * + * @param clazz The Refaster template collection under test. + */ + public static void validate(Class clazz) { + String className = clazz.getSimpleName(); + + BugCheckerRefactoringTestHelper.newInstance(RefasterTemplateCollection.class, clazz) + .setArgs(ImmutableList.of("-XepOpt:" + TEMPLATE_COLLECTION_FLAG + '=' + className)) + .addInput(className + "TestInput.java") + .addOutput(className + "TestOutput.java") + .doTest(TEXT_MATCH); + } + + @Override + public Description matchCompilationUnit(CompilationUnitTree tree, VisitorState state) { + List matches = new ArrayList<>(); + delegate.matchCompilationUnit( + tree, + VisitorState.createForCustomFindingCollection(new SubContext(state.context), matches::add) + .withPath(state.getPath())); + + ImmutableRangeMap indexedMatches = + indexTemplateMatches(matches, ((JCCompilationUnit) tree).endPositions); + + matches.forEach(state::reportMatch); + reportMissingMatches(tree, indexedMatches, state); + reportUnexpectedMatches(tree, indexedMatches, state); + + return Description.NO_MATCH; + } + + private static ImmutableRangeMap indexTemplateMatches( + List matches, EndPosTable endPositions) { + ImmutableRangeMap.Builder templateMatches = ImmutableRangeMap.builder(); + + for (Description description : matches) { + Set replacements = + Iterables.getOnlyElement(description.fixes).getReplacements(endPositions); + for (Replacement replacement : replacements) { + templateMatches.put( + replacement.range(), getSubstringAfterFinalDelimiter('.', description.checkName)); + } + } + + return templateMatches.build(); + } + + private void reportMissingMatches( + CompilationUnitTree tree, + ImmutableRangeMap indexedMatches, + VisitorState state) { + ImmutableSet templatesWithoutMatch = + Sets.difference( + templatesUnderTest, ImmutableSet.copyOf(indexedMatches.asMapOfRanges().values())) + .immutableCopy(); + if (!templatesWithoutMatch.isEmpty()) { + String sourceFile = ((JCCompilationUnit) tree).sourcefile.getName(); + reportViolations( + tree, + String.format( + "Did not encounter a test in `%s` for the following template(s)", + getSubstringAfterFinalDelimiter('/', sourceFile)), + templatesWithoutMatch, + state); + } + } + + private void reportUnexpectedMatches( + CompilationUnitTree tree, + ImmutableRangeMap indexedMatches, + VisitorState state) { + UnexpectedMatchReporter unexpectedMatchReporter = new UnexpectedMatchReporter(indexedMatches); + unexpectedMatchReporter.scan(tree.getTypeDecls(), state); + } + + private void reportViolations( + Tree tree, String message, ImmutableSet violations, VisitorState state) { + String violationEnumeration = String.join("\n* - ", violations); + String comment = + String.format("/*\n* ERROR: %s:\n* - %s\n*/\n", message, violationEnumeration); + SuggestedFix fixWithComment = + tree instanceof MethodTree + ? SuggestedFix.prefixWith(tree, comment) + : SuggestedFix.postfixWith(tree, '\n' + comment); + state.reportMatch(describeMatch(tree, fixWithComment)); + } + + private static String getSubstringAfterFinalDelimiter(char delimiter, String value) { + int index = value.lastIndexOf(delimiter); + checkState(index >= 0, "String '%s' does not contain character '%s'", value, delimiter); + return value.substring(index + 1); + } + + private class UnexpectedMatchReporter extends TreeScanner { + private final ImmutableRangeMap indexedMatches; + + UnexpectedMatchReporter(ImmutableRangeMap indexedMatches) { + this.indexedMatches = indexedMatches; + } + + @Nullable + @Override + public Void visitMethod(MethodTree tree, VisitorState state) { + if (!ASTHelpers.isGeneratedConstructor(tree)) { + getTemplateUnderTest(tree, state) + .ifPresent( + templateUnderTest -> reportUnexpectedMatches(tree, templateUnderTest, state)); + } + + return super.visitMethod(tree, state); + } + + private void reportUnexpectedMatches( + MethodTree tree, String templateUnderTest, VisitorState state) { + // XXX: Validate that `getMatchesInTree(tree, state)` returns a non-empty result (strictly + // speaking one of the values should match `templateUnderTest`, but we can skip that check). + + ImmutableListMultimap unexpectedMatchesByLineNumber = + getUnexpectedMatchesByLineNumber(getMatchesInTree(tree, state), templateUnderTest, state); + + if (!unexpectedMatchesByLineNumber.isEmpty()) { + reportViolations( + tree, + String.format( + "The following matches unexpectedly occurred in method `%s`", tree.getName()), + unexpectedMatchesByLineNumber.entries().stream() + .map( + e -> + String.format( + "Template `%s` matches on line %s, while it should match in a method named `test%s`.", + e.getValue(), e.getKey(), e.getValue())) + .collect(toImmutableSet()), + state); + } + } + + private Optional getTemplateUnderTest(MethodTree tree, VisitorState state) { + String methodName = tree.getName().toString(); + if (methodName.startsWith(TEST_METHOD_NAME_PREFIX)) { + return Optional.of(methodName.substring(TEST_METHOD_NAME_PREFIX.length())); + } + + /* + * Unless this method is `RefasterTemplateTestCase#elidedTypesAndStaticImports`, it's + * misnamed. + */ + if (!"elidedTypesAndStaticImports".equals(methodName)) { + state.reportMatch( + describeMatch( + tree, + SuggestedFix.prefixWith( + tree, "/* ERROR: Method names should start with `test`. */\n"))); + } + + return Optional.empty(); + } + + private ImmutableRangeMap getMatchesInTree( + MethodTree tree, VisitorState state) { + int startPosition = ASTHelpers.getStartPosition(tree); + int endPosition = state.getEndPosition(tree); + + checkState( + startPosition != Position.NOPOS && endPosition != Position.NOPOS, + "Cannot determine location of method in source code"); + + return indexedMatches.subRangeMap(Range.closedOpen(startPosition, endPosition)); + } + + private ImmutableListMultimap getUnexpectedMatchesByLineNumber( + ImmutableRangeMap matches, String templateUnderTest, VisitorState state) { + LineMap lineMap = state.getPath().getCompilationUnit().getLineMap(); + return matches.asMapOfRanges().entrySet().stream() + .filter(e -> !e.getValue().equals(templateUnderTest)) + .collect( + toImmutableListMultimap( + e -> lineMap.getLineNumber(e.getKey().lowerEndpoint()), Map.Entry::getValue)); + } + } +} diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/refastertemplates/RefasterTemplateTestCase.java b/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterTemplateTestCase.java similarity index 71% rename from error-prone-contrib/src/test/java/tech/picnic/errorprone/refastertemplates/RefasterTemplateTestCase.java rename to refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterTemplateTestCase.java index 42bf96d472..216791486e 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/refastertemplates/RefasterTemplateTestCase.java +++ b/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterTemplateTestCase.java @@ -1,20 +1,23 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refaster.test; import com.google.common.collect.ImmutableSet; /** * Interface implemented by classes that exercise Refaster templates. These classes come in {@code * *Input.java} and {@code *Output.java} pairs, demonstrating the expected result of applying the - * associated Refaster templates. These classes are resources in the {@code - * tech.picnic.errorprone.bugpatterns} package. + * associated Refaster templates. These classes are resources on the test classpath. */ -interface RefasterTemplateTestCase { +public interface RefasterTemplateTestCase { /** * In some test classes there are types and statically imported methods that are fully replaced by * the Refaster templates under test. In those cases Refaster does not remove the associated * imports, while Google Java Formatter does. Subclasses can extend this method to enumerate such * types and statically imported methods, such that any imports present in the input file are also * present in the output file. + * + * @return Any values that are the result of expressions defined to ensure that all {@code + * *Input.java} import statements are also required to be present in the associated {@code + * *Output.java} file. */ default ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(); diff --git a/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/package-info.java b/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/package-info.java new file mode 100644 index 0000000000..0c61555b5c --- /dev/null +++ b/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/package-info.java @@ -0,0 +1,4 @@ +/** Opinionated utilities for the testing of Refaster templates. */ +@com.google.errorprone.annotations.CheckReturnValue +@javax.annotation.ParametersAreNonnullByDefault +package tech.picnic.errorprone.refaster.test; diff --git a/refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/MatchInWrongMethodTemplates.java b/refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/MatchInWrongMethodTemplates.java new file mode 100644 index 0000000000..3e202f17dd --- /dev/null +++ b/refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/MatchInWrongMethodTemplates.java @@ -0,0 +1,23 @@ +package tech.picnic.errorprone.refaster.test; + +import com.google.errorprone.refaster.annotation.AfterTemplate; +import com.google.errorprone.refaster.annotation.BeforeTemplate; + +/** + * Refaster template collection to validate reporting of a match occurring in an unexpected place. + */ +final class MatchInWrongMethodTemplates { + private MatchInWrongMethodTemplates() {} + + static final class StringIsEmpty { + @BeforeTemplate + boolean before(String string) { + return string.equals(""); + } + + @AfterTemplate + boolean after(String string) { + return string.isEmpty(); + } + } +} diff --git a/refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/MethodWithoutPrefixTemplates.java b/refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/MethodWithoutPrefixTemplates.java new file mode 100644 index 0000000000..4d939d460c --- /dev/null +++ b/refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/MethodWithoutPrefixTemplates.java @@ -0,0 +1,25 @@ +package tech.picnic.errorprone.refaster.test; + +import com.google.errorprone.refaster.annotation.AfterTemplate; +import com.google.errorprone.refaster.annotation.BeforeTemplate; + +/** + * Refaster template collection to validate that in the tests all methods have the prefix `test`. + * + *

The only exception to this is {@link RefasterTemplateTestCase#elidedTypesAndStaticImports()}. + */ +final class MethodWithoutPrefixTemplates { + private MethodWithoutPrefixTemplates() {} + + static final class StringIsEmpty { + @BeforeTemplate + boolean before(String string) { + return string.equals(""); + } + + @AfterTemplate + boolean after(String string) { + return string.isEmpty(); + } + } +} diff --git a/refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/MissingTestAndWrongTestTemplates.java b/refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/MissingTestAndWrongTestTemplates.java new file mode 100644 index 0000000000..089b3bf989 --- /dev/null +++ b/refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/MissingTestAndWrongTestTemplates.java @@ -0,0 +1,31 @@ +package tech.picnic.errorprone.refaster.test; + +import com.google.errorprone.refaster.annotation.AfterTemplate; +import com.google.errorprone.refaster.annotation.BeforeTemplate; + +/** + * Refaster template collection to validate that a missing test and misplaced tests are both + * reported. + */ +final class MissingTestAndWrongTestTemplates { + private MissingTestAndWrongTestTemplates() {} + + static final class StringIsEmpty { + @BeforeTemplate + boolean before(String string) { + return string.equals(""); + } + + @AfterTemplate + boolean after(String string) { + return string.isEmpty(); + } + } + + static final class TemplateWithoutTest { + @BeforeTemplate + boolean before(String string) { + return string.equals("foo"); + } + } +} diff --git a/refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/PartialTestMatchTemplates.java b/refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/PartialTestMatchTemplates.java new file mode 100644 index 0000000000..c6af0fb126 --- /dev/null +++ b/refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/PartialTestMatchTemplates.java @@ -0,0 +1,36 @@ +package tech.picnic.errorprone.refaster.test; + +import com.google.errorprone.refaster.annotation.AfterTemplate; +import com.google.errorprone.refaster.annotation.BeforeTemplate; + +/** + * Refaster template collection to validate that matches for one template in a test method meant to + * cover another template are reported. + */ +final class PartialTestMatchTemplates { + private PartialTestMatchTemplates() {} + + static final class StringEquals { + @BeforeTemplate + boolean before(String string) { + return string.toCharArray().length == 0; + } + + @AfterTemplate + boolean after(String string) { + return string.equals(""); + } + } + + static final class StringIsEmpty { + @BeforeTemplate + boolean before(String string) { + return string.equals(""); + } + + @AfterTemplate + boolean after(String string) { + return string.isEmpty(); + } + } +} diff --git a/refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/RefasterTemplateCollectionTest.java b/refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/RefasterTemplateCollectionTest.java new file mode 100644 index 0000000000..360a17902c --- /dev/null +++ b/refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/RefasterTemplateCollectionTest.java @@ -0,0 +1,30 @@ +package tech.picnic.errorprone.refaster.test; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +/** + * Validates {@link RefasterTemplateCollection} error reporting. + * + *

The goal of the Refaster template collections under test is to verify the reporting of + * violations by {@link RefasterTemplateCollection} using the associated {@code TestInput.java} and + * {@code TestOutput.java} files. Normally, {@link RefasterTemplateCollection} will raise error + * messages to be rendered in the console or IDE. However, to verify that these error messages are + * emitted as intended, the {@code *TestOutput.java} files in this package contain error reporting + * that is normally not present. + */ +final class RefasterTemplateCollectionTest { + @ParameterizedTest + @ValueSource( + classes = { + MatchInWrongMethodTemplates.class, + MethodWithoutPrefixTemplates.class, + MissingTestAndWrongTestTemplates.class, + PartialTestMatchTemplates.class, + TemplateWithoutTestTemplates.class, + ValidTemplates.class + }) + void verifyRefasterTemplateCollections(Class clazz) { + RefasterTemplateCollection.validate(clazz); + } +} diff --git a/refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/TemplateWithoutTestTemplates.java b/refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/TemplateWithoutTestTemplates.java new file mode 100644 index 0000000000..35e404c4c7 --- /dev/null +++ b/refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/TemplateWithoutTestTemplates.java @@ -0,0 +1,35 @@ +package tech.picnic.errorprone.refaster.test; + +import com.google.errorprone.refaster.annotation.AfterTemplate; +import com.google.errorprone.refaster.annotation.BeforeTemplate; + +/** Refaster template collection to validate the reporting of missing test methods. */ +final class TemplateWithoutTestTemplates { + private TemplateWithoutTestTemplates() {} + + static final class StringIsEmpty { + @BeforeTemplate + boolean before(String string) { + return string.equals(""); + } + + @AfterTemplate + boolean after(String string) { + return string.isEmpty(); + } + } + + static final class TemplateWithoutTest { + @BeforeTemplate + boolean before(String string) { + return string.equals("foo"); + } + } + + static final class AnotherTemplateWithoutTest { + @BeforeTemplate + boolean before(String string) { + return string.equals("bar"); + } + } +} diff --git a/refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/ValidTemplates.java b/refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/ValidTemplates.java new file mode 100644 index 0000000000..3e479f111d --- /dev/null +++ b/refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/ValidTemplates.java @@ -0,0 +1,62 @@ +package tech.picnic.errorprone.refaster.test; + +import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; + +import com.google.common.base.Strings; +import com.google.errorprone.refaster.annotation.AfterTemplate; +import com.google.errorprone.refaster.annotation.BeforeTemplate; +import com.google.errorprone.refaster.annotation.Placeholder; +import com.google.errorprone.refaster.annotation.UseImportPolicy; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nullable; + +/** Refaster template collection to validate that having no violations works as expected. */ +final class ValidTemplates { + private ValidTemplates() {} + + static final class StringIsEmpty2 { + @BeforeTemplate + boolean before(String string) { + return string.toCharArray().length == 0; + } + + @AfterTemplate + boolean after(String string) { + return string.isEmpty(); + } + } + + static final class StaticImportStringLength { + @BeforeTemplate + boolean before(@Nullable String string) { + return Objects.isNull(string) || string.isEmpty(); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + boolean after(String string) { + return Strings.isNullOrEmpty(string); + } + } + + abstract static class BlockTemplateSetAddElement { + @Placeholder + abstract void doAfterAdd(E element); + + @BeforeTemplate + void before(Set set, E elem) { + if (!set.contains(elem)) { + set.add(elem); + doAfterAdd(elem); + } + } + + @AfterTemplate + void after(Set set, E elem) { + if (set.add(elem)) { + doAfterAdd(elem); + } + } + } +} diff --git a/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/MatchInWrongMethodTemplatesTestInput.java b/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/MatchInWrongMethodTemplatesTestInput.java new file mode 100644 index 0000000000..522d1ef20f --- /dev/null +++ b/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/MatchInWrongMethodTemplatesTestInput.java @@ -0,0 +1,10 @@ +package tech.picnic.errorprone.refaster.test; + +/** Code to test the Refaster templates from {@link MatchInWrongMethodTemplates}. */ +final class MatchInWrongMethodTemplatesTest implements RefasterTemplateTestCase { + boolean testWrongName() { + "foo".equals(""); + "bar".equals(""); + return "baz".equals(""); + } +} diff --git a/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/MatchInWrongMethodTemplatesTestOutput.java b/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/MatchInWrongMethodTemplatesTestOutput.java new file mode 100644 index 0000000000..3e1fc4b7b3 --- /dev/null +++ b/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/MatchInWrongMethodTemplatesTestOutput.java @@ -0,0 +1,16 @@ +package tech.picnic.errorprone.refaster.test; + +/** Code to test the Refaster templates from {@link MatchInWrongMethodTemplates}. */ +final class MatchInWrongMethodTemplatesTest implements RefasterTemplateTestCase { + /* + * ERROR: The following matches unexpectedly occurred in method `testWrongName`: + * - Template `StringIsEmpty` matches on line 6, while it should match in a method named `testStringIsEmpty`. + * - Template `StringIsEmpty` matches on line 7, while it should match in a method named `testStringIsEmpty`. + * - Template `StringIsEmpty` matches on line 8, while it should match in a method named `testStringIsEmpty`. + */ + boolean testWrongName() { + "foo".isEmpty(); + "bar".isEmpty(); + return "baz".isEmpty(); + } +} diff --git a/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/MethodWithoutPrefixTemplatesTestInput.java b/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/MethodWithoutPrefixTemplatesTestInput.java new file mode 100644 index 0000000000..c22dbb6ae3 --- /dev/null +++ b/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/MethodWithoutPrefixTemplatesTestInput.java @@ -0,0 +1,21 @@ +package tech.picnic.errorprone.refaster.test; + +import com.google.common.collect.ImmutableSet; + +/** Code to test the Refaster templates from {@link MethodWithoutPrefixTemplates}. */ +final class MethodWithoutPrefixTemplatesTest implements RefasterTemplateTestCase { + @Override + public ImmutableSet elidedTypesAndStaticImports() { + return ImmutableSet.of(); + } + + boolean testStringIsEmpty() { + return "foo".equals(""); + } + + private void foo() {} + + public String bar() { + return ""; + } +} diff --git a/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/MethodWithoutPrefixTemplatesTestOutput.java b/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/MethodWithoutPrefixTemplatesTestOutput.java new file mode 100644 index 0000000000..a771efa8b1 --- /dev/null +++ b/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/MethodWithoutPrefixTemplatesTestOutput.java @@ -0,0 +1,23 @@ +package tech.picnic.errorprone.refaster.test; + +import com.google.common.collect.ImmutableSet; + +/** Code to test the Refaster templates from {@link MethodWithoutPrefixTemplates}. */ +final class MethodWithoutPrefixTemplatesTest implements RefasterTemplateTestCase { + @Override + public ImmutableSet elidedTypesAndStaticImports() { + return ImmutableSet.of(); + } + + boolean testStringIsEmpty() { + return "foo".isEmpty(); + } + + /* ERROR: Method names should start with `test`. */ + private void foo() {} + + /* ERROR: Method names should start with `test`. */ + public String bar() { + return ""; + } +} diff --git a/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/MissingTestAndWrongTestTemplatesTestInput.java b/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/MissingTestAndWrongTestTemplatesTestInput.java new file mode 100644 index 0000000000..7c2c949f53 --- /dev/null +++ b/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/MissingTestAndWrongTestTemplatesTestInput.java @@ -0,0 +1,10 @@ +package tech.picnic.errorprone.refaster.test; + +/** Code to test the Refaster templates from {@link MissingTestAndWrongTestTemplates}. */ +final class MissingTestAndWrongTestTemplatesTest implements RefasterTemplateTestCase { + boolean testWrongName() { + "foo".equals(""); + "bar".equals(""); + return "baz".equals(""); + } +} diff --git a/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/MissingTestAndWrongTestTemplatesTestOutput.java b/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/MissingTestAndWrongTestTemplatesTestOutput.java new file mode 100644 index 0000000000..f46a0f65d0 --- /dev/null +++ b/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/MissingTestAndWrongTestTemplatesTestOutput.java @@ -0,0 +1,20 @@ +package tech.picnic.errorprone.refaster.test; + +/** Code to test the Refaster templates from {@link MissingTestAndWrongTestTemplates}. */ +final class MissingTestAndWrongTestTemplatesTest implements RefasterTemplateTestCase { + /* + * ERROR: The following matches unexpectedly occurred in method `testWrongName`: + * - Template `StringIsEmpty` matches on line 6, while it should match in a method named `testStringIsEmpty`. + * - Template `StringIsEmpty` matches on line 7, while it should match in a method named `testStringIsEmpty`. + * - Template `StringIsEmpty` matches on line 8, while it should match in a method named `testStringIsEmpty`. + */ + boolean testWrongName() { + "foo".isEmpty(); + "bar".isEmpty(); + return "baz".isEmpty(); + } +} +/* + * ERROR: Did not encounter a test in `MissingTestAndWrongTestTemplatesTestInput.java` for the following template(s): + * - TemplateWithoutTest + */ diff --git a/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/PartialTestMatchTemplatesTestInput.java b/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/PartialTestMatchTemplatesTestInput.java new file mode 100644 index 0000000000..4816d35ef0 --- /dev/null +++ b/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/PartialTestMatchTemplatesTestInput.java @@ -0,0 +1,9 @@ +package tech.picnic.errorprone.refaster.test; + +/** Code to test the Refaster templates from {@link PartialTestMatchTemplates}. */ +final class PartialTestMatchTemplatesTest implements RefasterTemplateTestCase { + boolean testStringIsEmpty() { + boolean b = "foo".toCharArray().length == 0; + return "bar".equals(""); + } +} diff --git a/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/PartialTestMatchTemplatesTestOutput.java b/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/PartialTestMatchTemplatesTestOutput.java new file mode 100644 index 0000000000..afe9f4740f --- /dev/null +++ b/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/PartialTestMatchTemplatesTestOutput.java @@ -0,0 +1,13 @@ +package tech.picnic.errorprone.refaster.test; + +/** Code to test the Refaster templates from {@link PartialTestMatchTemplates}. */ +final class PartialTestMatchTemplatesTest implements RefasterTemplateTestCase { + /* + * ERROR: The following matches unexpectedly occurred in method `testStringIsEmpty`: + * - Template `StringEquals` matches on line 6, while it should match in a method named `testStringEquals`. + */ + boolean testStringIsEmpty() { + boolean b = "foo".equals(""); + return "bar".isEmpty(); + } +} diff --git a/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/TemplateWithoutTestTemplatesTestInput.java b/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/TemplateWithoutTestTemplatesTestInput.java new file mode 100644 index 0000000000..a8c0ab762e --- /dev/null +++ b/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/TemplateWithoutTestTemplatesTestInput.java @@ -0,0 +1,8 @@ +package tech.picnic.errorprone.refaster.test; + +/** Code to test the Refaster templates from {@link TemplateWithoutTestTemplates}. */ +final class TemplateWithoutTestTemplatesTest implements RefasterTemplateTestCase { + boolean testStringIsEmpty() { + return "foo".equals(""); + } +} diff --git a/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/TemplateWithoutTestTemplatesTestOutput.java b/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/TemplateWithoutTestTemplatesTestOutput.java new file mode 100644 index 0000000000..31c38abd12 --- /dev/null +++ b/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/TemplateWithoutTestTemplatesTestOutput.java @@ -0,0 +1,13 @@ +package tech.picnic.errorprone.refaster.test; + +/** Code to test the Refaster templates from {@link TemplateWithoutTestTemplates}. */ +final class TemplateWithoutTestTemplatesTest implements RefasterTemplateTestCase { + boolean testStringIsEmpty() { + return "foo".isEmpty(); + } +} +/* + * ERROR: Did not encounter a test in `TemplateWithoutTestTemplatesTestInput.java` for the following template(s): + * - AnotherTemplateWithoutTest + * - TemplateWithoutTest + */ diff --git a/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/ValidTemplatesTestInput.java b/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/ValidTemplatesTestInput.java new file mode 100644 index 0000000000..29de6609c2 --- /dev/null +++ b/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/ValidTemplatesTestInput.java @@ -0,0 +1,32 @@ +package tech.picnic.errorprone.refaster.test; + +import com.google.common.base.Strings; +import com.google.common.collect.ImmutableSet; +import java.util.HashSet; +import java.util.Objects; +import java.util.Set; + +/** Code to test the Refaster templates from {@link ValidTemplates}. */ +final class ValidTemplatesTest implements RefasterTemplateTestCase { + @Override + public ImmutableSet elidedTypesAndStaticImports() { + return ImmutableSet.of(Objects.class, Strings.class); + } + + boolean testStringIsEmpty2() { + return "foo".toCharArray().length == 0; + } + + boolean testStaticImportStringLength() { + return Objects.isNull("foo") || "foo".isEmpty(); + } + + void testBlockTemplateSetAddElement() { + Set set = new HashSet<>(); + Integer element = 1; + if (!set.contains(element)) { + set.add(element); + System.out.print("added the following element to set: " + element); + } + } +} diff --git a/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/ValidTemplatesTestOutput.java b/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/ValidTemplatesTestOutput.java new file mode 100644 index 0000000000..dce5fa55ad --- /dev/null +++ b/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/ValidTemplatesTestOutput.java @@ -0,0 +1,33 @@ +package tech.picnic.errorprone.refaster.test; + +import static com.google.common.base.Strings.isNullOrEmpty; + +import com.google.common.base.Strings; +import com.google.common.collect.ImmutableSet; +import java.util.HashSet; +import java.util.Objects; +import java.util.Set; + +/** Code to test the Refaster templates from {@link ValidTemplates}. */ +final class ValidTemplatesTest implements RefasterTemplateTestCase { + @Override + public ImmutableSet elidedTypesAndStaticImports() { + return ImmutableSet.of(Objects.class, Strings.class); + } + + boolean testStringIsEmpty2() { + return "foo".isEmpty(); + } + + boolean testStaticImportStringLength() { + return isNullOrEmpty("foo"); + } + + void testBlockTemplateSetAddElement() { + Set set = new HashSet<>(); + Integer element = 1; + if (set.add(element)) { + System.out.print("added the following element to set: " + element); + } + } +}