diff --git a/.gitignore b/.gitignore index 8b96bc8..01bb14d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ .gradle/** .idea/** -build/** +build/classes/** +build/generated/** +build/reports/** +build/test-results/** +build/tmp/** diff --git a/src/np/com/krrish/Mapper.java b/src/np/com/krrish/Mapper.java index 0712a4a..a9dd576 100644 --- a/src/np/com/krrish/Mapper.java +++ b/src/np/com/krrish/Mapper.java @@ -3,10 +3,10 @@ package np.com.krrish; import java.lang.reflect.*; public class Mapper { - public static Object map(Object source, String destination) { + public static Object map(Object source, Class destination) { Object object = new Object(); try { - Class aClass = Class.forName(destination); + Class aClass = Class.forName(destination.getName()); object = aClass.getConstructor().newInstance(); Field[] sourceFields = source.getClass().getDeclaredFields(); for (Field sourceField : sourceFields) { diff --git a/test/np/com/krrish/MapperTest.java b/test/np/com/krrish/MapperTest.java index 0c48311..1b9b859 100644 --- a/test/np/com/krrish/MapperTest.java +++ b/test/np/com/krrish/MapperTest.java @@ -9,7 +9,7 @@ class MapperTest { @Test void testEmptyFieldsMap() { Source source = new Source(); - Object destination = Mapper.map(source, "np.com.krrish.Destination"); + Object destination = Mapper.map(source, Destination.class); assertEquals(Destination.class, destination.getClass()); } @@ -19,7 +19,7 @@ class MapperTest { source.setFirst("first"); source.setSecond("second"); - Destination destination = (Destination) Mapper.map(source, "np.com.krrish.Destination"); + Destination destination = (Destination) Mapper.map(source, Destination.class); assertEquals("first", destination.getFirst()); } }