Last active
August 29, 2015 14:03
-
-
Save pepperbob/5e22a54e6578a3655469 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import static org.junit.Assert.*; | |
| import java.util.Arrays; | |
| import org.junit.Test; | |
| import org.modelmapper.ModelMapper; | |
| import org.modelmapper.PropertyMap; | |
| public class ModelmapperTest { | |
| ModelMapper mapper = new ModelMapper(); | |
| static class A { | |
| private String title; | |
| private byte[] someBytes; | |
| public String getTitle() { | |
| return title; | |
| } | |
| public void setTitle(String title) { | |
| this.title = title; | |
| } | |
| public byte[] getSomeBytes() { | |
| return someBytes; | |
| } | |
| public void setSomeBytes(byte[] someBytes) { | |
| this.someBytes = someBytes; | |
| } | |
| } | |
| static class B { | |
| private String title; | |
| private byte[] someBytes; | |
| public String getTitle() { | |
| return title; | |
| } | |
| public void setTitle(String title) { | |
| this.title = title; | |
| } | |
| public byte[] getSomeBytes() { | |
| return someBytes; | |
| } | |
| public void setSomeBytes(byte[] someBytes) { | |
| this.someBytes = someBytes; | |
| } | |
| } | |
| @Test | |
| public void testOk() { | |
| A input = new A(); | |
| input.title = "ABCDEF"; | |
| input.someBytes = input.title.getBytes(); | |
| B result = mapper.map(input, B.class); | |
| assertEquals(input.title, result.title); | |
| assertTrue(Arrays.equals(input.someBytes, result.someBytes)); | |
| } | |
| @Test | |
| public void testFailing() { | |
| // fails right here: | |
| mapper.addMappings(new PropertyMap<A, B>() { | |
| @Override | |
| protected void configure() { | |
| skip().setSomeBytes(null); | |
| } | |
| }); | |
| A input = new A(); | |
| input.title = "ABCDEF"; | |
| input.someBytes = input.title.getBytes(); | |
| B result = mapper.map(input, B.class); | |
| assertEquals(input.title, result.title); | |
| assertNull(result.someBytes); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment