HomeCloud ComputingA practitioner’s primer on deterministic utility modernization

A practitioner’s primer on deterministic utility modernization



// Supply code snippet
// The person's identify
non-public String identify = "Java";

// LST illustration
J.VariableDeclarations | "// The person's namenprivate String identify = "Java""
|---J.Modifier | "non-public"
|---J.Identifier | "String"
---J.VariableDeclarations.NamedVariable | "identify = "Java""
    |---J.Identifier | "identify"
    ---J.Literal | ""Java""

Recipes work with many alternative file sorts together with XML or YAML to switch issues like Maven POMs or different configuration information. In addition they can create new information when wanted as a part of migrations. However recipes don’t even have to switch code in any respect. A robust function and good thing about the wealthy information from the LST is that they might simply collect information and insights, analyzing code bases to generate information tables for use for stories, metrics, or visualizations that assist groups perceive their code earlier than making modifications.

Testing recipes: Deterministic and dependable

OpenRewrite’s deterministic nature makes recipes straightforward to check. Right here’s how easy it’s to visualise the modifications a recipe ought to make, and to confirm it really works accurately:

@Take a look at
void migrateJUnitTest() {
    rewriteRun(
        // The recipe to check
        new MigrateToJUnit5(),
        
        // Earlier than: JUnit 4 code
        java("""
            import org.junit.Take a look at;
            
            public class MyTest {
                @Take a look at
                public void testSomething() {}
            }
            """),
            
        // After: Anticipated JUnit 5 end result
        java("""
            import org.junit.jupiter.api.Take a look at;
            
            public class MyTest {
                @Take a look at
                public void testSomething() {}
            }
            """)
    );
}

This check framework validates that the recipe produces precisely the anticipated output—no extra, no much less. As a result of recipes are deterministic, the identical enter all the time produces the identical end result, making them dependable and testable at scale.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments