Open Laurens-W opened 1 year ago
I am using
I am using the Maven plugin from the commandline within a Jenkins job:
mvn org.openrewrite.maven:rewrite-maven-plugin:5.0.0:run -Drewrite.activeRecipes=redacted -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-java-security:LATEST,org.openrewrite.recipe:rewrite-kubernetes:LATEST,org.openrewrite.recipe:rewrite-logging-frameworks:LATEST,org.openrewrite.recipe:rewrite-migrate-java:LATEST,org.openrewrite.recipe:rewrite-spring:LATEST,org.openrewrite.recipe:rewrite-testing-frameworks:LATEST -Drewrite.exclusions=**api**.yaml
Adding the following testcase to the org/openrewrite/java/testing/mockito/AnyToNullableTest.java and running it will show it fails
@Test void shouldNotReplaceUntypedAny() { //language=java rewriteRun( //language=xml pomXml(""" <project> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>foo</artifactId> <version>1.0.0</version> <dependencies> <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-all</artifactId> <version>1.10.19</version> </dependency> </dependencies> </project> """), //language=java java(""" class Example { String greet(Object obj, Object obj2) { return "Hello " + obj + obj2; } } """), //language=java java( """ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.mockito.Mockito.any; class MyTest { void test() { Example example = mock(Example.class); when(example.greet(any(Object.class), any())).thenReturn("Hello world"); } } """, """ import static org.mockito.ArgumentMatchers.nullable; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.mockito.Mockito.any; class MyTest { void test() { Example example = mock(Example.class); when(example.greet(nullable(Object.class), any())).thenReturn("Hello world"); } } """ ) ); }
The any import should not be removed as it is required by the untyped any(), if anything it should be replaced with the ArgumentMatchers.any
The import is removed as part of the AnyToNullable recipe
stacktrace output here
This issue is quite likely linked to
What version of OpenRewrite are you using?
I am using
How are you running OpenRewrite?
I am using the Maven plugin from the commandline within a Jenkins job:
What is the smallest, simplest way to reproduce the problem?
Adding the following testcase to the org/openrewrite/java/testing/mockito/AnyToNullableTest.java and running it will show it fails
What did you expect to see?
The any import should not be removed as it is required by the untyped any(), if anything it should be replaced with the ArgumentMatchers.any
What did you see instead?
The import is removed as part of the AnyToNullable recipe
What is the full stack trace of any errors you encountered?
Are you interested in contributing a fix to OpenRewrite?