### Question:
JpaRatingPersistenceService implements RatingPersistenceService { @Override public RatingStats countRatingStats(String contentId) { Object[] ret = (Object[]) em.createQuery(STAT_QUERY).setParameter(1, contentId).getSingleResult(); if (ret != null && ret.length > 0 && ret[0] != null) { return new RatingStats(contentId, (Double) ret[0], (Long) ret[1]); } return null; }  @Override List<Rating> getRatings(String contributorId, String... contentId); @Override void rate(String contributorId, String contentId, int rating); @Override RatingStats countRatingStats(String contentId); @Override void mergeRatingsForContributors(String contributorIdFrom, String contributorIdTo); @Override void deleteRatingsForContributor(String contributorId); @Override void deleteRatingsForContent(String... contentId);  }### Answer:
@Test public void countRatingStats() { JpaRatingPersistenceService tested = getTested(); em.getTransaction().begin(); tested.rate(CONTRIB_ID_1, CONTENT_ID_1, 1); tested.rate(CONTRIB_ID_2, CONTENT_ID_1, 5); tested.rate(CONTRIB_ID_1, CONTENT_ID_3, 4); em.getTransaction().commit(); em.getTransaction().begin(); RatingStats rs = tested.countRatingStats(CONTENT_ID_1); Assert.assertEquals(CONTENT_ID_1, rs.getContentId()); Assert.assertEquals(3, rs.getAverage(), 0.01); Assert.assertEquals(2, rs.getNumber()); Assert.assertNull(tested.countRatingStats(CONTENT_ID_2)); rs = tested.countRatingStats(CONTENT_ID_3); Assert.assertEquals(CONTENT_ID_3, rs.getContentId()); Assert.assertEquals(4, rs.getAverage(), 0.01); Assert.assertEquals(1, rs.getNumber()); em.getTransaction().commit(); }