#94 Adding another test

This commit is contained in:
Gunnar Morling 2014-01-20 00:09:13 +01:00
parent 77e6890b00
commit 3e34b6f6eb
5 changed files with 46 additions and 3 deletions

View File

@ -25,6 +25,8 @@ public class Source {
private TimeAndFormat timeAndFormat;
private String name;
public TimeAndFormat getTimeAndFormat() {
return timeAndFormat;
}
@ -32,4 +34,12 @@ public class Source {
public void setTimeAndFormat(TimeAndFormat timeAndFormat) {
this.timeAndFormat = timeAndFormat;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -42,7 +42,20 @@ public class SourcePropertyMapSeveralTimesTest extends MapperTestBase {
@Test
@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();
String sourceFormat = "dd-MM-yyyy";
SimpleDateFormat dateFormat = new SimpleDateFormat( sourceFormat );

View File

@ -32,6 +32,8 @@ public interface SourceTargetMapper {
@Mappings(
{
@Mapping(source = "name", target = "name1"),
@Mapping(source = "name", target = "name2"),
@Mapping(source = "timeAndFormat", target = "time"),
@Mapping(source = "timeAndFormat", target = "format")
})

View File

@ -27,6 +27,8 @@ public class Target {
private String format;
private Date time;
private String name1;
private String name2;
public String getFormat() {
return format;
@ -43,4 +45,20 @@ public class Target {
public void setTime(Date 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;
}
}

View File

@ -26,10 +26,10 @@ import java.util.Date;
public class TimeAndFormatMapper {
public String getFormat(TimeAndFormat t) {
return t.getTfFormat();
return t != null ? t.getTfFormat() : null;
}
public Date getTime(TimeAndFormat t) {
return t.getTfTime();
return t != null ? t.getTfTime() : null;
}
}