Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ jobs:

steps:
- uses: actions/checkout@v5
- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v5
with:
distribution: 'zulu'
java-version: 11
java-version: 17
- name: Build with Gradle
uses: gradle/gradle-build-action@v3
with:
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ subprojects {
apply plugin: "jacoco"

group = 'org.mapstruct.extensions.spring'
version = '1.1.4-SNAPSHOT'
version = '2.0.0-SNAPSHOT'

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(11))
languageVersion.set(JavaLanguageVersion.of(17))
}

withJavadocJar()
Expand Down
1 change: 0 additions & 1 deletion examples/classname/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ dependencies {
testImplementation projects.testExtensions
testImplementation libs.assertj
testImplementation libs.bundles.junit.jupiter
implementation libs.jsr250
implementation libs.mapstruct.core
annotationProcessor libs.mapstruct.processor
implementation libs.spring.context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ dependencies {

testImplementation libs.assertj
testImplementation libs.bundles.junit.jupiter
implementation libs.jsr250
implementation libs.jakarta.annotation
implementation libs.mapstruct.core
annotationProcessor libs.mapstruct.processor
implementation libs.spring.context
Expand Down
1 change: 0 additions & 1 deletion examples/custom-conversion-service-bean/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ dependencies {

testImplementation libs.assertj
testImplementation libs.bundles.junit.jupiter
implementation libs.jsr250
implementation libs.mapstruct.core
annotationProcessor libs.mapstruct.processor
implementation libs.spring.context
Expand Down
1 change: 0 additions & 1 deletion examples/noconfig/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ dependencies {
testImplementation projects.testExtensions
testImplementation libs.assertj
testImplementation libs.bundles.junit.jupiter
implementation libs.jsr250
implementation libs.mapstruct.core
annotationProcessor libs.mapstruct.processor
implementation libs.spring.context
Expand Down
1 change: 0 additions & 1 deletion examples/packagename-and-classname/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ dependencies {
testImplementation projects.testExtensions
testImplementation libs.assertj
testImplementation libs.bundles.junit.jupiter
implementation libs.jsr250
implementation libs.mapstruct.core
annotationProcessor libs.mapstruct.processor
implementation libs.spring.context
Expand Down
1 change: 0 additions & 1 deletion examples/packagename/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ dependencies {
testImplementation projects.testExtensions
testImplementation libs.assertj
testImplementation libs.bundles.junit.jupiter
implementation libs.jsr250
implementation libs.mapstruct.core
annotationProcessor libs.mapstruct.processor
implementation libs.spring.context
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package org.mapstruct.extensions.spring.converter;

import static javax.lang.model.element.Modifier.*;
import static javax.lang.model.element.Modifier.FINAL;
import static javax.lang.model.element.Modifier.PRIVATE;

import com.squareup.javapoet.*;
import java.time.Clock;
import java.util.List;
import java.util.Optional;

import com.squareup.javapoet.AnnotationSpec;
import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.FieldSpec;
import com.squareup.javapoet.MethodSpec;
import com.squareup.javapoet.ParameterSpec;
import com.squareup.javapoet.ParameterizedTypeName;
import com.squareup.javapoet.TypeSpec;
import com.squareup.javapoet.WildcardTypeName;

public class ConverterRegistrationConfigurationGenerator extends AdapterRelatedGenerator {

private static final ClassName CONFIGURABLE_CONVERSION_SERVICE_CLASS_NAME =
Expand Down Expand Up @@ -56,11 +65,7 @@ protected TypeSpec createMainTypeSpec(final ConversionServiceAdapterDescriptor d
}

private ClassName postConstructClassName() {
if (isTypeAvailable("jakarta.annotation.PostConstruct")) {
return ClassName.get("jakarta.annotation", "PostConstruct");
} else {
return ClassName.get("javax.annotation", "PostConstruct");
}
}

private MethodSpec createRegistrationMethodSpec(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,48 +1,37 @@
package org.mapstruct.extensions.spring.converter;

import static java.lang.Boolean.TRUE;
import static javax.lang.model.SourceVersion.RELEASE_9;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;

import java.io.IOException;
import java.util.Map;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.Elements;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.stubbing.Answer;

import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.Elements;
import java.io.IOException;
import java.util.Map;

import static java.lang.Boolean.TRUE;
import static javax.lang.model.SourceVersion.RELEASE_8;
import static javax.lang.model.SourceVersion.RELEASE_9;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;

@ExtendWith(MockitoExtension.class)
abstract class AbstractConversionServiceBeanNameIndependentGeneratorTest extends AdapterRelatedGeneratorTest {
@Mock private Elements elements;

private boolean isAtLeastJava9;

private final String java8GeneratedExpectedContentFilename;
private final String java8GeneratedNoDateExpectedContentFileName;
private final String java9PlusGeneratedExpectedContentFileName;
private final String java9PlusGeneratedNoDateExpectedContentFileName;
private final String noGeneratedExpectedContentFileName;
private final AdapterRelatedGenerator underTest;

protected AbstractConversionServiceBeanNameIndependentGeneratorTest(
final String java8GeneratedExpectedContentFilename,
final String java8GeneratedNoDateExpectedContentFileName,
final String java9PlusGeneratedExpectedContentFileName,
final String java9PlusGeneratedNoDateExpectedContentFileName,
final String noGeneratedExpectedContentFileName,
final AdapterRelatedGenerator underTest) {
this.java8GeneratedExpectedContentFilename = java8GeneratedExpectedContentFilename;
this.java8GeneratedNoDateExpectedContentFileName = java8GeneratedNoDateExpectedContentFileName;
this.java9PlusGeneratedExpectedContentFileName = java9PlusGeneratedExpectedContentFileName;
this.java9PlusGeneratedNoDateExpectedContentFileName =
java9PlusGeneratedNoDateExpectedContentFileName;
Expand All @@ -57,49 +46,14 @@ class DefaultProcessingEnvironment {
@BeforeEach
void initWithProcessingEnvironment() {
given(processingEnvironment.getElementUtils()).willReturn(elements);
given(processingEnvironment.getSourceVersion())
.will(
(Answer<SourceVersion>)
(invocation) -> {
if (isAtLeastJava9) {
return RELEASE_9;
} else {
return RELEASE_8;
}
});
given(processingEnvironment.getSourceVersion()).willReturn(RELEASE_9);
underTest.init(processingEnvironment);
}

@Nested
class Java8Generated {
@BeforeEach
void initElements() {
isAtLeastJava9 = false;
given(elements.getTypeElement("javax.annotation.Generated"))
.willReturn(mock(TypeElement.class));
}

@Test
void shouldGenerateMatchingOutput() throws IOException {
AbstractConversionServiceBeanNameIndependentGeneratorTest.this.shouldGenerateMatchingOutput(
java8GeneratedExpectedContentFilename, underTest::writeGeneratedCodeToOutput);
}

@Test
void shouldSuppressDateGenerationWhenProcessingEnvironmentHasSuppressionSetToTrue()
throws IOException {
given(processingEnvironment.getOptions())
.willReturn(Map.of("mapstruct.suppressGeneratorTimestamp", String.valueOf(TRUE)));
AbstractConversionServiceBeanNameIndependentGeneratorTest.this.shouldGenerateMatchingOutput(
java8GeneratedNoDateExpectedContentFileName, underTest::writeGeneratedCodeToOutput);
}
}

@Nested
class Java9PlusGenerated {
@BeforeEach
void initElements() {
isAtLeastJava9 = true;
given(elements.getTypeElement("javax.annotation.processing.Generated"))
.willReturn(mock(TypeElement.class));
}
Expand All @@ -122,11 +76,6 @@ void shouldSuppressDateGenerationWhenProcessingEnvironmentHasSuppressionSetToTru

@Nested
class NoGenerated {
@BeforeEach
void initElements() {
isAtLeastJava9 = false;
}

@Test
void shouldGenerateMatchingOutput() throws IOException {
AbstractConversionServiceBeanNameIndependentGeneratorTest.this.shouldGenerateMatchingOutput(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
package org.mapstruct.extensions.spring.converter;

import static java.lang.Boolean.TRUE;
import static javax.lang.model.SourceVersion.RELEASE_8;
import static javax.lang.model.SourceVersion.RELEASE_9;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;

import java.io.IOException;
import java.util.Map;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.Elements;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.stubbing.Answer;

@ExtendWith(MockitoExtension.class)
class ConversionServiceAdapterGeneratorTest extends AdapterRelatedGeneratorTest {
@Mock private Elements elements;

private boolean isAtLeastJava9;

private final ConversionServiceAdapterGenerator underTest =
new ConversionServiceAdapterGenerator(FIXED_CLOCK);

Expand All @@ -36,59 +32,14 @@ class DefaultProcessingEnvironment {
@BeforeEach
void initWithProcessingEnvironment() {
given(processingEnvironment.getElementUtils()).willReturn(elements);
given(processingEnvironment.getSourceVersion())
.will(
(Answer<SourceVersion>)
(invocation) -> {
if (isAtLeastJava9) {
return RELEASE_9;
} else {
return RELEASE_8;
}
});
given(processingEnvironment.getSourceVersion()).willReturn(RELEASE_9);
underTest.init(processingEnvironment);
}

@Nested
class Java8Generated {
@BeforeEach
void initElements() {
isAtLeastJava9 = false;
given(elements.getTypeElement("javax.annotation.Generated"))
.willReturn(mock(TypeElement.class));
}

@Test
void shouldGenerateMatchingOutput() throws IOException {
ConversionServiceAdapterGeneratorTest.this.shouldGenerateMatchingOutput(
"ConversionServiceAdapterJava8Generated.java",
underTest::writeGeneratedCodeToOutput);
}

@Test
void shouldGenerateMatchingOutputWhenUsingCustomConversionService() throws IOException {
ConversionServiceAdapterGeneratorTest.this
.shouldGenerateMatchingOutputWhenUsingCustomConversionService(
"ConversionServiceAdapterCustomBeanJava8Generated.java",
underTest::writeGeneratedCodeToOutput);
}

@Test
void shouldSuppressDateGenerationWhenProcessingEnvironmentHasSuppressionSetToTrue()
throws IOException {
given(processingEnvironment.getOptions())
.willReturn(Map.of("mapstruct.suppressGeneratorTimestamp", String.valueOf(TRUE)));
ConversionServiceAdapterGeneratorTest.this.shouldGenerateMatchingOutput(
"ConversionServiceAdapterJava8GeneratedNoDate.java",
underTest::writeGeneratedCodeToOutput);
}
}

@Nested
class Java9PlusGenerated {
@BeforeEach
void initElements() {
isAtLeastJava9 = true;
given(elements.getTypeElement("javax.annotation.processing.Generated"))
.willReturn(mock(TypeElement.class));
}
Expand Down Expand Up @@ -121,11 +72,6 @@ void shouldSuppressDateGenerationWhenProcessingEnvironmentHasSuppressionSetToTru

@Nested
class NoGenerated {
@BeforeEach
void initElements() {
isAtLeastJava9 = false;
}

@Test
void shouldGenerateMatchingOutput() throws IOException {
ConversionServiceAdapterGeneratorTest.this.shouldGenerateMatchingOutput(
Expand Down
Loading
Loading