### Question:
HibernateRatingDAO extends HibernatePersistentObjectDAO<Rating> implements RatingDAO { @Override public Rating findVotesByDocId(long docId) { List<Rating> coll = new ArrayList<Rating>(); try { String query = "select count(*), SUM(ld_vote) from ld_rating where ld_deleted=0 and ld_docid = " + docId; @SuppressWarnings("rawtypes") RowMapper ratingMapper = new BeanPropertyRowMapper() { public Object mapRow(ResultSet rs, int rowNum) throws SQLException { Rating rating = new Rating(); rating.setCount(rs.getInt(1)); if (rs.getInt(1) > 0) { float div = (float) rs.getInt(2) / (float) rs.getInt(1); double avg = Math.round(div * 100.0) / 100.0; rating.setAverage(Double.valueOf(avg).floatValue()); } else rating.setAverage(0F); return rating; } }; coll = (List<Rating>) query(query, new Object[] {}, ratingMapper, null); if (!coll.isEmpty() && coll.get(0).getCount() != 0) return coll.get(0); } catch (Throwable e) { if (log.isErrorEnabled()) log.error(e.getMessage(), e); } return null; } HibernateRatingDAO(); @Override boolean store(Rating rating, DocumentHistory transaction); @Override Rating findVotesByDocId(long docId); @Override Rating findByDocIdAndUserId(long docId, long userId); @Override List<Rating> findByDocId(long docId); @Override boolean delete(long id, int code);  }### Answer:
@Test public void testFindVotesByDocId() { Rating rat1 = dao.findVotesByDocId(1); Assert.assertNotNull(rat1); Assert.assertEquals(2, rat1.getCount().intValue()); Assert.assertEquals(new Float(2.5), rat1.getAverage().floatValue()); rat1 = dao.findVotesByDocId(2); Assert.assertNotNull(rat1); Assert.assertEquals(1, rat1.getCount().intValue()); Assert.assertEquals(new Float(3.0), rat1.getAverage().floatValue()); rat1 = dao.findVotesByDocId(99); Assert.assertNull(rat1); }