-
Notifications
You must be signed in to change notification settings - Fork 95
Correcting MockWebServer migration for OkHttp #849
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
base: main
Are you sure you want to change the base?
Conversation
| @@ -0,0 +1,222 @@ | |||
| package org.openrewrite.java.testing.junit5; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| package org.openrewrite.java.testing.junit5; | |
| /* | |
| * Copyright 2025 the original author or authors. | |
| * <p> | |
| * Licensed under the Moderne Source Available License (the "License"); | |
| * you may not use this file except in compliance with the License. | |
| * You may obtain a copy of the License at | |
| * <p> | |
| * https://docs.moderne.io/licensing/moderne-source-available-license | |
| * <p> | |
| * Unless required by applicable law or agreed to in writing, software | |
| * distributed under the License is distributed on an "AS IS" BASIS, | |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| * See the License for the specific language governing permissions and | |
| * limitations under the License. | |
| */ | |
| package org.openrewrite.java.testing.junit5; |
| import org.openrewrite.java.tree.J; | ||
| import org.openrewrite.java.tree.JavaType; | ||
| import org.openrewrite.java.tree.Statement; | ||
| import org.openrewrite.java.tree.TypeUtils; | ||
|
|
||
| import static java.util.Objects.requireNonNull; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| import org.openrewrite.java.tree.J; | |
| import org.openrewrite.java.tree.JavaType; | |
| import org.openrewrite.java.tree.Statement; | |
| import org.openrewrite.java.tree.TypeUtils; | |
| import static java.util.Objects.requireNonNull; | |
| import org.openrewrite.java.tree.J; |
| // return mi; | ||
| // } | ||
| // }.visit(tree, ctx); | ||
| j = new JavaIsoVisitor<ExecutionContext>() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| j = new JavaIsoVisitor<ExecutionContext>() { | |
| return new JavaIsoVisitor<ExecutionContext>() { |
| }.visit(j, ctx); | ||
| return j; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| }.visit(j, ctx); | |
| return j; | |
| }.visit(j, ctx); |
| } | ||
|
|
||
| @DocumentExample | ||
| // TODO: methods receiving MockResponse - maybe add comment instructing to double check? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // TODO: methods receiving MockResponse - maybe add comment instructing to double check? | |
| @DocumentExample | |
| @Test | |
| void shouldUpgradeMavenDependency() { | |
| rewriteRun( | |
| mavenProject("project", | |
| srcTestJava( | |
| //language=java | |
| java( | |
| """ | |
| import okhttp3.mockwebserver.MockResponse; | |
| import okhttp3.mockwebserver.MockWebServer; | |
| import okhttp3.mockwebserver.RecordedRequest; | |
| class Test { | |
| void test() { | |
| MockWebServer server = new MockWebServer(); | |
| server.enqueue( | |
| new MockResponse().setHeader("Content-Type", "application/json") | |
| // new MockResponse() | |
| // .setHeader("Content-Type", "application/json") | |
| // .setResponseCode(200) | |
| // .setBody("{}") | |
| ); | |
| // RecordedRequest recordedRequest = server.takeRequest(); | |
| } | |
| } | |
| """, | |
| """ | |
| import mockwebserver3.MockResponse; | |
| import mockwebserver3.MockWebServer; | |
| import mockwebserver3.RecordedRequest; | |
| class Test { | |
| void test() { | |
| MockWebServer server = new MockWebServer(); | |
| server.enqueue( | |
| new MockResponse() | |
| // .setHeader("Content-Type", "application/json") | |
| // .setResponseCode(200) | |
| // .setBody("{}") | |
| ); | |
| // RecordedRequest recordedRequest = server.takeRequest(); | |
| } | |
| } | |
| """ | |
| ) | |
| ), | |
| //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? |
What's changed?
mockwebserver3-junit5tomockwebserver3MockResponse. Now everything has to be switched to usingMockResponse.Builderto 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?
Checklist