|
| 1 | +/* |
| 2 | + * Copyright 2025 the original author or authors. |
| 3 | + * <p> |
| 4 | + * Licensed under the Moderne Source Available License (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://docs.moderne.io/licensing/moderne-source-available-license |
| 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.migrate; |
| 17 | + |
| 18 | +import org.junit.jupiter.api.Test; |
| 19 | +import org.openrewrite.DocumentExample; |
| 20 | +import org.openrewrite.config.Environment; |
| 21 | +import org.openrewrite.maven.tree.MavenResolutionResult; |
| 22 | +import org.openrewrite.test.RecipeSpec; |
| 23 | +import org.openrewrite.test.RewriteTest; |
| 24 | + |
| 25 | +import static org.assertj.core.api.Assertions.assertThat; |
| 26 | +import static org.openrewrite.java.Assertions.mavenProject; |
| 27 | +import static org.openrewrite.java.Assertions.version; |
| 28 | +import static org.openrewrite.maven.Assertions.pomXml; |
| 29 | + |
| 30 | +class Java8toJava11Test implements RewriteTest { |
| 31 | + |
| 32 | + @Override |
| 33 | + public void defaults(RecipeSpec spec) { |
| 34 | + spec.recipe(Environment.builder() |
| 35 | + .scanRuntimeClasspath("org.openrewrite.java.migrate") |
| 36 | + .build() |
| 37 | + .activateRecipes("org.openrewrite.java.migrate.UpgradePluginsForJava11")); |
| 38 | + } |
| 39 | + |
| 40 | + @DocumentExample |
| 41 | + @Test |
| 42 | + void needToJaxb2MavenPlugin() { |
| 43 | + rewriteRun( |
| 44 | + version( |
| 45 | + mavenProject("project", |
| 46 | + //language=xml |
| 47 | + pomXml( |
| 48 | + """ |
| 49 | + <project> |
| 50 | + <groupId>com.mycompany.app</groupId> |
| 51 | + <artifactId>my-app</artifactId> |
| 52 | + <version>1</version> |
| 53 | + <build> |
| 54 | + <plugins> |
| 55 | + <plugin> |
| 56 | + <groupId>org.codehaus.mojo</groupId> |
| 57 | + <artifactId>jaxb2-maven-plugin</artifactId> |
| 58 | + <version>2.3.1</version> |
| 59 | + </plugin> |
| 60 | + </plugins> |
| 61 | + </build> |
| 62 | + </project> |
| 63 | + """, |
| 64 | + after -> after.after(pomXml -> pomXml) |
| 65 | + .afterRecipe(doc -> assertThat(doc.getMarkers().findFirst(MavenResolutionResult.class)) |
| 66 | + .hasValueSatisfying(mrr -> mrr.getPom().getPlugins().get(0).getVersion().startsWith("2.5."))) |
| 67 | + ) |
| 68 | + ), |
| 69 | + 8) |
| 70 | + ); |
| 71 | + } |
| 72 | + |
| 73 | + @Test |
| 74 | + void noChangeOnCorrectJaxb2MavenPluginVersion() { |
| 75 | + rewriteRun( |
| 76 | + version( |
| 77 | + mavenProject("project", |
| 78 | + //language=xml |
| 79 | + pomXml( |
| 80 | + """ |
| 81 | + <project> |
| 82 | + <groupId>com.mycompany.app</groupId> |
| 83 | + <artifactId>my-app</artifactId> |
| 84 | + <version>1</version> |
| 85 | + <properties> |
| 86 | + <maven.compiler.release>11</maven.compiler.release> |
| 87 | + </properties> |
| 88 | + <build> |
| 89 | + <plugins> |
| 90 | + <plugin> |
| 91 | + <groupId>org.codehaus.mojo</groupId> |
| 92 | + <artifactId>jaxb2-maven-plugin</artifactId> |
| 93 | + <version>2.5.0</version> |
| 94 | + </plugin> |
| 95 | + </plugins> |
| 96 | + </build> |
| 97 | + </project> |
| 98 | + """ |
| 99 | + ) |
| 100 | + ), |
| 101 | + 11) |
| 102 | + ); |
| 103 | + } |
| 104 | +} |
0 commit comments