@Test @SuppressWarnings({ "unchecked", "rawtypes" }) public void testOverridingDifferentClassDefinedForMapping() { BeanPropertyRowMapper mapper = new BeanPropertyRowMapper(Person.class); thrown.expect(InvalidDataAccessApiUsageException.class); mapper.setMappedClass(Long.class); }
@Test public void testStaticQueryWithRowMapper() throws Exception { Mock mock = new Mock(); List<Person> result = mock.getJdbcTemplate().query( "select name, age, birth_date, balance from people", new BeanPropertyRowMapper<Person>(Person.class)); assertEquals(1, result.size()); verifyPerson(result.get(0)); mock.verifyClosed(); }
@Test public void testMappingNullValue() throws Exception { BeanPropertyRowMapper<Person> mapper = new BeanPropertyRowMapper<Person>(Person.class); Mock mock = new Mock(MockType.TWO); thrown.expect(TypeMismatchException.class); mock.getJdbcTemplate().query( "select name, null as age, birth_date, balance from people", mapper); }
@Test @SuppressWarnings({ "unchecked", "rawtypes" }) public void testOverridingDifferentClassDefinedForMapping() { ParameterizedBeanPropertyRowMapper mapper = ParameterizedBeanPropertyRowMapper.newInstance(Person.class); thrown.expect(InvalidDataAccessApiUsageException.class); mapper.setMappedClass(Long.class); }
@Test public void testStaticQueryWithRowMapper() throws Exception { Mock mock = new Mock(); List<Person> result = mock.getJdbcTemplate().query( "select name, age, birth_date, balance from people", ParameterizedBeanPropertyRowMapper.newInstance(Person.class)); assertEquals(1, result.size()); verifyPerson(result.get(0)); mock.verifyClosed(); }
@Test public void testOverridingSameClassDefinedForMapping() { BeanPropertyRowMapper<Person> mapper = new BeanPropertyRowMapper<Person>(Person.class); mapper.setMappedClass(Person.class); }
protected void verifyPerson(Person bean) throws Exception { assertEquals("Bubba", bean.getName()); assertEquals(22L, bean.getAge()); assertEquals(new java.util.Date(1221222L), bean.getBirth_date()); assertEquals(new BigDecimal("1234.56"), bean.getBalance()); }
@Test public void testOverridingSameClassDefinedForMapping() { ParameterizedBeanPropertyRowMapper<Person> mapper = ParameterizedBeanPropertyRowMapper.newInstance(Person.class); mapper.setMappedClass(Person.class); }