feat: Add mapper for objects with same fields

This commit is contained in:
Krrish Ghimire
2019-12-03 22:49:20 +05:45
commit 2f1475b4cd
11 changed files with 365 additions and 0 deletions

12
test/Destination.java Normal file
View File

@@ -0,0 +1,12 @@
public class Destination {
private String first;
private String second;
public String getFirst() {
return first;
}
public String getSecond() {
return second;
}
}

29
test/MapperTest.java Normal file
View File

@@ -0,0 +1,29 @@
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, "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, "Destination");
assertEquals("first", destination.getFirst());
}
}

12
test/Source.java Normal file
View File

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