forked from mapstruct/mapstruct
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changes for using a large constructor
- Loading branch information
Quinn Gil
committed
Mar 11, 2021
1 parent
228660c
commit c036a66
Showing
10 changed files
with
284 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
processor/src/test/java/org/mapstruct/ap/test/largestconstructor/IntSourceDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright MapStruct Authors. | ||
* | ||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
|
||
/** | ||
* @author Quinn Gil | ||
* | ||
*/ | ||
package org.mapstruct.ap.test.largestconstructor; | ||
|
||
public class IntSourceDto { | ||
private final int value; | ||
|
||
public IntSourceDto(int value) { | ||
this.value = value; | ||
} | ||
|
||
public int getIntValue() { | ||
return value; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...ssor/src/test/java/org/mapstruct/ap/test/largestconstructor/LargestConstructorMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright MapStruct Authors. | ||
* | ||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package org.mapstruct.ap.test.largestconstructor; | ||
|
||
import org.mapstruct.Mapper; | ||
import org.mapstruct.factory.Mappers; | ||
|
||
/** | ||
* @author Quinn Gil | ||
* | ||
*/ | ||
@Mapper | ||
public interface LargestConstructorMapper { | ||
|
||
LargestConstructorMapper INSTANCE = Mappers.getMapper( LargestConstructorMapper.class ); | ||
|
||
SingleLargestDto mapSingleToSingle(StringSourceDto dto); | ||
|
||
SingleLargestWithDefaultDto mapMultipleToDefault(IntSourceDto dto); | ||
|
||
MultipleLargestDto mapMultipleToEmpty(StringSourceDto dto); | ||
} |
70 changes: 70 additions & 0 deletions
70
processor/src/test/java/org/mapstruct/ap/test/largestconstructor/LargestConstructorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright MapStruct Authors. | ||
* | ||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package org.mapstruct.ap.test.largestconstructor; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mapstruct.ap.test.constructor.Default; | ||
import org.mapstruct.ap.testutil.WithClasses; | ||
import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption; | ||
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/*** | ||
* @author Quinn Gil | ||
*/ | ||
@WithClasses({ | ||
Default.class, | ||
LargestConstructorMapper.class, | ||
SingleLargestDto.class, | ||
StringSourceDto.class, | ||
IntSourceDto.class, | ||
SingleLargestWithDefaultDto.class, | ||
MultipleLargestDto.class | ||
}) | ||
@RunWith(AnnotationProcessorTestRunner.class) | ||
public class LargestConstructorTest { | ||
|
||
@Test | ||
@ProcessorOption( name = "mapstruct.useMostParametersConstructor", value = "true") | ||
public void useLargestConstructorWithSetting() { | ||
StringSourceDto source = new StringSourceDto("source value"); | ||
|
||
SingleLargestDto target = LargestConstructorMapper.INSTANCE.mapSingleToSingle( source ); | ||
|
||
assertThat( target.getStringValue() ).isEqualTo( "source value" ); | ||
} | ||
|
||
@Test | ||
public void useEmptyConstructorWithoutSetting() { | ||
StringSourceDto source = new StringSourceDto("source value"); | ||
|
||
SingleLargestDto target = LargestConstructorMapper.INSTANCE.mapSingleToSingle( source ); | ||
|
||
assertThat( target.getStringValue() ).isEqualTo( "from empty constructor" ); | ||
} | ||
|
||
@Test | ||
@ProcessorOption( name = "mapstruct.useMostParametersConstructor", value = "true") | ||
public void useDefaultAnnotationWithSetting() { | ||
IntSourceDto source = new IntSourceDto(1234); | ||
|
||
SingleLargestWithDefaultDto target = LargestConstructorMapper.INSTANCE.mapMultipleToDefault( source ); | ||
|
||
assertThat( target.getValue() ).isEqualTo( "from default annotation constructor" ); | ||
} | ||
|
||
@Test | ||
@ProcessorOption( name = "mapstruct.useMostParametersConstructor", value = "true") | ||
public void useEmptyWhenMultipleLargestPresent() { | ||
StringSourceDto source = new StringSourceDto("source value"); | ||
|
||
MultipleLargestDto target = LargestConstructorMapper.INSTANCE.mapMultipleToEmpty( source ); | ||
|
||
assertThat( target.getStringValue() ).isEqualTo( "from empty constructor" ); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
processor/src/test/java/org/mapstruct/ap/test/largestconstructor/MultipleLargestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright MapStruct Authors. | ||
* | ||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package org.mapstruct.ap.test.largestconstructor; | ||
|
||
/** | ||
* @author Quinn Gil | ||
* | ||
*/ | ||
public class MultipleLargestDto { | ||
|
||
private final String stringValue; | ||
private final int intValue; | ||
|
||
public MultipleLargestDto(String stringValue) { | ||
this.stringValue = stringValue; | ||
this.intValue = -1; | ||
} | ||
|
||
public MultipleLargestDto(int intValue) { | ||
this.intValue = intValue; | ||
this.stringValue = "from int constructor"; | ||
} | ||
|
||
public MultipleLargestDto() { | ||
stringValue = "from empty constructor"; | ||
intValue = 1; | ||
} | ||
|
||
public String getStringValue() { | ||
return stringValue; | ||
} | ||
|
||
public int getIntValue() { | ||
return intValue; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
processor/src/test/java/org/mapstruct/ap/test/largestconstructor/SingleLargestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright MapStruct Authors. | ||
* | ||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package org.mapstruct.ap.test.largestconstructor; | ||
|
||
/** | ||
* @author Quinn Gil | ||
* | ||
*/ | ||
public class SingleLargestDto { | ||
|
||
private final String stringValue; | ||
|
||
public SingleLargestDto(String stringValue) { | ||
this.stringValue = stringValue; | ||
} | ||
|
||
public SingleLargestDto() { | ||
stringValue = "from empty constructor"; | ||
} | ||
|
||
public String getStringValue() { | ||
return stringValue; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...r/src/test/java/org/mapstruct/ap/test/largestconstructor/SingleLargestWithDefaultDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright MapStruct Authors. | ||
* | ||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package org.mapstruct.ap.test.largestconstructor; | ||
|
||
import org.mapstruct.ap.test.constructor.Default; | ||
|
||
/** | ||
* @author Quinn Gil | ||
* | ||
*/ | ||
public class SingleLargestWithDefaultDto { | ||
|
||
private final String value; | ||
private final int intValue; | ||
|
||
public SingleLargestWithDefaultDto(String value, int intValue) { | ||
this.value = value; | ||
this.intValue = intValue; | ||
} | ||
|
||
@Default | ||
public SingleLargestWithDefaultDto(int intValue) { | ||
value = "from default annotation constructor"; | ||
this.intValue = intValue; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
public int getIntValue() { | ||
return intValue; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
processor/src/test/java/org/mapstruct/ap/test/largestconstructor/StringSourceDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright MapStruct Authors. | ||
* | ||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package org.mapstruct.ap.test.largestconstructor; | ||
|
||
/** | ||
* @author Quinn Gil | ||
* | ||
*/ | ||
public class StringSourceDto { | ||
private final String value; | ||
|
||
public StringSourceDto(String value) { | ||
this.value = value; | ||
} | ||
|
||
public String getStringValue() { | ||
return value; | ||
} | ||
} |