SolrUtilities { public static Document toDocument(SolrDocument solrDocument) { Map<String, Object> document = new HashMap<>(); solrDocument.getFieldNames().stream() .filter(name -> !name.equals(SolrDao.VERSION_FIELD)) .forEach(name -> document.put(name, solrDocument.getFieldValue(name))); reformatComments(solrDocument, document); insertChildAlerts(solrDocument, document); return new Document(document, (String) solrDocument.getFieldValue(Constants.GUID), (String) solrDocument.getFieldValue(Constants.SENSOR_TYPE), (Long) solrDocument.getFieldValue(Constants.Fields.TIMESTAMP.getName())); }  static SearchResult getSearchResult(SolrDocument solrDocument, List<String> fields, Function<String, String> indexSupplier); static Document toDocument(SolrDocument solrDocument); static SolrInputDocument toSolrInputDocument(Document document); static Optional<String> getIndex(Function<String, String> indexSupplier, String sensorName,
      Optional<String> index);  }
@Test public void toDocumentShouldProperlyReturnDocument() throws Exception { long expectedTimestamp = System.currentTimeMillis(); SolrDocument solrDocument = new SolrDocument(); solrDocument.addField(SolrDao.VERSION_FIELD, 1.0); solrDocument.addField(Constants.GUID, "guid"); solrDocument.addField(Constants.SENSOR_TYPE, "bro"); solrDocument.addField(Constants.Fields.TIMESTAMP.getName(), expectedTimestamp); solrDocument.addField("field", "value"); Document expectedDocument = new Document(new HashMap<String, Object>() {{ put("field", "value"); put(Constants.GUID, "guid"); put(Constants.SENSOR_TYPE, "bro"); put(Constants.Fields.TIMESTAMP.getName(), expectedTimestamp); }}, "guid", "bro", expectedTimestamp); Document actualDocument = SolrUtilities.toDocument(solrDocument); assertEquals(expectedDocument, actualDocument); }