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 {
@Mappings({
@Mapping(target = "address", ignore = true ),
@Mapping(target = "job", ignore = true ),
@Mapping(target = "city", ignore = true )
})

View File

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

View File

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

View File

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