@Test public void test_should_map_result_set_to_entity() throws Exception { Mockito.when(rs.next()).thenReturn(true).thenReturn(false); when((Long) rs.getObject("id")).thenReturn(1L); when(rs.getString("code")).thenReturn("SUBMITTED"); when(rs.getString("objecttype")).thenReturn("Receipt Header"); when(rs.getString("description")).thenReturn("Submitted"); when(rs.getString("tenantId")).thenReturn("default"); when((Long) rs.getObject("createdBy")).thenReturn(1L); when((Long) rs.getObject("lastModifiedBy")).thenReturn(1L); try{ when(rs.getTimestamp("createdDate")).thenReturn(null); when(rs.getTimestamp("lastModifiedDate")).thenReturn(null); } catch(Exception e) { Assert.fail("Exception " + e); } Status actualStatus = statusRowMapper.mapRow(rs, 1); Status expectedStatus = getModelStatus(); assertThat(expectedStatus.equals(actualStatus)); }
@Override public Status mapRow(ResultSet rs, int rowNum) throws SQLException { Status status = new Status(); status.setId((Long) rs.getObject("id")); status.setCode(rs.getString("code")); status.setObjectType(rs.getString("objecttype")); status.setDescription(rs.getString("description")); status.setTenantId(rs.getString("tenantId")); status.setCreatedBy((Long) rs.getObject("createdBy")); status.setLastModifiedBy((Long) rs.getObject("lastModifiedBy")); try { Date date = isEmpty(rs.getDate("createdDate")) ? null : sdf.parse(sdf.format(rs.getDate("createdDate"))); status.setCreatedDate(date); date = isEmpty(rs.getDate("lastModifiedDate")) ? null : sdf.parse(sdf.format(rs.getDate("lastModifiedDate"))); status.setLastModifiedDate(date); } catch (ParseException e) { e.printStackTrace(); throw new SQLException("Parse exception while parsing date"); } return status; }
StatusRowMapper implements RowMapper<Status> { @Override public Status mapRow(ResultSet rs, int rowNum) throws SQLException { Status status = new Status(); status.setId((Long) rs.getObject("id")); status.setCode(rs.getString("code")); status.setObjectType(rs.getString("objecttype")); status.setDescription(rs.getString("description")); status.setTenantId(rs.getString("tenantId")); status.setCreatedBy((Long) rs.getObject("createdBy")); status.setLastModifiedBy((Long) rs.getObject("lastModifiedBy")); try { Date date = isEmpty(rs.getDate("createdDate")) ? null : sdf.parse(sdf.format(rs.getDate("createdDate"))); status.setCreatedDate(date); date = isEmpty(rs.getDate("lastModifiedDate")) ? null : sdf.parse(sdf.format(rs.getDate("lastModifiedDate"))); status.setLastModifiedDate(date); } catch (ParseException e) { e.printStackTrace(); throw new SQLException("Parse exception while parsing date"); } return status; } }
StatusRowMapper implements RowMapper<Status> { @Override public Status mapRow(ResultSet rs, int rowNum) throws SQLException { Status status = new Status(); status.setId((Long) rs.getObject("id")); status.setCode(rs.getString("code")); status.setObjectType(rs.getString("objecttype")); status.setDescription(rs.getString("description")); status.setTenantId(rs.getString("tenantId")); status.setCreatedBy((Long) rs.getObject("createdBy")); status.setLastModifiedBy((Long) rs.getObject("lastModifiedBy")); try { Date date = isEmpty(rs.getDate("createdDate")) ? null : sdf.parse(sdf.format(rs.getDate("createdDate"))); status.setCreatedDate(date); date = isEmpty(rs.getDate("lastModifiedDate")) ? null : sdf.parse(sdf.format(rs.getDate("lastModifiedDate"))); status.setLastModifiedDate(date); } catch (ParseException e) { e.printStackTrace(); throw new SQLException("Parse exception while parsing date"); } return status; }  }
StatusRowMapper implements RowMapper<Status> { @Override public Status mapRow(ResultSet rs, int rowNum) throws SQLException { Status status = new Status(); status.setId((Long) rs.getObject("id")); status.setCode(rs.getString("code")); status.setObjectType(rs.getString("objecttype")); status.setDescription(rs.getString("description")); status.setTenantId(rs.getString("tenantId")); status.setCreatedBy((Long) rs.getObject("createdBy")); status.setLastModifiedBy((Long) rs.getObject("lastModifiedBy")); try { Date date = isEmpty(rs.getDate("createdDate")) ? null : sdf.parse(sdf.format(rs.getDate("createdDate"))); status.setCreatedDate(date); date = isEmpty(rs.getDate("lastModifiedDate")) ? null : sdf.parse(sdf.format(rs.getDate("lastModifiedDate"))); status.setLastModifiedDate(date); } catch (ParseException e) { e.printStackTrace(); throw new SQLException("Parse exception while parsing date"); } return status; }  @Override Status mapRow(ResultSet rs, int rowNum); }
StatusRowMapper implements RowMapper<Status> { @Override public Status mapRow(ResultSet rs, int rowNum) throws SQLException { Status status = new Status(); status.setId((Long) rs.getObject("id")); status.setCode(rs.getString("code")); status.setObjectType(rs.getString("objecttype")); status.setDescription(rs.getString("description")); status.setTenantId(rs.getString("tenantId")); status.setCreatedBy((Long) rs.getObject("createdBy")); status.setLastModifiedBy((Long) rs.getObject("lastModifiedBy")); try { Date date = isEmpty(rs.getDate("createdDate")) ? null : sdf.parse(sdf.format(rs.getDate("createdDate"))); status.setCreatedDate(date); date = isEmpty(rs.getDate("lastModifiedDate")) ? null : sdf.parse(sdf.format(rs.getDate("lastModifiedDate"))); status.setLastModifiedDate(date); } catch (ParseException e) { e.printStackTrace(); throw new SQLException("Parse exception while parsing date"); } return status; }  @Override Status mapRow(ResultSet rs, int rowNum);  }