mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#94 Adding another test
This commit is contained in:
parent
77e6890b00
commit
3e34b6f6eb
@ -25,6 +25,8 @@ public class Source {
|
|||||||
|
|
||||||
private TimeAndFormat timeAndFormat;
|
private TimeAndFormat timeAndFormat;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
public TimeAndFormat getTimeAndFormat() {
|
public TimeAndFormat getTimeAndFormat() {
|
||||||
return timeAndFormat;
|
return timeAndFormat;
|
||||||
}
|
}
|
||||||
@ -32,4 +34,12 @@ public class Source {
|
|||||||
public void setTimeAndFormat(TimeAndFormat timeAndFormat) {
|
public void setTimeAndFormat(TimeAndFormat timeAndFormat) {
|
||||||
this.timeAndFormat = timeAndFormat;
|
this.timeAndFormat = timeAndFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,20 @@ public class SourcePropertyMapSeveralTimesTest extends MapperTestBase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@IssueKey("94")
|
@IssueKey("94")
|
||||||
public void shouldMapSameSourcePropertyToSeveralTargetProperties() throws ParseException {
|
public void shouldMapSameSourcePropertyToSeveralTargetProperties() {
|
||||||
|
Source source = new Source();
|
||||||
|
source.setName( "Bob" );
|
||||||
|
|
||||||
|
Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source );
|
||||||
|
|
||||||
|
assertThat( target ).isNotNull();
|
||||||
|
assertThat( target.getName1() ).isEqualTo( "Bob" );
|
||||||
|
assertThat( target.getName2() ).isEqualTo( "Bob" );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@IssueKey("94")
|
||||||
|
public void shouldMapSameSourcePropertyToSeveralTargetPropertiesInvokingOtherMapper() throws ParseException {
|
||||||
Source source = new Source();
|
Source source = new Source();
|
||||||
String sourceFormat = "dd-MM-yyyy";
|
String sourceFormat = "dd-MM-yyyy";
|
||||||
SimpleDateFormat dateFormat = new SimpleDateFormat( sourceFormat );
|
SimpleDateFormat dateFormat = new SimpleDateFormat( sourceFormat );
|
||||||
|
@ -32,6 +32,8 @@ public interface SourceTargetMapper {
|
|||||||
|
|
||||||
@Mappings(
|
@Mappings(
|
||||||
{
|
{
|
||||||
|
@Mapping(source = "name", target = "name1"),
|
||||||
|
@Mapping(source = "name", target = "name2"),
|
||||||
@Mapping(source = "timeAndFormat", target = "time"),
|
@Mapping(source = "timeAndFormat", target = "time"),
|
||||||
@Mapping(source = "timeAndFormat", target = "format")
|
@Mapping(source = "timeAndFormat", target = "format")
|
||||||
})
|
})
|
||||||
|
@ -27,6 +27,8 @@ public class Target {
|
|||||||
|
|
||||||
private String format;
|
private String format;
|
||||||
private Date time;
|
private Date time;
|
||||||
|
private String name1;
|
||||||
|
private String name2;
|
||||||
|
|
||||||
public String getFormat() {
|
public String getFormat() {
|
||||||
return format;
|
return format;
|
||||||
@ -43,4 +45,20 @@ public class Target {
|
|||||||
public void setTime(Date time) {
|
public void setTime(Date time) {
|
||||||
this.time = time;
|
this.time = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getName1() {
|
||||||
|
return name1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName1(String name1) {
|
||||||
|
this.name1 = name1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName2() {
|
||||||
|
return name2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName2(String name2) {
|
||||||
|
this.name2 = name2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,10 +26,10 @@ import java.util.Date;
|
|||||||
public class TimeAndFormatMapper {
|
public class TimeAndFormatMapper {
|
||||||
|
|
||||||
public String getFormat(TimeAndFormat t) {
|
public String getFormat(TimeAndFormat t) {
|
||||||
return t.getTfFormat();
|
return t != null ? t.getTfFormat() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getTime(TimeAndFormat t) {
|
public Date getTime(TimeAndFormat t) {
|
||||||
return t.getTfTime();
|
return t != null ? t.getTfTime() : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user