11package org .mapstruct .extensions .spring .converter ;
22
3+ import static java .lang .Boolean .TRUE ;
4+ import static javax .lang .model .SourceVersion .RELEASE_9 ;
5+ import static org .mockito .BDDMockito .given ;
6+ import static org .mockito .Mockito .mock ;
7+
8+ import java .io .IOException ;
9+ import java .util .Map ;
10+ import javax .annotation .processing .ProcessingEnvironment ;
11+ import javax .lang .model .element .TypeElement ;
12+ import javax .lang .model .util .Elements ;
13+
314import org .junit .jupiter .api .BeforeEach ;
415import org .junit .jupiter .api .Nested ;
516import org .junit .jupiter .api .Test ;
617import org .junit .jupiter .api .extension .ExtendWith ;
718import org .mockito .Mock ;
819import org .mockito .junit .jupiter .MockitoExtension ;
9- import org .mockito .stubbing .Answer ;
10-
11- import javax .annotation .processing .ProcessingEnvironment ;
12- import javax .lang .model .SourceVersion ;
13- import javax .lang .model .element .TypeElement ;
14- import javax .lang .model .util .Elements ;
15- import java .io .IOException ;
16- import java .util .Map ;
17-
18- import static java .lang .Boolean .TRUE ;
19- import static javax .lang .model .SourceVersion .RELEASE_8 ;
20- import static javax .lang .model .SourceVersion .RELEASE_9 ;
21- import static org .mockito .BDDMockito .given ;
22- import static org .mockito .Mockito .mock ;
2320
2421@ ExtendWith (MockitoExtension .class )
2522abstract class AbstractConversionServiceBeanNameIndependentGeneratorTest extends AdapterRelatedGeneratorTest {
2623 @ Mock private Elements elements ;
2724
28- private boolean isAtLeastJava9 ;
29-
30- private final String java8GeneratedExpectedContentFilename ;
31- private final String java8GeneratedNoDateExpectedContentFileName ;
3225 private final String java9PlusGeneratedExpectedContentFileName ;
3326 private final String java9PlusGeneratedNoDateExpectedContentFileName ;
3427 private final String noGeneratedExpectedContentFileName ;
3528 private final AdapterRelatedGenerator underTest ;
3629
3730 protected AbstractConversionServiceBeanNameIndependentGeneratorTest (
38- final String java8GeneratedExpectedContentFilename ,
39- final String java8GeneratedNoDateExpectedContentFileName ,
4031 final String java9PlusGeneratedExpectedContentFileName ,
4132 final String java9PlusGeneratedNoDateExpectedContentFileName ,
4233 final String noGeneratedExpectedContentFileName ,
4334 final AdapterRelatedGenerator underTest ) {
44- this .java8GeneratedExpectedContentFilename = java8GeneratedExpectedContentFilename ;
45- this .java8GeneratedNoDateExpectedContentFileName = java8GeneratedNoDateExpectedContentFileName ;
4635 this .java9PlusGeneratedExpectedContentFileName = java9PlusGeneratedExpectedContentFileName ;
4736 this .java9PlusGeneratedNoDateExpectedContentFileName =
4837 java9PlusGeneratedNoDateExpectedContentFileName ;
@@ -57,49 +46,14 @@ class DefaultProcessingEnvironment {
5746 @ BeforeEach
5847 void initWithProcessingEnvironment () {
5948 given (processingEnvironment .getElementUtils ()).willReturn (elements );
60- given (processingEnvironment .getSourceVersion ())
61- .will (
62- (Answer <SourceVersion >)
63- (invocation ) -> {
64- if (isAtLeastJava9 ) {
65- return RELEASE_9 ;
66- } else {
67- return RELEASE_8 ;
68- }
69- });
49+ given (processingEnvironment .getSourceVersion ()).willReturn (RELEASE_9 );
7050 underTest .init (processingEnvironment );
7151 }
7252
73- @ Nested
74- class Java8Generated {
75- @ BeforeEach
76- void initElements () {
77- isAtLeastJava9 = false ;
78- given (elements .getTypeElement ("javax.annotation.Generated" ))
79- .willReturn (mock (TypeElement .class ));
80- }
81-
82- @ Test
83- void shouldGenerateMatchingOutput () throws IOException {
84- AbstractConversionServiceBeanNameIndependentGeneratorTest .this .shouldGenerateMatchingOutput (
85- java8GeneratedExpectedContentFilename , underTest ::writeGeneratedCodeToOutput );
86- }
87-
88- @ Test
89- void shouldSuppressDateGenerationWhenProcessingEnvironmentHasSuppressionSetToTrue ()
90- throws IOException {
91- given (processingEnvironment .getOptions ())
92- .willReturn (Map .of ("mapstruct.suppressGeneratorTimestamp" , String .valueOf (TRUE )));
93- AbstractConversionServiceBeanNameIndependentGeneratorTest .this .shouldGenerateMatchingOutput (
94- java8GeneratedNoDateExpectedContentFileName , underTest ::writeGeneratedCodeToOutput );
95- }
96- }
97-
9853 @ Nested
9954 class Java9PlusGenerated {
10055 @ BeforeEach
10156 void initElements () {
102- isAtLeastJava9 = true ;
10357 given (elements .getTypeElement ("javax.annotation.processing.Generated" ))
10458 .willReturn (mock (TypeElement .class ));
10559 }
@@ -122,11 +76,6 @@ void shouldSuppressDateGenerationWhenProcessingEnvironmentHasSuppressionSetToTru
12276
12377 @ Nested
12478 class NoGenerated {
125- @ BeforeEach
126- void initElements () {
127- isAtLeastJava9 = false ;
128- }
129-
13079 @ Test
13180 void shouldGenerateMatchingOutput () throws IOException {
13281 AbstractConversionServiceBeanNameIndependentGeneratorTest .this .shouldGenerateMatchingOutput (
0 commit comments