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.
- Loading branch information
sjaakd
committed
May 10, 2019
1 parent
6990b69
commit c1a0c50
Showing
5 changed files
with
135 additions
and
0 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
20 changes: 20 additions & 0 deletions
20
processor/src/test/java/org/mapstruct/ap/test/builder/off/SimpleMapper.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,20 @@ | ||
/* | ||
* 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.builder.off; | ||
|
||
import org.mapstruct.BeanMapping; | ||
import org.mapstruct.Builder; | ||
import org.mapstruct.CollectionMappingStrategy; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
|
||
@Mapper(collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED) | ||
public interface SimpleMapper { | ||
|
||
@BeanMapping( builder = @Builder( noBuilder = true ) ) | ||
@Mapping(target = "name", source = "fullName") | ||
SimpleNotRealyImmutablePerson toNotRealyImmutable(SimpleMutablePerson source); | ||
} |
21 changes: 21 additions & 0 deletions
21
processor/src/test/java/org/mapstruct/ap/test/builder/off/SimpleMutablePerson.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,21 @@ | ||
/* | ||
* 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.builder.off; | ||
|
||
import java.util.List; | ||
|
||
public class SimpleMutablePerson { | ||
private String fullName; | ||
|
||
public String getFullName() { | ||
return fullName; | ||
} | ||
|
||
public void setFullName(String fullName) { | ||
this.fullName = fullName; | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
...r/src/test/java/org/mapstruct/ap/test/builder/off/SimpleNotRealyImmutableBuilderTest.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,42 @@ | ||
/* | ||
* 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.builder.off; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mapstruct.ap.testutil.IssueKey; | ||
import org.mapstruct.ap.testutil.WithClasses; | ||
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; | ||
import org.mapstruct.ap.testutil.runner.GeneratedSource; | ||
import org.mapstruct.factory.Mappers; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@IssueKey("1743") | ||
@WithClasses({ | ||
SimpleMutablePerson.class, | ||
SimpleNotRealyImmutablePerson.class | ||
}) | ||
@RunWith(AnnotationProcessorTestRunner.class) | ||
public class SimpleNotRealyImmutableBuilderTest { | ||
|
||
@Rule | ||
public final GeneratedSource generatedSource = new GeneratedSource(); | ||
|
||
@Test | ||
@WithClasses({ SimpleMapper.class }) | ||
public void testSimpleImmutableBuilderHappyPath() { | ||
SimpleMapper mapper = Mappers.getMapper( SimpleMapper.class ); | ||
SimpleMutablePerson source = new SimpleMutablePerson(); | ||
source.setFullName( "Bob" ); | ||
|
||
SimpleNotRealyImmutablePerson targetObject = mapper.toNotRealyImmutable( source ); | ||
|
||
assertThat( targetObject.getName() ).isEqualTo( "Bob" ); | ||
|
||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
processor/src/test/java/org/mapstruct/ap/test/builder/off/SimpleNotRealyImmutablePerson.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,44 @@ | ||
/* | ||
* 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.builder.off; | ||
|
||
public class SimpleNotRealyImmutablePerson { | ||
|
||
private String name; | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
public SimpleNotRealyImmutablePerson() { | ||
} | ||
|
||
SimpleNotRealyImmutablePerson(Builder builder) { | ||
this.name = builder.name; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public static class Builder { | ||
|
||
private String name; | ||
|
||
public Builder name(String name) { | ||
throw new IllegalStateException( "name should not be called on builder" ); | ||
} | ||
|
||
public SimpleNotRealyImmutablePerson build() { | ||
return new SimpleNotRealyImmutablePerson( this ); | ||
} | ||
|
||
} | ||
} |