|
23 | 23 | import io.spring.initializr.generator.buildsystem.DependencyScope; |
24 | 24 | import io.spring.initializr.generator.buildsystem.maven.MavenBuild; |
25 | 25 | import io.spring.initializr.generator.io.IndentingWriterFactory; |
| 26 | +import io.spring.initializr.generator.language.Language; |
| 27 | +import io.spring.initializr.generator.project.MutableProjectDescription; |
26 | 28 | import io.spring.initializr.generator.version.VersionProperty; |
27 | 29 | import io.spring.initializr.generator.version.VersionReference; |
| 30 | +import org.junit.jupiter.api.BeforeEach; |
28 | 31 | import org.junit.jupiter.api.Test; |
29 | 32 |
|
30 | 33 | import static org.assertj.core.api.Assertions.assertThat; |
|
36 | 39 | */ |
37 | 40 | class ConvertAnnotationProcessorsToPluginConfigBuildCustomizerTests { |
38 | 41 |
|
39 | | - private final ConvertAnnotationProcessorsToPluginConfigBuildCustomizer customizer = new ConvertAnnotationProcessorsToPluginConfigBuildCustomizer(); |
| 42 | + private ConvertAnnotationProcessorsToPluginConfigBuildCustomizer customizer; |
| 43 | + |
| 44 | + @BeforeEach |
| 45 | + void setUp() { |
| 46 | + MutableProjectDescription projectDescription = new MutableProjectDescription(); |
| 47 | + projectDescription.setLanguage(Language.forId("java", "17")); |
| 48 | + this.customizer = new ConvertAnnotationProcessorsToPluginConfigBuildCustomizer(projectDescription); |
| 49 | + } |
40 | 50 |
|
41 | 51 | @Test |
42 | 52 | void annotationProcessorIsConvertedToDefaultCompileExecution() throws IOException { |
@@ -358,6 +368,41 @@ void annotationProcessorWithExclusionsHasExclusionsInPath() throws IOException { |
358 | 368 | """); |
359 | 369 | } |
360 | 370 |
|
| 371 | + @Test |
| 372 | + void annotationProcessorIsNotConvertedForNonJavaLanguage() throws IOException { |
| 373 | + MutableProjectDescription projectDescription = new MutableProjectDescription(); |
| 374 | + projectDescription.setLanguage(Language.forId("kotlin", "17")); |
| 375 | + ConvertAnnotationProcessorsToPluginConfigBuildCustomizer kotlinCustomizer = new ConvertAnnotationProcessorsToPluginConfigBuildCustomizer( |
| 376 | + projectDescription); |
| 377 | + MavenBuild build = new MavenBuild(); |
| 378 | + build.dependencies() |
| 379 | + .add("configuration-processor", |
| 380 | + Dependency.withCoordinates("org.springframework.boot", "spring-boot-configuration-processor") |
| 381 | + .scope(DependencyScope.ANNOTATION_PROCESSOR) |
| 382 | + .build()); |
| 383 | + kotlinCustomizer.customize(build); |
| 384 | + String pom = generatePom(build); |
| 385 | + assertThat(pom).contains("<dependency>"); |
| 386 | + assertThat(pom).doesNotContain("<annotationProcessorPaths>"); |
| 387 | + } |
| 388 | + |
| 389 | + @Test |
| 390 | + void annotationProcessorIsNotConvertedWhenLanguageIsNull() throws IOException { |
| 391 | + MutableProjectDescription projectDescription = new MutableProjectDescription(); |
| 392 | + ConvertAnnotationProcessorsToPluginConfigBuildCustomizer nullLanguageCustomizer = new ConvertAnnotationProcessorsToPluginConfigBuildCustomizer( |
| 393 | + projectDescription); |
| 394 | + MavenBuild build = new MavenBuild(); |
| 395 | + build.dependencies() |
| 396 | + .add("configuration-processor", |
| 397 | + Dependency.withCoordinates("org.springframework.boot", "spring-boot-configuration-processor") |
| 398 | + .scope(DependencyScope.ANNOTATION_PROCESSOR) |
| 399 | + .build()); |
| 400 | + nullLanguageCustomizer.customize(build); |
| 401 | + String pom = generatePom(build); |
| 402 | + assertThat(pom).contains("<dependency>"); |
| 403 | + assertThat(pom).doesNotContain("<annotationProcessorPaths>"); |
| 404 | + } |
| 405 | + |
361 | 406 | private String generatePom(MavenBuild build) throws IOException { |
362 | 407 | StringWriter writer = new StringWriter(); |
363 | 408 | new MavenBuildProjectContributor(build, IndentingWriterFactory.withDefaultSettings()).writeBuild(writer); |
|
0 commit comments