Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hamcrest to assertj adddependency issue #1

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions hamcrest-to-assertj/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Meant to show an issue with 'AddDependency' when used on modified LST.

```sh
mvn org.openrewrite.maven:rewrite-maven-plugin:5.39.0:run \
-Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-testing-frameworks:2.16.0 \
-Drewrite.activeRecipes=org.openrewrite.java.testing.hamcrest.MigrateHamcrestToAssertJ \
-Drewrite.exportDatatables=true
```

After this, I expect `App.java` should be changed and `assertj` dependency
should be added to the pom. However, only `App.java` is changed and code no
longer compiles. Debugging suggests a condition related to `onlyIfUsing` in
`AddDependency` is not seeing the modified LST.
23 changes: 23 additions & 0 deletions hamcrest-to-assertj/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>
<name>hamcrest-to-assertj</name>
<description>
Meant to show an issue with OpenRewrite's AddDependency + onlyIfUsing +
recipe lists. It doesn't seem like `UsingType` sees the modified LST.
</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>17</maven.compiler.release>
</properties>
<dependencies>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
</dependency>
</dependencies>
</project>
10 changes: 10 additions & 0 deletions hamcrest-to-assertj/src/main/java/test/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;

public class App {
public static void main(final String[] args ) {
assertThat("Peano was wrong!", 1, equalTo(2));
}
}