Skip to content

Conversation

@steve-aom-elliott
Copy link
Contributor

What's changed?

  • New artifactId corrected from mockwebserver3-junit5 to mockwebserver3
  • In-progress work for changing how some classes are built / manipulated. Previously there were many methods existing on MockResponse. Now everything has to be switched to using MockResponse.Builder to change all these values.

What's your motivation?

Compilation failures after previous setup's migration ran.

Anything in particular you'd like reviewers to focus on?

  • Trying to see if I can cut down on additional recipe calls given there are a fair number of methods yet to migrate.

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@steve-aom-elliott steve-aom-elliott self-assigned this Nov 21, 2025
@steve-aom-elliott steve-aom-elliott added bug Something isn't working dependencies Pull requests that update a dependency file test provided junit labels Nov 21, 2025
@github-project-automation github-project-automation bot moved this to In Progress in OpenRewrite Nov 21, 2025
…padding (including the newline), leading to it changing wrapping.
@steve-aom-elliott steve-aom-elliott force-pushed the 1589-correcting-mockwebserver-migration branch 2 times, most recently from 72584dc to 630c51b Compare November 27, 2025 21:45
…uild()`, and backpatching the parameter types onto the various method invocations. Feels like there could be a lot of improvement still with how this done, as it feels pretty hacky right now.
@steve-aom-elliott steve-aom-elliott force-pushed the 1589-correcting-mockwebserver-migration branch from 630c51b to 58ef5a9 Compare November 27, 2025 21:47
import static org.assertj.core.api.Assertions.assertThat;
import static org.openrewrite.java.Assertions.java;
import static org.openrewrite.java.Assertions.mavenProject;
import static org.openrewrite.java.Assertions.*;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import static org.openrewrite.java.Assertions.*;
import static org.openrewrite.java.Assertions.java;
import static org.openrewrite.java.Assertions.mavenProject;

}

@DocumentExample
// TODO: methods receiving MockResponse - maybe add comment instructing to double check?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// TODO: methods receiving MockResponse - maybe add comment instructing to double check?
// @Test
// void wip() {
// rewriteRun(
// //language=java
// java(
// """
// import okhttp3.Headers;
// import okhttp3.mockwebserver.MockResponse;
//
// class A {
// void someMethod() {
// Headers headers = new Headers.Builder().build();
// MockResponse a = new MockResponse();
// // .status(String): void
// // .getStatus(): String
// // --
// // .setStatus(String): MockResponse[this]
// // ---
// // .headers(Headers): void
// // .setHeaders(Headers): MockResponse
// // .getHeaders(): Headers
// // ---
// // .addHeader(String): MockResponse
// // .addHeader(String,Object): MockResponse
// // .addHeaderLenient(String,Object): MockResponse
// // ---
// // .setHeader(String,Object): MockResponse
// // .removeHeader(String): MockResponse
// // .clearHeaders(): MockResponse
// a.header
// a.trailers(headers);
// }
// }
// """
// )
// );
// }
@DocumentExample
@Test
void shouldUpgradeMavenDependency() {
rewriteRun(
spec -> spec.recipeFromResource("/META-INF/rewrite/junit5.yml", "org.openrewrite.java.testing.junit5.UpgradeOkHttpMockWebServer"),
mavenProject("project",
// TODO: handle solely J.NewClass and update declarative recipe to include new one.
//language=xml
pomXml(
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<version>4.10.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
""",
spec -> spec.after(pom ->
assertThat(pom)
.doesNotContain("<artifactId>mockwebserver</artifactId>")
.contains("<artifactId>mockwebserver3</artifactId>")
.containsPattern("<version>5\\.(.*)</version>")
.actual()
)
)
)
);
}
// TODO: methods receiving MockResponse - maybe add comment instructing to double check?

@steve-aom-elliott
Copy link
Contributor Author

I'm going to try to look into whether I can set up a single visitor to perform all the type changes needed prior to using the JavaTemplate to write the .build() chaining in, as the problem I'm hitting here is that I'm changing MockResponse fields to MockResponse.Builder fields, return types from some of the methods of MockResponse to be on MockResponse.Builder instead, followed by introducing a .build() call that belongs to MockResponse.Builder but returns MockResponse, meaning ChangeType recipe effectively breaks the type attribution, but covers a lot of the scenarios otherwise that I'd want to be changing. Going to probably roll my own visitor that combines functionality from some of the other ones, or create a visitor that is capable of altering a method invocation's signature's parameter types, which I don't believe we have easily accessible a the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working dependencies Pull requests that update a dependency file junit test provided

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

3 participants