Skip to content

Instantly share code, notes, and snippets.

@sjaakd
Created April 6, 2014 09:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sjaakd/10003485 to your computer and use it in GitHub Desktop.
Save sjaakd/10003485 to your computer and use it in GitHub Desktop.
package org.mapstruct.ap.test.sourcenobean;
/**
*
* @author Sjaak Derksen
*/
public class Source {
private String val1;
private String val2;
public String getVal1() {
return val1;
}
public void setVal1( String val1 ) {
this.val1 = val1;
}
public String getVal2() {
return val2;
}
public void setVal2( String val2 ) {
this.val2 = val2;
}
}
package org.mapstruct.ap.test.sourcenobean;
import java.text.ParseException;
import static org.fest.assertions.Assertions.assertThat;
import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.MapperTestBase;
import org.mapstruct.ap.testutil.WithClasses;
import org.testng.annotations.Test;
/**
*
* @author Sjaak Derksen
*/
@WithClasses({ Source.class, Target.class, SourceTargetMapper.class })
public class SourceNoBeanTest extends MapperTestBase {
@Test(enabled = false)
@IssueKey("182")
public void shouldMapSameSourcePropertyToSeveralTargetProperties() throws ParseException {
Source source = new Source();
source.setVal1( "val1" );
source.setVal2( "val2" );
Target target = SourceTargetMapper.INSTANCE.sourceToTarget( 5, source, "7" );
assertThat( target ).isNotNull();
assertThat( target.getArgName1() ).isEqualTo( 5 );
assertThat( target.getVal1() ).isEqualTo( "val1" );
assertThat( target.getValx() ).isEqualTo( "val2" );
assertThat( target.getArgName2() ).isEqualTo( 7 );
}
}
package org.mapstruct.ap.test.sourcenobean;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
/**
*
* @author Sjaak Derksen
*/
@Mapper
public interface SourceTargetMapper {
SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class );
@Mapping(source = "val2", target = "valx" )
Target sourceToTarget(Integer argName1, Source arg2, String argName2);
}
package org.mapstruct.ap.test.sourcenobean;
/**
*
* @author Sjaak Derksen
*/
public class Target {
private Integer argName1;
private Integer argName2;
private String val1;
private String valx;
public Integer getArgName1() {
return argName1;
}
public void setArgName1( Integer argName1 ) {
this.argName1 = argName1;
}
public Integer getArgName2() {
return argName2;
}
public void setArgName2( Integer argName2 ) {
this.argName2 = argName2;
}
public String getVal1() {
return val1;
}
public void setVal1( String val1 ) {
this.val1 = val1;
}
public String getValx() {
return valx;
}
public void setValx( String valx ) {
this.valx = valx;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment