From c151f3ba0e49b6cd50f66e262dd64fe7dd07d701 Mon Sep 17 00:00:00 2001 From: moparisthebest Date: Wed, 9 May 2018 23:20:40 -0400 Subject: [PATCH] Finish porting tests --- .../com/moparisthebest/jdbc/codegen/QmDao.java | 5 +++-- .../jdbc/codegen/QueryMapperQmDao.java | 7 ++++--- .../moparisthebest/jdbc/QueryMapperTest.java | 18 ++++++++---------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/test/src/main/java/com/moparisthebest/jdbc/codegen/QmDao.java b/test/src/main/java/com/moparisthebest/jdbc/codegen/QmDao.java index b445f45..5d8fc8b 100644 --- a/test/src/main/java/com/moparisthebest/jdbc/codegen/QmDao.java +++ b/test/src/main/java/com/moparisthebest/jdbc/codegen/QmDao.java @@ -141,13 +141,14 @@ public interface QmDao extends JdbcMapper { @SQL(selectLongLong) Map getMapLongLong() throws SQLException; - /* + @SQL(selectLongArray) + @SingleRow Long[] getLongObjectArray() throws SQLException; @SQL(selectLongArray) + @SingleRow long[] getLongPrimitiveArray() throws SQLException; - */ @SQL(bobTomMap) List> getBobTomMap() throws SQLException; diff --git a/test/src/main/java/com/moparisthebest/jdbc/codegen/QueryMapperQmDao.java b/test/src/main/java/com/moparisthebest/jdbc/codegen/QueryMapperQmDao.java index 4f614b1..b92d8ea 100644 --- a/test/src/main/java/com/moparisthebest/jdbc/codegen/QueryMapperQmDao.java +++ b/test/src/main/java/com/moparisthebest/jdbc/codegen/QueryMapperQmDao.java @@ -215,7 +215,6 @@ public class QueryMapperQmDao implements QmDao { return qm.toMap(selectLongLong, Long.class, Long.class); } - /* @Override public Long[] getLongObjectArray() throws SQLException { return qm.toObject(selectLongArray, Long[].class); @@ -225,7 +224,6 @@ public class QueryMapperQmDao implements QmDao { public long[] getLongPrimitiveArray() throws SQLException { return qm.toObject(selectLongArray, long[].class); } - */ @Override public List> getBobTomMap() throws SQLException { @@ -233,8 +231,11 @@ public class QueryMapperQmDao implements QmDao { } @Override + @SuppressWarnings("unchecked") public List> getBobTomMapCaseInsensitive() throws SQLException { - return qm.toType(bobTomMap, new TypeReference>>() {}); + // todo: ParameterizedTypeImpl cannot be cast to java.lang.Class + // return qm.toType(bobTomMap, new TypeReference>>() {}); + return (List>)(Object)qm.toListMap(bobTomMap, CaseInsensitiveHashMap.class, String.class); } @Override diff --git a/test/src/test/java/com/moparisthebest/jdbc/QueryMapperTest.java b/test/src/test/java/com/moparisthebest/jdbc/QueryMapperTest.java index 803c323..8cfca6d 100644 --- a/test/src/test/java/com/moparisthebest/jdbc/QueryMapperTest.java +++ b/test/src/test/java/com/moparisthebest/jdbc/QueryMapperTest.java @@ -342,8 +342,7 @@ public class QueryMapperTest { final Long[] expected = {fieldPerson1.getPersonNo()}; assertArrayEquals(expected, qm.getPersonNoObjectArray(expected[0])); } -/* - // todo: fix these + @Test public void testSelectObjectArray() throws Throwable { final Long[] arr = {1L, 2L, 3L}; @@ -353,9 +352,9 @@ public class QueryMapperTest { @Test public void testSelectPrimitiveArray() throws Throwable { final long[] arr = {1L, 2L, 3L}; - assertArrayEquals(arr, qm.toObject("SELECT 1, 2, 3 FROM person WHERE person_no = ?", long[].class, fieldPerson1.getPersonNo())); + assertArrayEquals(arr, qm.getLongPrimitiveArray()); } -*/ + @Test(expected = com.moparisthebest.jdbc.MapperException.class) public void testNoDefaultConstructorFails() throws Throwable { if(qm instanceof QueryMapperQmDao) @@ -405,8 +404,6 @@ public class QueryMapperTest { @Test public void testCaseInsensitiveMapJdbcMapper() throws Throwable { - if(qm instanceof QueryMapperQmDao) - return; // skip todo: java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to java.lang.Class final Map map = qm.getBobTomMapCaseInsensitive().get(0); assertEquals("bob", map.get("bob")); assertEquals("bob", map.get("Bob")); @@ -431,17 +428,18 @@ public class QueryMapperTest { final List fromDb = qm.getThreePeopleType(people[0].getPersonNo(), people[1].getPersonNo(), people[2].getPersonNo()); assertArrayEquals(people, fromDb.toArray()); } -/* - // todo: port this one + @Test public void testListQueryMapperList() throws SQLException { - final ListQueryMapper lqm = new ListQueryMapper(qm); + if(!(qm instanceof QueryMapperQmDao)) + return; // todo: port this when JdbcMapper supports in-lists on generic SQL backends + final ListQueryMapper lqm = new ListQueryMapper(((QueryMapperQmDao)qm).getQm()); final List fromDb = lqm.toList("SELECT * from person WHERE " + ListQueryMapper.inListReplace + " ORDER BY person_no", FieldPerson.class, lqm.inList("person_no", Arrays.asList(people[0].getPersonNo(), people[1].getPersonNo(), people[2].getPersonNo()))); assertArrayEquals(people, fromDb.toArray()); lqm.close(); } -*/ + @Test public void testResultSetIterable() throws SQLException { final ResultSetIterable rsi = qm.getThreePeopleResultSetIterable(people[0].getPersonNo(), people[1].getPersonNo(), people[2].getPersonNo());