SolrUpdateDao implements UpdateDao { public void convertCommentsToRaw(Map<String,Object> source) { @SuppressWarnings("unchecked") List<Map<String, Object>> comments = (List<Map<String, Object>>) source.get(COMMENTS_FIELD); if (comments == null || comments.isEmpty()) { return; } List<String> asJson = new ArrayList<>(); for (Map<String, Object> comment : comments) { asJson.add((new AlertComment(comment)).asJson()); } source.put(COMMENTS_FIELD, asJson); } SolrUpdateDao(SolrClient client, SolrRetrieveLatestDao retrieveLatestDao, AccessConfig config); @Override Document update(Document update, Optional<String> rawIndex); @Override Map<Document, Optional<String>> batchUpdate(Map<Document, Optional<String>> updates); @Override Document addCommentToAlert(CommentAddRemoveRequest request); @Override Document addCommentToAlert(CommentAddRemoveRequest request, Document latest); @Override Document removeCommentFromAlert(CommentAddRemoveRequest request); @Override Document removeCommentFromAlert(CommentAddRemoveRequest request, Document latest); void convertCommentsToRaw(Map<String,Object> source);  }
@Test public void testConvertCommentsToRaw() { List<Map<String, Object>> commentList = new ArrayList<>(); Map<String, Object> comments = new HashMap<>(); comments.put("comment", "test comment"); comments.put("username", "test username"); comments.put("timestamp", 1526424323279L); commentList.add(comments); Map<String, Object> document = new HashMap<>(); document.put("testField", "testValue"); document.put(COMMENTS_FIELD, commentList); solrUpdateDao.convertCommentsToRaw(document); @SuppressWarnings("unchecked") List<String> actualComments = (List<String>) document.get(COMMENTS_FIELD); String expectedComment = "{\"comment\":\"test comment\",\"username\":\"test username\",\"timestamp\":1526424323279}"; assertEquals(expectedComment, actualComments.get(0)); assertEquals(1, actualComments.size()); assertEquals("testValue", document.get("testField")); }