|
| 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.lombok; |
| 17 | + |
| 18 | +import org.junit.jupiter.api.Test; |
| 19 | +import org.openrewrite.DocumentExample; |
| 20 | +import org.openrewrite.test.RecipeSpec; |
| 21 | +import org.openrewrite.test.RewriteTest; |
| 22 | + |
| 23 | +import java.util.regex.Matcher; |
| 24 | +import java.util.regex.Pattern; |
| 25 | + |
| 26 | +import static org.assertj.core.api.Assertions.assertThat; |
| 27 | +import static org.openrewrite.maven.Assertions.pomXml; |
| 28 | + |
| 29 | +class LombokBestPracticesTest implements RewriteTest { |
| 30 | + |
| 31 | + @Override |
| 32 | + public void defaults(RecipeSpec spec) { |
| 33 | + spec.recipeFromResource("/META-INF/rewrite/lombok.yml", |
| 34 | + "org.openrewrite.java.migrate.lombok.LombokBestPractices"); |
| 35 | + } |
| 36 | + |
| 37 | + @DocumentExample |
| 38 | + @Test |
| 39 | + void providedScope() { |
| 40 | + rewriteRun( |
| 41 | + pomXml( |
| 42 | + //language=xml |
| 43 | + """ |
| 44 | + <project> |
| 45 | + <modelVersion>4.0.0</modelVersion> |
| 46 | + <groupId>com.example</groupId> |
| 47 | + <artifactId>example</artifactId> |
| 48 | + <version>1.0.0</version> |
| 49 | + <dependencies> |
| 50 | + <dependency> |
| 51 | + <groupId>org.projectlombok</groupId> |
| 52 | + <artifactId>lombok</artifactId> |
| 53 | + <version>1.18.6</version> |
| 54 | + </dependency> |
| 55 | + <dependency> |
| 56 | + <groupId>org.projectlombok</groupId> |
| 57 | + <artifactId>lombok-mapstruct-binding</artifactId> |
| 58 | + <version>0.2.0</version> |
| 59 | + </dependency> |
| 60 | + </dependencies> |
| 61 | + </project> |
| 62 | + """, |
| 63 | + spec -> spec.after(pom -> { |
| 64 | + Matcher version = Pattern.compile("1.[1-9]\\d+(.\\d+)?").matcher(pom); |
| 65 | + assertThat(version.find()).isTrue(); |
| 66 | + //language=xml |
| 67 | + return """ |
| 68 | + <project> |
| 69 | + <modelVersion>4.0.0</modelVersion> |
| 70 | + <groupId>com.example</groupId> |
| 71 | + <artifactId>example</artifactId> |
| 72 | + <version>1.0.0</version> |
| 73 | + <dependencies> |
| 74 | + <dependency> |
| 75 | + <groupId>org.projectlombok</groupId> |
| 76 | + <artifactId>lombok</artifactId> |
| 77 | + <version>%s</version> |
| 78 | + <scope>provided</scope> |
| 79 | + </dependency> |
| 80 | + <dependency> |
| 81 | + <groupId>org.projectlombok</groupId> |
| 82 | + <artifactId>lombok-mapstruct-binding</artifactId> |
| 83 | + <version>0.2.0</version> |
| 84 | + <scope>provided</scope> |
| 85 | + </dependency> |
| 86 | + </dependencies> |
| 87 | + </project> |
| 88 | + """.formatted(version.group(0)); |
| 89 | + }) |
| 90 | + ) |
| 91 | + ); |
| 92 | + } |
| 93 | +} |
0 commit comments