fix: Ignore if field does not exist

This commit is contained in:
Krrish Ghimire
2019-12-03 23:25:18 +05:45
parent 8f4f154879
commit 8fc1410cd0
5 changed files with 43 additions and 34 deletions

View File

@@ -0,0 +1,14 @@
package np.com.krrish;
public class Destination {
private String first;
private String second;
String getFirst() {
return first;
}
public String getSecond() {
return second;
}
}

View File

@@ -0,0 +1,31 @@
package np.com.krrish;
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;
class MapperTest {
private Mapper mapper;
@BeforeEach
void setUp() {
mapper = new Mapper();
}
@Test
void testEmptyFieldsMap() {
Source source = new Source();
Object destination = mapper.map(source, "np.com.krrish.Destination");
assertEquals(Destination.class, destination.getClass());
}
@Test
void testMapWithSameFields() {
Source source = new Source();
source.setFirst("first");
source.setSecond("second");
Destination destination = (Destination) mapper.map(source, "np.com.krrish.Destination");
assertEquals("first", destination.getFirst());
}
}

View File

@@ -0,0 +1,14 @@
package np.com.krrish;
public class Source {
private String first;
private String second;
void setFirst(String first) {
this.first = first;
}
void setSecond(String second) {
this.second = second;
}
}