A practitioner’s primer on deterministic application modernization

Read more at:

// Source code snippet
// The user's name
private String name = "Java";

// LST representation
J.VariableDeclarations | "// The user's name\nprivate String name = "Java""
|---J.Modifier | "private"
|---J.Identifier | "String"
\---J.VariableDeclarations.NamedVariable | "name = "Java""
    |---J.Identifier | "name"
    \---J.Literal | ""Java""

Recipes work with many different file types including XML or YAML to modify things like Maven POMs or other configuration files. They also can create new files when needed as part of migrations. But recipes don’t even have to modify code at all. A powerful feature and benefit of the rich data from the LST is that they may just gather data and insights, analyzing code bases to generate data tables to be used for reports, metrics, or visualizations that help teams understand their code before making changes.

Testing recipes: Deterministic and reliable

OpenRewrite’s deterministic nature makes recipes easy to test. Here’s how simple it is to visualize the changes a recipe should make, and to verify it works correctly:

@Test
void migrateJUnitTest() {
    rewriteRun(
        // The recipe to test
        new MigrateToJUnit5(),
        
        // Before: JUnit 4 code
        java("""
            import org.junit.Test;
            
            public class MyTest {
                @Test
                public void testSomething() {}
            }
            """),
            
        // After: Expected JUnit 5 result
        java("""
            import org.junit.jupiter.api.Test;
            
            public class MyTest {
                @Test
                public void testSomething() {}
            }
            """)
    );
}

This test framework validates that the recipe produces exactly the expected output—no more, no less. Because recipes are deterministic, the same input always produces the same result, making them reliable and testable at scale.

Source link

Multi-Function Air Blower: Blowing, suction, extraction, and even inflation
spot_img

Leave a reply

Please enter your comment!
Please enter your name here