Skip to content

Update builds to support strictMode testing #953

@stleary

Description

@stleary

After executing the unit tests, set default strictMode to true, then re-run all of the tests.
Fix in both gradle and maven builds. It might be possible (?) to integrate this action into the existing test task, but if not:

In Gradle:
Modify the existing test task (copilot, I have not verified this):

apply plugin: 'java'

repositories {
    mavenCentral()
}

dependencies {
    testImplementation 'junit:junit:4.12'
}

task modifyCode {
    doLast {
        // Add your code modification logic here
        def file = file('src/main/java/com/example/YourClass.java')
        def text = file.text
        text = text.replaceAll('oldCode', 'newCode')
        file.text = text
        println 'Code modified.'
    }
}

task rerunTests(dependsOn: ['modifyCode', 'test']) {
    doLast {
        println 'Re-running tests...'
    }
}

test {
    finalizedBy 'rerunTests'
}

If a new task is needed (claude.ai, not verified):

    dependsOn test
    doLast {
        // Make your code change here
        File sourceFile = file('src/main/java/YourFile.java')
        String content = sourceFile.text
        content = content.replace('oldCode', 'newCode')
        sourceFile.text = content
        
        // Run tests again
        tasks.test.execute()
    }
}

Copilot also suggests a one-test-run fix for maven, but it requires a new ModifyCode class. Not shown here.

In Maven, new task (claude.ai, not verified):

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>3.1.0</version>
    <executions>
        <execution>
            <id>test-with-code-change</id>
            <phase>verify</phase>
            <goals>
                <goal>java</goal>
            </goals>
            <configuration>
                <mainClass>org.apache.maven.shared.utils.io.FileUtils</mainClass>
                <arguments>
                    <argument>src/main/java/YourFile.java</argument>
                    <argument>oldCode</argument>
                    <argument>newCode</argument>
                </arguments>
            </configuration>
        </execution>
    </executions>
</plugin>

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions