From 5b49655e1670216dbb5006e43360962a51c5d77b Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Thu, 4 Aug 2022 14:11:43 +0200 Subject: [PATCH] Apply feedback and update `README.md` --- .../RefasterTemplatesTest.java | 4 +- refaster-test-support/README.md | 40 +++++++++---------- ...r.java => RefasterTemplateCollection.java} | 12 +++--- ...va => RefasterTemplateCollectionTest.java} | 16 ++++---- 4 files changed, 36 insertions(+), 36 deletions(-) rename refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/{RefasterTemplateCollectionValidator.java => RefasterTemplateCollection.java} (97%) rename refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/{RefasterTemplateCollectionValidatorTest.java => RefasterTemplateCollectionTest.java} (50%) 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 index c577729ccfe..7b78e494757 100644 --- 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 @@ -7,7 +7,7 @@ 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.RefasterTemplateCollectionValidator; +import tech.picnic.errorprone.refaster.test.RefasterTemplateCollection; final class RefasterTemplatesTest { /** The names of all Refaster template groups defined in this module. */ @@ -76,6 +76,6 @@ private static Stream validateTemplateCollectionTestCases() { @MethodSource("validateTemplateCollectionTestCases") @ParameterizedTest void validateTemplateCollection(Class clazz) { - RefasterTemplateCollectionValidator.validate(clazz); + RefasterTemplateCollection.validate(clazz); } } diff --git a/refaster-test-support/README.md b/refaster-test-support/README.md index cd70763c1e3..9719463e72c 100644 --- a/refaster-test-support/README.md +++ b/refaster-test-support/README.md @@ -11,39 +11,39 @@ match the associated output file. This extension 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 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. +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 class using -`RefasterTemplateCollectionValidator`, one should create suitably named input -and output files. The collection's Refaster templates are applied to the input -file and must exactly match the contents of the provided output file. +A class that contains one or more Refaster templates is called a Refaster +template collection. In a nutshell, to test a Refaster template collection +class using `RefasterTemplateCollection`, one should create suitably named +input and output files. The collection's Refaster templates are applied to the +input file and must exactly match the contents of the provided output file. To test Refaster templates, one can create a (parameterized) test for every -class containing the Refaster templates to invoke the -`RefasterTemplateCollectionValidator`. A class that contains one or more -Refaster templates is called a Refaster template collection. 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. +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 have to be met: -- Create a class with a (parameterized) test method that calls the - `RefasterTemplateCollectionValidator#validate` and passes the collection(s) - to validate. The Refaster template collection must match the naming - convention `Templates.java`. +- Create a class with a (parameterized) test method that invokes + `RefasterTemplateCollection#validate` and passes the collection(s) to + validate. The Refaster template collection must match the naming convention + `Templates.java`. - An input file matching the naming convention `TemplatesTestInput.java` is added for every template collection. - An output file matching the naming convention `TemplatesTestOutput.java` file is added for every template collection. -- For each Refaster template in the collection, the input and output file must +- For every Refaster template in the collection, the input and output file must contain a method. The name of the method is equal to the name of the Refaster template prefixed with `test` (e.g. `test`). - The method contains at least one expression that matches the @@ -68,7 +68,7 @@ src/ tech.picnic.errorprone.refastertemplates └── RefasterCollectionTest.java -- This test class invokes - -- `RefasterTemplateCollectionValidator#validate`. + -- `RefasterTemplateCollection#validate`. resources/ tech.picnic.errorprone.refastertemplates └── ExampleTemplatesTestInput.java diff --git a/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterTemplateCollectionValidator.java b/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterTemplateCollection.java similarity index 97% rename from refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterTemplateCollectionValidator.java rename to refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterTemplateCollection.java index 8be1f29c241..1ffe29dc9af 100644 --- a/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterTemplateCollectionValidator.java +++ b/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterTemplateCollection.java @@ -53,25 +53,25 @@ * exactly one distinct method, as indicated by each method's name. */ @BugPattern( - name = "RefasterTemplateCollectionValidator", + name = "RefasterTemplateCollection", summary = "Exercises a Refaster template collection", severity = ERROR) -public final class RefasterTemplateCollectionValidator extends BugChecker +public final class RefasterTemplateCollection extends BugChecker implements CompilationUnitTreeMatcher { private static final long serialVersionUID = 1L; private static final String TEMPLATE_COLLECTION_FLAG = - "RefasterTemplateCollectionValidator:TemplateCollection"; + "RefasterTemplateCollection:TemplateCollection"; private static final String TEST_METHOD_NAME_PREFIX = "test"; private final ImmutableSortedSet templatesUnderTest; private final RefasterCheck delegate; /** - * Instantiates a {@link RefasterTemplateCollectionValidator} instance. + * Instantiates a {@link RefasterTemplateCollection} instance. * * @param flags Any provided command line flags. */ - public RefasterTemplateCollectionValidator(ErrorProneFlags flags) { + public RefasterTemplateCollection(ErrorProneFlags flags) { String templateCollectionUnderTest = getTemplateCollectionUnderTest(flags); delegate = createRefasterCheck(templateCollectionUnderTest); templatesUnderTest = getTemplatesUnderTest(templateCollectionUnderTest); @@ -117,7 +117,7 @@ private static ImmutableSortedSet getTemplatesUnderTest( public static void validate(Class clazz) { String className = clazz.getSimpleName(); - BugCheckerRefactoringTestHelper.newInstance(RefasterTemplateCollectionValidator.class, clazz) + BugCheckerRefactoringTestHelper.newInstance(RefasterTemplateCollection.class, clazz) .setArgs(ImmutableList.of("-XepOpt:" + TEMPLATE_COLLECTION_FLAG + '=' + className)) .addInput(className + "TestInput.java") .addOutput(className + "TestOutput.java") diff --git a/refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/RefasterTemplateCollectionValidatorTest.java b/refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/RefasterTemplateCollectionTest.java similarity index 50% rename from refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/RefasterTemplateCollectionValidatorTest.java rename to refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/RefasterTemplateCollectionTest.java index eefa5185eb0..5a2194909ec 100644 --- a/refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/RefasterTemplateCollectionValidatorTest.java +++ b/refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/RefasterTemplateCollectionTest.java @@ -4,16 +4,16 @@ import org.junit.jupiter.params.provider.ValueSource; /** - * Validates {@link RefasterTemplateCollectionValidator} error reporting. + * Validates {@link RefasterTemplateCollection} error reporting. * *

The goal of the Refaster template collections under test is to verify the reporting of - * violations by {@link RefasterTemplateCollectionValidator} using the associated {@code - * TestInput.java} and {@code TestOutput.java} files. Normally, {@link - * RefasterTemplateCollectionValidator} will raise error messages to be rendered in the console or - * IDE. However, to verify that these error messages are as intended, the {@code *TestOutput.java} - * files in this package contain error reporting that is normally not present. + * 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 + * as intended, the {@code *TestOutput.java} files in this package contain error reporting that is + * normally not present. */ -final class RefasterTemplateCollectionValidatorTest { +final class RefasterTemplateCollectionTest { @ParameterizedTest @ValueSource( classes = { @@ -25,6 +25,6 @@ final class RefasterTemplateCollectionValidatorTest { ValidTemplates.class }) void verifyRefasterTemplateCollections(Class clazz) { - RefasterTemplateCollectionValidator.validate(clazz); + RefasterTemplateCollection.validate(clazz); } }