Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
<suppress checks="MissingJavadocType" files=".*"/>
<suppress checks="JavadocVariable" files=".*"/>
<suppress checks="MissingJavadocMethod" files=".*"/>
<suppress checks="DesignForExtension" files="[\\/]src[\\/]test[\\/]java[\\/]org[\\/]checkstyle[\\/]autofix[\\/]recipe[\\/]AbstractRecipeTest\.java"/>
</suppressions>
12 changes: 0 additions & 12 deletions src/test/java/org/checkstyle/autofix/InputClassRenamer.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,9 @@ public TreeVisitor<?, ExecutionContext> getVisitor() {
return new ClassRenameVisitor();
}

/**
* A visitor that traverse Java AST nodes and renames classes starting with "Input" to "Output".
*/
private static final class ClassRenameVisitor extends JavaIsoVisitor<ExecutionContext> {

/** The prefix to match in class names. */
private static final String FROM_PREFIX = "Input";
/** The prefix to replace with in class names. */
private static final String TO_PREFIX = "Output";

@Override
Expand Down Expand Up @@ -82,13 +77,6 @@ public J.NewClass visitNewClass(J.NewClass constructorNode,
return result;
}

/**
* Checks if a given class name starts with the FROM_PREFIX
* and returns the renamed version with TO_PREFIX.
*
* @param originalName The original class name.
* @return The new class name with TO_PREFIX if matched, otherwise null.
*/
private String renameIfMatch(String originalName) {
final String result;
if (originalName.startsWith(FROM_PREFIX)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,47 +28,18 @@
import org.openrewrite.Recipe;
import org.openrewrite.test.RewriteTest;

/**
* Base test class for recipe testing that provides common functionality
* for reading test files and executing recipe tests with preprocessing.
*/
public abstract class AbstractRecipeTest implements RewriteTest {

private static final String BASE_TEST_RESOURCES_PATH = "src/test/resources/org"
+ "/checkstyle/autofix/recipe/";

/**
* Creates a preprocessing recipe that normalizes class names from InputXxx to OutputXxx.
* This allows test files to have descriptive names while maintaining consistent class names.
*
* @return the preprocessing recipe
*/
private Recipe createPreprocessingRecipe() {
return new InputClassRenamer();
}

/**
* Creates the main recipe that should be tested.
* Subclasses must implement this method to provide their specific recipe.
*
* @return the main recipe to test
*/
protected abstract Recipe getRecipe();

/**
* Tests a recipe with the given recipe path and test case name.
* Expects input and output files to follow the naming convention:
* - Input: {recipePath}/{testCaseName}/Input{testCaseName}.java
* - Output: {recipePath}/{testCaseName}/Output{testCaseName}.java
* The method automatically applies preprocessing to normalize class names
* before running the main recipe.
*
* @param recipePath the recipe-specific path.
* @param testCaseName the name of the test case (should match directory and file names)
* @throws IOException if files cannot be read
*/
protected void testRecipe(String recipePath, String testCaseName)
throws IOException {
protected void testRecipe(String recipePath, String testCaseName) throws IOException {
final String testCaseDir = testCaseName.toLowerCase();
final String inputFileName = "Input" + testCaseName + ".java";
final String outputFileName = "Output" + testCaseName + ".java";
Expand Down