mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#255 adding unit test for existing mapping target
This commit is contained in:
parent
b5e18b54fc
commit
34a5765cbb
@ -37,7 +37,7 @@ import org.mapstruct.ap.testutil.IssueKey;
|
||||
@RunWith(AnnotationProcessorTestRunner.class)
|
||||
public class JavaExpressionTest {
|
||||
|
||||
@Test
|
||||
@Test
|
||||
@WithClasses({ SourceTargetMapper.class })
|
||||
public void testJavaExpressionInsertion() throws ParseException {
|
||||
Source source = new Source();
|
||||
@ -84,4 +84,25 @@ public class JavaExpressionTest {
|
||||
Date result = dateFormat.parse( date );
|
||||
return result;
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithClasses({ SourceTargetMapper.class })
|
||||
public void testJavaExpressionInsertionWithExistingTarget() throws ParseException {
|
||||
Source source = new Source();
|
||||
String format = "dd-MM-yyyy,hh:mm:ss";
|
||||
Date time = getTime( format, "09-01-2014,01:35:03" );
|
||||
|
||||
source.setFormat( format );
|
||||
source.setTime( time );
|
||||
Target target = new Target();
|
||||
|
||||
|
||||
Target target2 = SourceTargetMapper.INSTANCE.sourceToTargetWithMappingTarget( source, target );
|
||||
|
||||
assertThat( target ).isNotNull();
|
||||
assertThat( target.getTimeAndFormat().getTime() ).isEqualTo( time );
|
||||
assertThat( target.getTimeAndFormat().getFormat() ).isEqualTo( format );
|
||||
assertThat( target.getAnotherProp() ).isNull();
|
||||
assertThat( target ).isEqualTo( target2 );
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ package org.mapstruct.ap.test.source.expressions.java;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.MappingTarget;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@ -38,4 +39,11 @@ public interface SourceTargetMapper {
|
||||
@Mapping( target = "anotherProp", ignore = true )
|
||||
} )
|
||||
Target sourceToTarget(Source s);
|
||||
|
||||
@Mappings( {
|
||||
@Mapping( target = "timeAndFormat", expression = "java( new org.mapstruct.ap.test.source.expressions.java."
|
||||
+ "TimeAndFormat( s.getTime(), s.getFormat() ))" ),
|
||||
@Mapping( target = "anotherProp", ignore = true )
|
||||
} )
|
||||
Target sourceToTargetWithMappingTarget(Source s, @MappingTarget Target t);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user