### Question:
RatingService { public void handleContentRatingFields(@Observes ContentBeforeIndexedEvent event) { log.log(Level.FINE, "handleContentRatingFields called for event {0}", event); if (event == null || event.getContentId() == null || event.getContentData() == null) { log.warning("Invalid event " + event); return; } RatingStats rs = ratingPersistenceService.countRatingStats(event.getContentId()); Map<String, Object> content = event.getContentData(); if (rs != null) { content.put(ContentObjectFields.SYS_RATING_AVG, rs.getAverage()); content.put(ContentObjectFields.SYS_RATING_NUM, rs.getNumber()); } else { content.remove(ContentObjectFields.SYS_RATING_AVG); content.remove(ContentObjectFields.SYS_RATING_NUM); } }  void contributorDeletedEventHandler(@Observes ContributorDeletedEvent event); void contentDeletedEventHandler(@Observes ContentDeletedEvent event); void handleContentRatingFields(@Observes ContentBeforeIndexedEvent event); void contributorMergedEventHandler(@Observes ContributorMergedEvent event); void contributorCodeChangedEventHandler(@Observes ContributorCodeChangedEvent event);  }### Answer:
@Test public void handleContentRatingFields() { RatingService tested = getTested(); tested.handleContentRatingFields(null); verifyZeroInteractions(tested.ratingPersistenceService); reset(tested.ratingPersistenceService); tested.handleContentRatingFields(new ContentBeforeIndexedEvent(null, null)); verifyZeroInteractions(tested.ratingPersistenceService); reset(tested.ratingPersistenceService); tested.handleContentRatingFields(new ContentBeforeIndexedEvent("id", null)); verifyZeroInteractions(tested.ratingPersistenceService); reset(tested.ratingPersistenceService); tested.handleContentRatingFields(new ContentBeforeIndexedEvent(null, new HashMap<String, Object>())); verifyZeroInteractions(tested.ratingPersistenceService); { reset(tested.ratingPersistenceService); Map<String, Object> content = new HashMap<String, Object>(); content.put(ContentObjectFields.SYS_RATING_NUM, "10"); Mockito.when(tested.ratingPersistenceService.countRatingStats("id")).thenReturn(new RatingStats("id", 3, 5)); tested.handleContentRatingFields(new ContentBeforeIndexedEvent("id", content)); Assert.assertEquals(new Double(3), content.get(ContentObjectFields.SYS_RATING_AVG)); Assert.assertEquals(new Long(5), content.get(ContentObjectFields.SYS_RATING_NUM)); } { reset(tested.ratingPersistenceService); Map<String, Object> content = new HashMap<String, Object>(); content.put(ContentObjectFields.SYS_RATING_NUM, "10"); Mockito.when(tested.ratingPersistenceService.countRatingStats("id")).thenReturn(null); tested.handleContentRatingFields(new ContentBeforeIndexedEvent("id", content)); Assert.assertNull(content.get(ContentObjectFields.SYS_RATING_AVG)); Assert.assertNull(content.get(ContentObjectFields.SYS_RATING_NUM)); } }