|
| 1 | +/* |
| 2 | + * Copyright 2021 the original author or authors. |
| 3 | + * <p> |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * <p> |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * <p> |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package org.openrewrite.java.testing.junit5; |
| 17 | + |
| 18 | +import org.junit.jupiter.api.Test; |
| 19 | +import org.openrewrite.config.Environment; |
| 20 | +import org.openrewrite.test.RecipeSpec; |
| 21 | +import org.openrewrite.test.RewriteTest; |
| 22 | +import org.openrewrite.test.TypeValidation; |
| 23 | + |
| 24 | +import static org.openrewrite.java.Assertions.java; |
| 25 | +import static org.openrewrite.java.Assertions.mavenProject; |
| 26 | +import static org.openrewrite.maven.Assertions.pomXml; |
| 27 | + |
| 28 | +public class UpgradeOkHttpMockWebServerTest implements RewriteTest { |
| 29 | + |
| 30 | + @Override |
| 31 | + public void defaults(RecipeSpec spec) { |
| 32 | + spec |
| 33 | + .typeValidationOptions(TypeValidation.none()) |
| 34 | + .recipe(Environment.builder() |
| 35 | + .scanRuntimeClasspath() |
| 36 | + .build() |
| 37 | + .activateRecipes("org.openrewrite.java.testing.junit5.UpgradeOkHttpMockWebServer")); |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + void shouldUpgradeMavenDependency() { |
| 42 | + rewriteRun( |
| 43 | + mavenProject("project", |
| 44 | + //language=java |
| 45 | + java( |
| 46 | + """ |
| 47 | + import okhttp3.mockwebserver.MockWebServer; |
| 48 | + |
| 49 | + class Test { |
| 50 | + void test() { |
| 51 | + MockWebServer server = new MockWebServer(); |
| 52 | + } |
| 53 | + } |
| 54 | + """, |
| 55 | + """ |
| 56 | + import mockwebserver3.MockWebServer; |
| 57 | + |
| 58 | + class Test { |
| 59 | + void test() { |
| 60 | + MockWebServer server = new MockWebServer(); |
| 61 | + } |
| 62 | + } |
| 63 | + """ |
| 64 | + ), |
| 65 | + //language=xml |
| 66 | + pomXml( |
| 67 | + """ |
| 68 | + <project> |
| 69 | + <modelVersion>4.0.0</modelVersion> |
| 70 | + <groupId>com.example</groupId> |
| 71 | + <artifactId>demo</artifactId> |
| 72 | + <version>0.0.1-SNAPSHOT</version> |
| 73 | + <dependencies> |
| 74 | + <dependency> |
| 75 | + <groupId>com.squareup.okhttp3</groupId> |
| 76 | + <artifactId>mockwebserver</artifactId> |
| 77 | + <version>4.10.0</version> |
| 78 | + </dependency> |
| 79 | + </dependencies> |
| 80 | + </project> |
| 81 | + """, |
| 82 | + """ |
| 83 | + <project> |
| 84 | + <modelVersion>4.0.0</modelVersion> |
| 85 | + <groupId>com.example</groupId> |
| 86 | + <artifactId>demo</artifactId> |
| 87 | + <version>0.0.1-SNAPSHOT</version> |
| 88 | + <dependencies> |
| 89 | + <dependency> |
| 90 | + <groupId>com.squareup.okhttp3</groupId> |
| 91 | + <artifactId>mockwebserver3-junit5</artifactId> |
| 92 | + <version>5.0.0-alpha.11</version> |
| 93 | + </dependency> |
| 94 | + </dependencies> |
| 95 | + </project> |
| 96 | + """ |
| 97 | + ) |
| 98 | + ) |
| 99 | + ); |
| 100 | + } |
| 101 | +} |
0 commit comments