rewrite-static-analysis icon indicating copy to clipboard operation
rewrite-static-analysis copied to clipboard

`RemoveUnneededAssertion` should also clean up testng assertions

Open gadams00 opened this issue 3 years ago • 4 comments

The org.openrewrite.java.security.UseFilesCreateTempDirectory recipe attempts to remove unnecessary assertions as a cleanup step, but when run on https://github.com/broadinstitute/picard it's not cleaning up asserts here: https://github.com/broadinstitute/picard/blob/master/src/test/java/picard/illumina/CollectIlluminaBasecallingMetricsTest.java#L23

this is because the RemoveUnneededAnnotations visitor only removes junit asserts and these are from testng. The result is

        rootTestDir = Files.createTempDirectory("cibm." + ".tmp").toFile();
        Assert.assertTrue(true);
        Assert.assertTrue(true);

RemoveUnneededAnnotations should probably handle testng asserts as well.

gadams00 avatar Sep 14 '22 17:09 gadams00

This Github issue should be moved to rewrite-java-security as this is where the mentioned code resides now: https://github.com/openrewrite/rewrite-java-security/issues/11

mccartney avatar Oct 22 '22 14:10 mccartney

We're just using RemoveUnneededAssertion. This is likely a bug there if it's not working correctly.

https://github.com/openrewrite/rewrite-java-security/blob/a1492e34a6db6768839a97ca78f153a387a76e0e/src/main/java/org/openrewrite/java/security/UseFilesCreateTempDirectory.java#L284

JLLeitschuh avatar Aug 30 '23 17:08 JLLeitschuh

This issue should, likely, be transferred to rewrite-static-analysis

JLLeitschuh avatar Aug 30 '23 17:08 JLLeitschuh

Thanks for the suggestion @gadams00 ! It shouldn't be hard to clean up additional assertions, such as those for testng. The starting point would be to expand on the preconditions here to add testng parallels. https://github.com/openrewrite/rewrite-static-analysis/blob/2fb2bfb0faf43e9f12bd1ce149e5e42ee14337a2/src/main/java/org/openrewrite/staticanalysis/RemoveUnneededAssertion.java#L59-L66

timtebeek avatar Sep 13 '23 13:09 timtebeek