@Test
public void testGetTagTagIndexSearchResponseDto()
{

    // Build the mocks need for the test.
    SearchResponse searchResponse = mock(SearchResponse.class);
    MockTerms terms = mock(MockTerms.class);
    Aggregations aggregations = mock(Aggregations.class);
    MockBucket tagTypeCodeEntry = mock(MockBucket.class);
    List<MockBucket> tagTypeCodeEntryList = Collections.singletonList(tagTypeCodeEntry);
    MockTerms tagTypeDisplayNameAggs = mock(MockTerms.class);
    MockBucket tagTypeDisplayNameEntry = mock(MockBucket.class);
    List<MockBucket> tagTypeDisplayNameEntryList = Collections.singletonList(tagTypeDisplayNameEntry);
    StringTerms tagCodeAggs = mock(StringTerms.class);
    StringTerms.Bucket tagCodeEntry = mock(StringTerms.Bucket.class);
    List<StringTerms.Bucket> tagCodeEntryList = Collections.singletonList(tagCodeEntry);
    MockTerms tagNameAggs = mock(MockTerms.class);
    MockBucket tagNameEntry = mock(MockBucket.class);
    List<MockBucket> tagNameEntryList = Collections.singletonList(tagNameEntry);
    // Mock the calls to external methods.
    when(searchResponse.getAggregations()).thenReturn(aggregations);
    when(aggregations.get(TAG_TYPE_FACET_AGGS)).thenReturn(terms);
    when(terms.getBuckets()).thenReturn(tagTypeCodeEntryList);
    when(tagTypeCodeEntry.getKeyAsString()).thenReturn(TAG_TYPE_CODE);
    when(tagTypeCodeEntry.getAggregations()).thenReturn(aggregations);
    when(aggregations.get(TAGTYPE_NAME_AGGREGATION)).thenReturn(tagTypeDisplayNameAggs);
    when(tagTypeDisplayNameAggs.getBuckets()).thenReturn(tagTypeDisplayNameEntryList);
    when(tagTypeDisplayNameEntry.getAggregations()).thenReturn(aggregations);
    when(tagTypeDisplayNameEntry.getKeyAsString()).thenReturn(TAG_TYPE_DISPLAY_NAME);
    when(aggregations.get(TAG_CODE_AGGREGATION)).thenReturn(tagCodeAggs);
    when(tagCodeAggs.getBuckets()).thenReturn(tagCodeEntryList);
    when(tagCodeEntry.getAggregations()).thenReturn(aggregations);
    when(tagCodeEntry.getKeyAsString()).thenReturn(TAG_CODE);
    when(tagCodeEntry.getDocCount()).thenReturn((long) TAG_CODE_COUNT);
    when(aggregations.get(TAG_NAME_AGGREGATION)).thenReturn(tagNameAggs);
    when(tagNameAggs.getBuckets()).thenReturn(tagNameEntryList);
    when(tagNameEntry.getKeyAsString()).thenReturn(TAG_DISPLAY_NAME);
    // Call the method under test.
    List<TagTypeIndexSearchResponseDto> resultList = elasticsearchHelper.getTagTagIndexSearchResponseDto(searchResponse);
    // Validate the results.
    List<TagTypeIndexSearchResponseDto> expectedList = new ArrayList<>();
    List<TagIndexSearchResponseDto> expectedTagList = new ArrayList<>();
    expectedTagList.add(new TagIndexSearchResponseDto(TAG_CODE, TAG_CODE_COUNT, TAG_DISPLAY_NAME));
    expectedList.add(new TagTypeIndexSearchResponseDto(TAG_TYPE_CODE, expectedTagList, TAG_TYPE_DISPLAY_NAME));
    assertEquals(expectedList, resultList);
    // Verify the calls to external methods.
    verify(searchResponse).getAggregations();
    verify(aggregations).get(TAG_TYPE_FACET_AGGS);
    verify(terms).getBuckets();
    verify(tagTypeCodeEntry).getKeyAsString();
    verify(tagTypeCodeEntry).getAggregations();
    verify(aggregations).get(TAGTYPE_NAME_AGGREGATION);
    verify(tagTypeDisplayNameAggs).getBuckets();
    verify(tagTypeDisplayNameEntry).getAggregations();
    verify(tagTypeDisplayNameEntry).getKeyAsString();
    verify(aggregations).get(TAG_CODE_AGGREGATION);
    verify(tagCodeAggs).getBuckets();
    verify(tagCodeEntry).getAggregations();
    verify(tagCodeEntry).getKeyAsString();
    verify(tagCodeEntry).getDocCount();
    verify(aggregations).get(TAG_NAME_AGGREGATION);
    verify(tagNameAggs).getBuckets();
    verify(tagNameEntry).getKeyAsString();
    verifyNoMoreInteractions(aggregations, searchResponse, tagCodeAggs, tagCodeEntry, tagNameAggs, tagNameEntry, tagTypeDisplayNameAggs,
        tagTypeDisplayNameEntry, tagTypeCodeEntry, terms);
}