TagHelper { public void executeFunctionForTagEntities(final String indexName, final List<TagEntity> tagEntities, final TriConsumer<String, String, String> function) { tagEntities.forEach(tagEntity -> { tagEntity.getChildrenTagEntities().size(); final String jsonString = safeObjectMapperWriteValueAsString(tagEntity); if (StringUtils.isNotEmpty(jsonString)) { try { function.accept(indexName, tagEntity.getId().toString(), jsonString); } catch (Exception ex) { LOGGER.warn("Index operation exception is logged {} for {}, {}, {}", ex, indexName, tagEntity.getId().toString(), jsonString); } } }); LOGGER.info("Finished processing {} tags with a search index function.", tagEntities.size()); }  void executeFunctionForTagEntities(final String indexName, final List<TagEntity> tagEntities,
        final TriConsumer<String, String, String> function); String safeObjectMapperWriteValueAsString(final TagEntity tagEntity); void validateTagKey(TagKey tagKey);  }
@Test public void testExecuteFunctionForTagEntities() { final List<TagEntity> tagEntities = Collections.unmodifiableList(Arrays .asList(tagDaoTestHelper.createTagEntity(TAG_TYPE, TAG_CODE, TAG_DISPLAY_NAME, TAG_DESCRIPTION), tagDaoTestHelper.createTagEntity(TAG_TYPE_2, TAG_CODE_2, TAG_DISPLAY_NAME_2, TAG_DESCRIPTION_2))); when(jsonHelper.objectToJson(any())).thenReturn(JSON_STRING); tagHelper.executeFunctionForTagEntities(SEARCH_INDEX_NAME, tagEntities, (indexName, id, json) -> { }); verify(jsonHelper, times(tagEntities.size())).objectToJson(any()); verifyNoMoreInteractions(alternateKeyHelper, jsonHelper); }