diff --git a/README.md b/README.md index 88f2c22..d8a0efe 100644 --- a/README.md +++ b/README.md @@ -25,5 +25,13 @@ List users = repository.fetchAll(); User user = repository.findById(12); + List fullNames = repository.fullNames(); +``` + +Mapping + +```java + @ColumnProperty(name = "employee_id") + private int employeeID; ``` \ No newline at end of file diff --git a/src/test/java/com/ljunggren/storm/mapper/ArrayMapperTest.java b/src/test/java/com/ljunggren/storm/mapper/ArrayMapperTest.java index a2ec859..fed42b4 100644 --- a/src/test/java/com/ljunggren/storm/mapper/ArrayMapperTest.java +++ b/src/test/java/com/ljunggren/storm/mapper/ArrayMapperTest.java @@ -6,7 +6,6 @@ import java.lang.reflect.Type; import java.sql.SQLException; -import org.junit.Before; import org.junit.Test; import com.ljunggren.storm.TestUser; @@ -15,21 +14,19 @@ public class ArrayMapperTest { TestUser[] users; + String[] names; private MockResultSet resultSet; private MapperChain mapper = new ArrayMapper(); - @Before - public void setup() throws SQLException { + @Test + public void mapTest() throws NoSuchFieldException, SecurityException, SQLException { resultSet = new MockResultSet("mock"); resultSet.addColumn("ID", new Integer[] {1, 2}); resultSet.addColumn("FIRSTNAME", new String[] {"Alex", "Christie"}); resultSet.addColumn("LASTNAME", new String[] {"Ljunggren", "Ljunggren"}); resultSet.addColumn("EMPLOYEEID", new Integer[] {100, 101}); - } - - @Test - public void mapTest() throws NoSuchFieldException, SecurityException, SQLException { + Field field = this.getClass().getDeclaredField("users"); Type returnType = field.getGenericType(); TestUser[] users = (TestUser[]) mapper.map(resultSet, returnType); @@ -46,4 +43,17 @@ assertEquals(101, christie.getEmployeeID()); } + @Test + public void mapPrimitiveTest() throws NoSuchFieldException, SecurityException, SQLException { + resultSet = new MockResultSet("mock"); + resultSet.addColumn("FIRSTNAME", new String[] {"Alex", "Christie"}); + + Field field = this.getClass().getDeclaredField("names"); + Type returnType = field.getGenericType(); + String[] names = (String[]) mapper.map(resultSet, returnType); + + assertEquals("Alex", names[0]); + assertEquals("Christie", names[1]); + } + } diff --git a/src/test/java/com/ljunggren/storm/mapper/ListMapperTest.java b/src/test/java/com/ljunggren/storm/mapper/ListMapperTest.java index eee749c..d697f8c 100644 --- a/src/test/java/com/ljunggren/storm/mapper/ListMapperTest.java +++ b/src/test/java/com/ljunggren/storm/mapper/ListMapperTest.java @@ -7,7 +7,6 @@ import java.sql.SQLException; import java.util.List; -import org.junit.Before; import org.junit.Test; import com.ljunggren.storm.TestUser; @@ -16,22 +15,20 @@ public class ListMapperTest { List users; + List names; private MockResultSet resultSet; private MapperChain mapper = new ListMapper(); - @Before - public void setup() throws SQLException { + @Test + @SuppressWarnings("unchecked") + public void mapTest() throws NoSuchFieldException, SecurityException, SQLException { resultSet = new MockResultSet("mock"); resultSet.addColumn("ID", new Integer[] {1, 2}); resultSet.addColumn("FIRSTNAME", new String[] {"Alex", "Christie"}); resultSet.addColumn("LASTNAME", new String[] {"Ljunggren", "Ljunggren"}); resultSet.addColumn("EMPLOYEEID", new Integer[] {100, 101}); - } - - @Test - @SuppressWarnings("unchecked") - public void mapTest() throws NoSuchFieldException, SecurityException, SQLException { + Field field = this.getClass().getDeclaredField("users"); Type returnType = field.getGenericType(); List users = (List) mapper.map(resultSet, returnType); @@ -48,4 +45,18 @@ assertEquals(101, christie.getEmployeeID()); } + @Test + @SuppressWarnings("unchecked") + public void mapPrimitiveTest() throws NoSuchFieldException, SecurityException, SQLException { + resultSet = new MockResultSet("mock"); + resultSet.addColumn("FIRSTNAME", new String[] {"Alex", "Christie"}); + + Field field = this.getClass().getDeclaredField("names"); + Type returnType = field.getGenericType(); + List names = (List) mapper.map(resultSet, returnType); + + assertEquals("Alex", names.get(0)); + assertEquals("Christie", names.get(1)); + } + }