From a507f0a7e5937fa18a1c8e85fdc21bd65fbe4a8e Mon Sep 17 00:00:00 2001 From: Raimund Klein <770876+Chessray@users.noreply.github.com> Date: Mon, 20 Jun 2022 08:39:45 +0100 Subject: [PATCH 1/3] Use Google's compile-testing library. --- extensions/build.gradle | 1 + .../ConverterMapperProcessorTest.java | 150 +++++++++--------- gradle/libs.versions.toml | 2 + 3 files changed, 81 insertions(+), 72 deletions(-) diff --git a/extensions/build.gradle b/extensions/build.gradle index 60962cc..447a80f 100644 --- a/extensions/build.gradle +++ b/extensions/build.gradle @@ -9,6 +9,7 @@ dependencies { testImplementation libs.assertj testImplementation libs.bundles.junit.jupiter testImplementation libs.commons.io + testImplementation libs.compile.testing testImplementation libs.guava testImplementation libs.mapstruct.core testImplementation libs.mockito diff --git a/extensions/src/test/java/org/mapstruct/extensions/spring/converter/ConverterMapperProcessorTest.java b/extensions/src/test/java/org/mapstruct/extensions/spring/converter/ConverterMapperProcessorTest.java index c852d2f..3077279 100644 --- a/extensions/src/test/java/org/mapstruct/extensions/spring/converter/ConverterMapperProcessorTest.java +++ b/extensions/src/test/java/org/mapstruct/extensions/spring/converter/ConverterMapperProcessorTest.java @@ -12,8 +12,7 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.core.convert.converter.Converter; -import javax.tools.*; -import java.io.IOException; +import javax.tools.JavaFileObject; import java.io.Writer; import java.lang.ref.WeakReference; import java.time.Clock; @@ -21,12 +20,11 @@ import java.util.Set; import static com.google.common.collect.Iterables.concat; -import static java.nio.file.Files.createTempDirectory; -import static java.util.Arrays.asList; -import static java.util.Collections.singletonList; +import static com.google.common.collect.Iterables.toArray; +import static com.google.testing.compile.JavaSourcesSubject.assertThat; import static javax.lang.model.element.Modifier.*; -import static javax.tools.StandardLocation.CLASS_OUTPUT; import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.api.InstanceOfAssertFactories.list; import static org.mockito.ArgumentMatchers.any; @ExtendWith(MockitoExtension.class) @@ -45,29 +43,6 @@ class ConverterMapperProcessorTest { private static Set commonCompilationUnits; private static final String PACKAGE_NAME = "test"; - private boolean compile(JavaFileObject... additionalCompilationUnits) throws IOException { - final JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); - - final DiagnosticCollector diagnostics = new DiagnosticCollector<>(); - final StandardJavaFileManager fileManager = - compiler.getStandardFileManager(diagnostics, null, null); - fileManager.setLocation(CLASS_OUTPUT, singletonList(createTempDirectory("classes").toFile())); - - final JavaCompiler.CompilationTask task = - compiler.getTask( - null, - fileManager, - diagnostics, - null, - null, - concat(commonCompilationUnits, asList(additionalCompilationUnits))); - task.setProcessors(singletonList(processor)); - - final boolean success = task.call(); - diagnostics.getDiagnostics().forEach(System.err::println); - return success; - } - @BeforeAll static void setupCommonSourceFiles() { commonCompilationUnits = @@ -152,46 +127,67 @@ private static TypeSpec buildConfigClassWithExternalConversion(final String clas } @Test - void shouldCompileSimpleConverterMapper() throws IOException { + void shouldCompileSimpleConverterMapper() { // Given final JavaFile mapperFile = JavaFile.builder( PACKAGE_NAME, converterMapperWithoutGenericSourceOrTargetTypeBuilder().build()) .build(); - // When - final boolean compileResult = compile(mapperFile.toJavaFileObject()); - - // Then - then(compileResult).isTrue(); + // When - Then + assertThat(mapperFile.toJavaFileObject(), commonCompilationUnits.toArray(new JavaFileObject[0])) + .processedWith(processor) + .compilesWithoutError(); + BDDMockito.then(adapterGenerator) + .should() + .writeConversionServiceAdapter(descriptorArgumentCaptor.capture(), any(Writer.class)); + then(descriptorArgumentCaptor.getValue()) + .isNotNull() + .extracting(ConversionServiceAdapterDescriptor::getFromToMappings) + .asInstanceOf(list(Pair.class)) + .containsExactly(Pair.of(CAR_CLASS_NAME, CAR_DTO_CLASS_NAME)); } @Test - void shouldCompileConverterMapperWithGenericSourceType() throws IOException { + void shouldCompileConverterMapperWithGenericSourceType() { // Given final JavaFile mapperFile = JavaFile.builder(PACKAGE_NAME, converterMapperWithGenericSourceTypeBuilder().build()) .build(); - // When - final boolean compileResult = compile(mapperFile.toJavaFileObject()); - - // Then - then(compileResult).isTrue(); + // When - Then + assertThat(mapperFile.toJavaFileObject(), commonCompilationUnits.toArray(new JavaFileObject[0])) + .processedWith(processor) + .compilesWithoutError(); + BDDMockito.then(adapterGenerator) + .should() + .writeConversionServiceAdapter(descriptorArgumentCaptor.capture(), any(Writer.class)); + then(descriptorArgumentCaptor.getValue()) + .isNotNull() + .extracting(ConversionServiceAdapterDescriptor::getFromToMappings) + .asInstanceOf(list(Pair.class)) + .containsExactly(Pair.of(genericSourceTypeName(), CAR_DTO_CLASS_NAME)); } @Test - void shouldCompileConverterMapperWithGenericTargetType() throws IOException { + void shouldCompileConverterMapperWithGenericTargetType() { // Given final JavaFile mapperFile = JavaFile.builder(PACKAGE_NAME, converterMapperWithGenericTargetTypeBuilder().build()) .build(); - // When - final boolean compileResult = compile(mapperFile.toJavaFileObject()); - - // Then - then(compileResult).isTrue(); + // When - Then + assertThat(mapperFile.toJavaFileObject(), commonCompilationUnits.toArray(new JavaFileObject[0])) + .processedWith(processor) + .compilesWithoutError(); + BDDMockito.then(adapterGenerator) + .should() + .writeConversionServiceAdapter(descriptorArgumentCaptor.capture(), any(Writer.class)); + then(descriptorArgumentCaptor.getValue()) + .isNotNull() + .extracting(ConversionServiceAdapterDescriptor::getFromToMappings) + .asInstanceOf(list(Pair.class)) + .containsExactly(Pair.of(CAR_CLASS_NAME, genericTargetTypeName())); } private static TypeSpec.Builder converterMapperWithoutGenericSourceOrTargetTypeBuilder() { @@ -207,15 +203,23 @@ private static TypeSpec.Builder converterMapperBuilder( } private static TypeSpec.Builder converterMapperWithGenericSourceTypeBuilder() { - return converterMapperBuilder( - ParameterizedTypeName.get(ClassName.get(WeakReference.class), CAR_CLASS_NAME), - CAR_DTO_CLASS_NAME); + return converterMapperBuilder(genericSourceTypeName(), CAR_DTO_CLASS_NAME); + } + + private static ParameterizedTypeName genericSourceTypeName() { + return genericTypeName(CAR_CLASS_NAME); + } + + private static ParameterizedTypeName genericTypeName(final ClassName wrappedClassName) { + return ParameterizedTypeName.get(ClassName.get(WeakReference.class), wrappedClassName); } private static TypeSpec.Builder converterMapperWithGenericTargetTypeBuilder() { - return converterMapperBuilder( - CAR_CLASS_NAME, - ParameterizedTypeName.get(ClassName.get(WeakReference.class), CAR_DTO_CLASS_NAME)); + return converterMapperBuilder(CAR_CLASS_NAME, genericTargetTypeName()); + } + + private static ParameterizedTypeName genericTargetTypeName() { + return genericTypeName(CAR_DTO_CLASS_NAME); } private static TypeSpec.Builder plainCarMapperBuilder( @@ -235,18 +239,19 @@ private static MethodSpec convertMethod( } @Test - void shouldIgnoreNonConverterMappers() throws IOException { + void shouldIgnoreNonConverterMappers() { // Given final JavaFile plainMapperFile = JavaFile.builder( PACKAGE_NAME, plainCarMapperBuilder(CAR_CLASS_NAME, CAR_DTO_CLASS_NAME).build()) .build(); - // When - final boolean compileResult = compile(plainMapperFile.toJavaFileObject()); - - // Then - then(compileResult).isTrue(); + // When - Then + assertThat( + plainMapperFile.toJavaFileObject(), + commonCompilationUnits.toArray(new JavaFileObject[0])) + .processedWith(processor) + .compilesWithoutError(); BDDMockito.then(adapterGenerator) .should() .writeConversionServiceAdapter(descriptorArgumentCaptor.capture(), any(Writer.class)); @@ -256,7 +261,7 @@ PACKAGE_NAME, plainCarMapperBuilder(CAR_CLASS_NAME, CAR_DTO_CLASS_NAME).build()) } @Test - void shouldProcessOnlyConvertMethodForMapperWithMultipleMethods() throws IOException { + void shouldProcessOnlyConvertMethodForMapperWithMultipleMethods() { // Given final JavaFile mapperFile = JavaFile.builder( @@ -266,11 +271,10 @@ void shouldProcessOnlyConvertMethodForMapperWithMultipleMethods() throws IOExcep .build()) .build(); - // When - final boolean compileResult = compile(mapperFile.toJavaFileObject()); - - // Then - then(compileResult).isTrue(); + // When - Then + assertThat(mapperFile.toJavaFileObject(), commonCompilationUnits.toArray(new JavaFileObject[0])) + .processedWith(processor) + .compilesWithoutError(); BDDMockito.then(adapterGenerator) .should() .writeConversionServiceAdapter(descriptorArgumentCaptor.capture(), any(Writer.class)); @@ -282,7 +286,7 @@ void shouldProcessOnlyConvertMethodForMapperWithMultipleMethods() throws IOExcep } @Test - void shouldAddConversionServiceCallsForExternalConversions() throws IOException { + void shouldAddConversionServiceCallsForExternalConversions() { // Given final JavaFile mappingConfigFile = JavaFile.builder( @@ -293,12 +297,14 @@ PACKAGE_NAME, buildConfigClassWithExternalConversion("StringToLocaleConfig")) PACKAGE_NAME, converterMapperWithoutGenericSourceOrTargetTypeBuilder().build()) .build(); - // When - final boolean compileResult = - compile(mappingConfigFile.toJavaFileObject(), mapperFile.toJavaFileObject()); - - // Then - then(compileResult).isTrue(); + // When - Then + assertThat( + mapperFile.toJavaFileObject(), + toArray( + concat(Set.of(mappingConfigFile.toJavaFileObject()), commonCompilationUnits), + JavaFileObject.class)) + .processedWith(processor) + .compilesWithoutError(); BDDMockito.then(adapterGenerator) .should() .writeConversionServiceAdapter(descriptorArgumentCaptor.capture(), any(Writer.class)); diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 80887d5..abc419a 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,6 +3,7 @@ asciidoctorPlugin = "3.3.2" assertj = "3.23.1" commons-io = "2.11.0" commons-lang3 = "3.12.0" +compile-testing = "0.19" guava = "31.1-jre" javapoet = "1.13.0" jsr250 = "1.0" @@ -18,6 +19,7 @@ versionsPlugin = "0.42.0" assertj = { group = "org.assertj", name = "assertj-core", version.ref = "assertj"} commons-io = { group = "commons-io", name = "commons-io", version.ref = "commons-io" } commons-lang3 = { group = "org.apache.commons", name = "commons-lang3", version.ref = "commons-lang3" } +compile-testing = { group = "com.google.testing.compile", name = "compile-testing", version.ref = "compile-testing" } guava = { group = "com.google.guava", name = "guava", version.ref = "guava" } javapoet = { group = "com.squareup", name = "javapoet", version.ref = "javapoet"} jsr250 = { group = "javax.annotation", name = "jsr250-api", version.ref = "jsr250" } From 93c8540d3e1109a9e33d76078c58220b37b988e4 Mon Sep 17 00:00:00 2001 From: Raimund Klein <770876+Chessray@users.noreply.github.com> Date: Tue, 26 Sep 2023 12:34:03 +0100 Subject: [PATCH 2/3] Google Compile Testing Library working now. --- .../converter/AbstractProcessorTest.java | 29 ++---- .../ConverterMapperProcessorTest.java | 89 +++++++++++-------- gradle/libs.versions.toml | 2 +- 3 files changed, 62 insertions(+), 58 deletions(-) diff --git a/extensions/src/test/java/org/mapstruct/extensions/spring/converter/AbstractProcessorTest.java b/extensions/src/test/java/org/mapstruct/extensions/spring/converter/AbstractProcessorTest.java index 621bf03..bce6625 100644 --- a/extensions/src/test/java/org/mapstruct/extensions/spring/converter/AbstractProcessorTest.java +++ b/extensions/src/test/java/org/mapstruct/extensions/spring/converter/AbstractProcessorTest.java @@ -1,14 +1,12 @@ package org.mapstruct.extensions.spring.converter; import static com.google.common.collect.Iterables.concat; -import static java.nio.file.Files.createTempDirectory; import static java.util.Arrays.asList; -import static java.util.Collections.singletonList; import static javax.lang.model.element.Modifier.*; -import static javax.tools.StandardLocation.CLASS_OUTPUT; +import com.google.testing.compile.Compilation; +import com.google.testing.compile.Compiler; import com.squareup.javapoet.*; -import java.io.IOException; import java.util.Set; import javax.annotation.processing.Processor; import javax.tools.*; @@ -49,27 +47,14 @@ protected static JavaFileObject toJavaFileObject(JavaFile.Builder fileBuilder) { COMPONENT_JAVA_FILE_OBJECT, LAZY_JAVA_FILE_OBJECT); - protected static boolean compile( - final Processor processor, final JavaFileObject... additionalCompilationUnits) - throws IOException { + protected static Compilation compile( + final Processor processor, final JavaFileObject... additionalCompilationUnits) { return compile(processor, concat(COMMON_COMPILATION_UNITS, asList(additionalCompilationUnits))); } - protected static boolean compile( - final Processor processor, final Iterable compilationUnits) - throws IOException { - final var compiler = ToolProvider.getSystemJavaCompiler(); - - final var diagnostics = new DiagnosticCollector(); - final var fileManager = compiler.getStandardFileManager(diagnostics, null, null); - fileManager.setLocation(CLASS_OUTPUT, singletonList(createTempDirectory("classes").toFile())); - - final var task = compiler.getTask(null, fileManager, diagnostics, null, null, compilationUnits); - task.setProcessors(singletonList(processor)); - - final var success = task.call(); - diagnostics.getDiagnostics().forEach(System.err::println); - return success; + protected static Compilation compile( + final Processor processor, final Iterable compilationUnits) { + return Compiler.javac().withProcessors(processor).compile(compilationUnits); } private static TypeSpec buildSimpleModelClassTypeSpec(final String className) { diff --git a/extensions/src/test/java/org/mapstruct/extensions/spring/converter/ConverterMapperProcessorTest.java b/extensions/src/test/java/org/mapstruct/extensions/spring/converter/ConverterMapperProcessorTest.java index bf2ff01..c260d4b 100644 --- a/extensions/src/test/java/org/mapstruct/extensions/spring/converter/ConverterMapperProcessorTest.java +++ b/extensions/src/test/java/org/mapstruct/extensions/spring/converter/ConverterMapperProcessorTest.java @@ -1,18 +1,23 @@ package org.mapstruct.extensions.spring.converter; +import static com.google.common.collect.Iterables.concat; +import static com.google.testing.compile.CompilationSubject.assertThat; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.RetentionPolicy.SOURCE; import static javax.lang.model.element.Modifier.*; import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.api.InstanceOfAssertFactories.list; import static org.mockito.ArgumentMatchers.any; +import com.google.testing.compile.Compilation; +import com.google.testing.compile.Compiler; import com.squareup.javapoet.*; -import java.io.IOException; import java.io.Writer; import java.lang.annotation.Retention; import java.lang.annotation.Target; import java.lang.ref.WeakReference; import java.time.Clock; +import java.util.List; import java.util.Locale; import javax.tools.*; import org.junit.jupiter.api.Test; @@ -51,7 +56,7 @@ class ConverterMapperProcessorTest extends AbstractProcessorTest { @Captor private ArgumentCaptor descriptorArgumentCaptor; - private boolean compile(final JavaFileObject... additionalCompilationUnits) throws IOException { + private Compilation compile(final JavaFileObject... additionalCompilationUnits) { return compile(processor, additionalCompilationUnits); } @@ -80,17 +85,19 @@ PACKAGE_NAME, converterMapperWithoutGenericSourceOrTargetTypeBuilder().build()) .build(); // When - Then - assertThat(mapperFile.toJavaFileObject(), commonCompilationUnits.toArray(new JavaFileObject[0])) - .processedWith(processor) - .compilesWithoutError(); + assertThat( + Compiler.javac() + .withProcessors(processor) + .compile(concat(List.of(mapperFile.toJavaFileObject()), COMMON_COMPILATION_UNITS))) + .succeeded(); BDDMockito.then(adapterGenerator) .should() - .writeConversionServiceAdapter(descriptorArgumentCaptor.capture(), any(Writer.class)); + .writeGeneratedCodeToOutput(descriptorArgumentCaptor.capture(), any(Writer.class)); then(descriptorArgumentCaptor.getValue()) .isNotNull() .extracting(ConversionServiceAdapterDescriptor::getFromToMappings) - .asInstanceOf(list(Pair.class)) - .containsExactly(Pair.of(CAR_CLASS_NAME, CAR_DTO_CLASS_NAME)); + .asInstanceOf(list(FromToMapping.class)) + .containsExactly(new FromToMapping().source(CAR_CLASS_NAME).target(CAR_DTO_CLASS_NAME)); } @Test @@ -101,17 +108,20 @@ void shouldCompileConverterMapperWithGenericSourceType() { .build(); // When - Then - assertThat(mapperFile.toJavaFileObject(), commonCompilationUnits.toArray(new JavaFileObject[0])) - .processedWith(processor) - .compilesWithoutError(); + assertThat( + Compiler.javac() + .withProcessors(processor) + .compile(concat(List.of(mapperFile.toJavaFileObject()), COMMON_COMPILATION_UNITS))) + .succeeded(); BDDMockito.then(adapterGenerator) .should() - .writeConversionServiceAdapter(descriptorArgumentCaptor.capture(), any(Writer.class)); + .writeGeneratedCodeToOutput(descriptorArgumentCaptor.capture(), any(Writer.class)); then(descriptorArgumentCaptor.getValue()) .isNotNull() .extracting(ConversionServiceAdapterDescriptor::getFromToMappings) - .asInstanceOf(list(Pair.class)) - .containsExactly(Pair.of(genericSourceTypeName(), CAR_DTO_CLASS_NAME)); + .asInstanceOf(list(FromToMapping.class)) + .containsExactly( + new FromToMapping().source(genericSourceTypeName()).target(CAR_DTO_CLASS_NAME)); } @Test @@ -122,17 +132,20 @@ void shouldCompileConverterMapperWithGenericTargetType() { .build(); // When - Then - assertThat(mapperFile.toJavaFileObject(), commonCompilationUnits.toArray(new JavaFileObject[0])) - .processedWith(processor) - .compilesWithoutError(); + assertThat( + Compiler.javac() + .withProcessors(processor) + .compile(concat(List.of(mapperFile.toJavaFileObject()), COMMON_COMPILATION_UNITS))) + .succeeded(); BDDMockito.then(adapterGenerator) .should() - .writeConversionServiceAdapter(descriptorArgumentCaptor.capture(), any(Writer.class)); + .writeGeneratedCodeToOutput(descriptorArgumentCaptor.capture(), any(Writer.class)); then(descriptorArgumentCaptor.getValue()) .isNotNull() .extracting(ConversionServiceAdapterDescriptor::getFromToMappings) - .asInstanceOf(list(Pair.class)) - .containsExactly(Pair.of(CAR_CLASS_NAME, genericTargetTypeName())); + .asInstanceOf(list(FromToMapping.class)) + .containsExactly( + new FromToMapping().source(CAR_CLASS_NAME).target(genericTargetTypeName())); } private static TypeSpec.Builder converterMapperWithoutGenericSourceOrTargetTypeBuilder() { @@ -193,10 +206,11 @@ PACKAGE_NAME, plainCarMapperBuilder(CAR_CLASS_NAME, CAR_DTO_CLASS_NAME).build()) // When - Then assertThat( - plainMapperFile.toJavaFileObject(), - commonCompilationUnits.toArray(new JavaFileObject[0])) - .processedWith(processor) - .compilesWithoutError(); + Compiler.javac() + .withProcessors(processor) + .compile( + concat(List.of(plainMapperFile.toJavaFileObject()), COMMON_COMPILATION_UNITS))) + .succeeded(); BDDMockito.then(adapterGenerator) .should() .writeGeneratedCodeToOutput(descriptorArgumentCaptor.capture(), any(Writer.class)); @@ -217,9 +231,11 @@ void shouldProcessOnlyConvertMethodForMapperWithMultipleMethods() { .build(); // When - Then - assertThat(mapperFile.toJavaFileObject(), commonCompilationUnits.toArray(new JavaFileObject[0])) - .processedWith(processor) - .compilesWithoutError(); + assertThat( + Compiler.javac() + .withProcessors(processor) + .compile(concat(List.of(mapperFile.toJavaFileObject()), COMMON_COMPILATION_UNITS))) + .succeeded(); BDDMockito.then(adapterGenerator) .should() .writeGeneratedCodeToOutput(descriptorArgumentCaptor.capture(), any(Writer.class)); @@ -244,12 +260,15 @@ PACKAGE_NAME, converterMapperWithoutGenericSourceOrTargetTypeBuilder().build()) // When - Then assertThat( - mapperFile.toJavaFileObject(), - toArray( - concat(Set.of(mappingConfigFile.toJavaFileObject()), commonCompilationUnits), - JavaFileObject.class)) - .processedWith(processor) - .compilesWithoutError(); + Compiler.javac() + .withProcessors(processor) + .compile( + concat( + List.of( + mapperFile.toJavaFileObject(), mappingConfigFile.toJavaFileObject()), + COMMON_COMPILATION_UNITS))) + .succeeded(); + BDDMockito.then(adapterGenerator) .should() .writeGeneratedCodeToOutput(descriptorArgumentCaptor.capture(), any(Writer.class)); @@ -265,7 +284,7 @@ PACKAGE_NAME, converterMapperWithoutGenericSourceOrTargetTypeBuilder().build()) } @Test - void shouldCompileMapperWithDelegatingConverterAnnotation() throws IOException { + void shouldCompileMapperWithDelegatingConverterAnnotation() { final var delegatingConverterAnnotationTypeSpec = TypeSpec.annotationBuilder(ClassName.get(DelegatingConverter.class)) .addAnnotation( @@ -316,6 +335,6 @@ void shouldCompileMapperWithDelegatingConverterAnnotation() throws IOException { mapperFile.toJavaFileObject(), autowiredFile.toJavaFileObject()); - then(compileResult).isTrue(); + assertThat(compileResult).succeeded(); } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 721fe8f..b2d2f57 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,7 +3,7 @@ asciidoctorPlugin = "3.3.2" assertj = "3.24.2" commons-io = "2.13.0" commons-lang3 = "3.13.0" -compile-testing = "0.19" +compile-testing = "0.21.0" dependencyCheck = "8.4.0" dummymaker = "4.0.0" guava = "32.1.2-jre" From f138f4fc66786292bef2c3e99635cdb773c4bd37 Mon Sep 17 00:00:00 2001 From: Raimund Klein <770876+Chessray@users.noreply.github.com> Date: Tue, 26 Sep 2023 13:19:45 +0100 Subject: [PATCH 3/3] Google Compile Testing Library working now. --- .../ConverterMapperProcessorTest.java | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/extensions/src/test/java/org/mapstruct/extensions/spring/converter/ConverterMapperProcessorTest.java b/extensions/src/test/java/org/mapstruct/extensions/spring/converter/ConverterMapperProcessorTest.java index c260d4b..cff7b1f 100644 --- a/extensions/src/test/java/org/mapstruct/extensions/spring/converter/ConverterMapperProcessorTest.java +++ b/extensions/src/test/java/org/mapstruct/extensions/spring/converter/ConverterMapperProcessorTest.java @@ -2,6 +2,7 @@ import static com.google.common.collect.Iterables.concat; import static com.google.testing.compile.CompilationSubject.assertThat; +import static com.google.testing.compile.Compiler.javac; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.RetentionPolicy.SOURCE; import static javax.lang.model.element.Modifier.*; @@ -10,7 +11,6 @@ import static org.mockito.ArgumentMatchers.any; import com.google.testing.compile.Compilation; -import com.google.testing.compile.Compiler; import com.squareup.javapoet.*; import java.io.Writer; import java.lang.annotation.Retention; @@ -86,7 +86,7 @@ PACKAGE_NAME, converterMapperWithoutGenericSourceOrTargetTypeBuilder().build()) // When - Then assertThat( - Compiler.javac() + javac() .withProcessors(processor) .compile(concat(List.of(mapperFile.toJavaFileObject()), COMMON_COMPILATION_UNITS))) .succeeded(); @@ -109,7 +109,7 @@ void shouldCompileConverterMapperWithGenericSourceType() { // When - Then assertThat( - Compiler.javac() + javac() .withProcessors(processor) .compile(concat(List.of(mapperFile.toJavaFileObject()), COMMON_COMPILATION_UNITS))) .succeeded(); @@ -133,7 +133,7 @@ void shouldCompileConverterMapperWithGenericTargetType() { // When - Then assertThat( - Compiler.javac() + javac() .withProcessors(processor) .compile(concat(List.of(mapperFile.toJavaFileObject()), COMMON_COMPILATION_UNITS))) .succeeded(); @@ -206,7 +206,7 @@ PACKAGE_NAME, plainCarMapperBuilder(CAR_CLASS_NAME, CAR_DTO_CLASS_NAME).build()) // When - Then assertThat( - Compiler.javac() + javac() .withProcessors(processor) .compile( concat(List.of(plainMapperFile.toJavaFileObject()), COMMON_COMPILATION_UNITS))) @@ -232,7 +232,7 @@ void shouldProcessOnlyConvertMethodForMapperWithMultipleMethods() { // When - Then assertThat( - Compiler.javac() + javac() .withProcessors(processor) .compile(concat(List.of(mapperFile.toJavaFileObject()), COMMON_COMPILATION_UNITS))) .succeeded(); @@ -260,7 +260,7 @@ PACKAGE_NAME, converterMapperWithoutGenericSourceOrTargetTypeBuilder().build()) // When - Then assertThat( - Compiler.javac() + javac() .withProcessors(processor) .compile( concat( @@ -329,12 +329,11 @@ void shouldCompileMapperWithDelegatingConverterAnnotation() { final var autowiredFile = JavaFile.builder("org.springframework.beans.factory.annotation", autowiredTypeSpec).build(); - final var compileResult = - compile( - delegatingConverterFile.toJavaFileObject(), - mapperFile.toJavaFileObject(), - autowiredFile.toJavaFileObject()); - - assertThat(compileResult).succeeded(); + assertThat( + compile( + delegatingConverterFile.toJavaFileObject(), + mapperFile.toJavaFileObject(), + autowiredFile.toJavaFileObject())) + .succeeded(); } }