rewrite-static-analysis
rewrite-static-analysis copied to clipboard
`RemoveUnneededAssertion` should also clean up testng assertions
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.
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
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
This issue should, likely, be transferred to rewrite-static-analysis
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