Make sure we have a conflicting test with adder

This commit is contained in:
Filip Hrisafov 2018-04-28 10:05:49 +02:00
parent 84bf019fdf
commit b6905d5168
4 changed files with 25 additions and 1 deletions

View File

@ -27,6 +27,7 @@ import org.mapstruct.ReportingPolicy;
public interface ErroneousSimpleBuilderMapper { public interface ErroneousSimpleBuilderMapper {
@Mappings({ @Mappings({
@Mapping(target = "address", ignore = true ),
@Mapping(target = "job", ignore = true ), @Mapping(target = "job", ignore = true ),
@Mapping(target = "city", ignore = true ) @Mapping(target = "city", ignore = true )
}) })

View File

@ -51,6 +51,7 @@ public class SimpleImmutableBuilderTest {
source.setAge( 3 ); source.setAge( 3 );
source.setFullName( "Bob" ); source.setFullName( "Bob" );
source.setChildren( Arrays.asList( "Alice", "Tom" ) ); source.setChildren( Arrays.asList( "Alice", "Tom" ) );
source.setAddress( "Plaza 1" );
SimpleImmutablePerson targetObject = mapper.toImmutable( source ); SimpleImmutablePerson targetObject = mapper.toImmutable( source );
@ -58,6 +59,7 @@ public class SimpleImmutableBuilderTest {
assertThat( targetObject.getName() ).isEqualTo( "Bob" ); assertThat( targetObject.getName() ).isEqualTo( "Bob" );
assertThat( targetObject.getJob() ).isEqualTo( "programmer" ); assertThat( targetObject.getJob() ).isEqualTo( "programmer" );
assertThat( targetObject.getCity() ).isEqualTo( "Bengalore" ); assertThat( targetObject.getCity() ).isEqualTo( "Bengalore" );
assertThat( targetObject.getAddress() ).isEqualTo( "Plaza 1" );
assertThat( targetObject.getChildren() ).contains( "Alice", "Tom" ); assertThat( targetObject.getChildren() ).contains( "Alice", "Tom" );
} }
@ -67,7 +69,7 @@ public class SimpleImmutableBuilderTest {
diagnostics = @Diagnostic( diagnostics = @Diagnostic(
kind = javax.tools.Diagnostic.Kind.ERROR, kind = javax.tools.Diagnostic.Kind.ERROR,
type = ErroneousSimpleBuilderMapper.class, type = ErroneousSimpleBuilderMapper.class,
line = 33, line = 34,
messageRegExp = "Unmapped target property: \"name\"\\.")) messageRegExp = "Unmapped target property: \"name\"\\."))
public void testSimpleImmutableBuilderMissingPropertyFailsToCompile() { public void testSimpleImmutableBuilderMissingPropertyFailsToCompile() {
} }

View File

@ -26,6 +26,7 @@ public class SimpleImmutablePerson {
private final int age; private final int age;
private final String job; private final String job;
private final String city; private final String city;
private final String address;
private final List<String> children; private final List<String> children;
SimpleImmutablePerson(Builder builder) { SimpleImmutablePerson(Builder builder) {
@ -33,6 +34,7 @@ public class SimpleImmutablePerson {
this.age = builder.age; this.age = builder.age;
this.job = builder.job; this.job = builder.job;
this.city = builder.city; this.city = builder.city;
this.address = builder.address;
this.children = new ArrayList<String>( builder.children ); this.children = new ArrayList<String>( builder.children );
} }
@ -56,6 +58,10 @@ public class SimpleImmutablePerson {
return city; return city;
} }
public String getAddress() {
return address;
}
public List<String> getChildren() { public List<String> getChildren() {
return children; return children;
} }
@ -65,6 +71,7 @@ public class SimpleImmutablePerson {
private int age; private int age;
private String job; private String job;
private String city; private String city;
private String address;
private List<String> children = new ArrayList<String>(); private List<String> children = new ArrayList<String>();
public Builder age(int age) { public Builder age(int age) {
@ -91,6 +98,11 @@ public class SimpleImmutablePerson {
return this; return this;
} }
public Builder address(String address) {
this.address = address;
return this;
}
public List<String> getChildren() { public List<String> getChildren() {
throw new UnsupportedOperationException( "This is just a marker method" ); throw new UnsupportedOperationException( "This is just a marker method" );
} }

View File

@ -23,6 +23,7 @@ import java.util.List;
public class SimpleMutablePerson { public class SimpleMutablePerson {
private String fullName; private String fullName;
private int age; private int age;
private String address;
private List<String> children; private List<String> children;
public int getAge() { public int getAge() {
@ -41,6 +42,14 @@ public class SimpleMutablePerson {
this.fullName = fullName; this.fullName = fullName;
} }
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public List<String> getChildren() { public List<String> getChildren() {
return children; return children;
} }