@Test
public void testGetNestedAggregation()
{

    // Create a mock sub-aggregation.
    Terms subAggregation = mock(Terms.class);
    // Create mock nested aggregations.
    Aggregations nestedAggregations = mock(Aggregations.class);
    when(nestedAggregations.get(SUB_AGGREGATION_NAME)).thenReturn(subAggregation);
    // Create a mock nested aggregation.
    Nested nestedAggregation = mock(Nested.class);
    when(nestedAggregation.getAggregations()).thenReturn(nestedAggregations);
    // Create mock search response aggregations.
    Aggregations searchResponseAggregations = mock(Aggregations.class);
    when(searchResponseAggregations.get(NESTED_AGGREGATION_NAME)).thenReturn(nestedAggregation);
    // Create a mock search response.
    SearchResponse searchResponse = mock(SearchResponse.class);
    when(searchResponse.getAggregations()).thenReturn(searchResponseAggregations);
    // Call the method under test.
    Terms result = elasticsearchHelper.getNestedAggregation(searchResponse, NESTED_AGGREGATION_NAME, SUB_AGGREGATION_NAME);
    // Verify the external calls.
    verifyNoMoreInteractionsHelper();
    // Validate the result.
    assertEquals(subAggregation, result);
}