@Test public void testConstructorNoAsmAndNoAsmLinb() throws Exception { JdbcMapperBuilder<DbConstructorObject> builder = JdbcMapperFactoryHelper.disableAsm().newBuilder(DbConstructorObject.class); try { builder.addMapping("prop1"); builder.addMapping("prop2"); fail("Expect exception"); } catch (Exception e) { // expected } }
@Test public void testChooseSmallestMatchingConstructor() throws Exception { JdbcMapperBuilder<DbConstructorObject> builder = JdbcMapperFactoryHelper.asm().newBuilder(DbConstructorObject.class); builder.addMapping("prop1"); JdbcMapper<DbConstructorObject> mapper = builder.mapper(); ResultSet rs = mock(ResultSet.class); when(rs.getString(1)).thenReturn("propValue"); DbConstructorObject o = mapper.map(rs); assertEquals("propValue", o.getProp1()); assertNull(o.getProp2()); assertNull(o.getProp3()); assertEquals(0, o.getC()); }
@Test public void testConstructorProp3() throws Exception { JdbcMapperBuilder<DbConstructorObject> builder = JdbcMapperFactoryHelper.asm().newBuilder(DbConstructorObject.class); builder.addMapping("prop3"); JdbcMapper<DbConstructorObject> mapper = builder.mapper(); Timestamp ts = new Timestamp(System.currentTimeMillis()); ResultSet rs = mock(ResultSet.class); when(rs.getTimestamp(1)).thenReturn(ts); when(rs.getObject(1)).thenReturn(ts); DbConstructorObject o = mapper.map(rs); assertNull(o.getProp1()); assertNull(o.getProp2()); assertEquals(ts, o.getProp3()); assertEquals(2, o.getC()); }