Set<String> fields = new HashSet<>(Arrays.asList("field1", "field2", "field3"));
CustomFieldsVisitor fieldsVisitor = new CustomFieldsVisitor(fields, false);
searcher.doc(0, fieldsVisitor);
fieldsVisitor.postProcess(mapper);
assertThat(fieldsVisitor.fields().size(), equalTo(3));
assertThat(fieldsVisitor.fields().get("field1").size(), equalTo(1));
assertThat((Integer) fieldsVisitor.fields().get("field1").get(0), equalTo(1));
assertThat(fieldsVisitor.fields().get("field2").size(), equalTo(1));
assertThat((Float) fieldsVisitor.fields().get("field2").get(0), equalTo(1.1f));
assertThat(fieldsVisitor.fields().get("field3").size(), equalTo(3));
assertThat((Long) fieldsVisitor.fields().get("field3").get(0), equalTo(1l));