### Question:
ElasticsearchIndexManager extends Task { public void runIndexManagement() throws Exception { logger.info("Starting index management"); String serializedIndexMetadata = config.getIndexMetadata(); List<IndexMetadata> indexMetadataList; try { indexMetadataList = IndexUtils.parseIndexMetadata(serializedIndexMetadata); } catch (Exception e) { logger.error(String.format("Failed to build index metadata from %s", serializedIndexMetadata), e); return; } Client esTransportClient = getTransportClient(); DateTime dateTime = new DateTime(); runIndexManagement(esTransportClient, indexMetadataList, dateTime); } @Inject protected  ElasticsearchIndexManager(IConfiguration config, HttpModule httpModule); @Override void execute(); void runIndexManagement(); @Override String getName(); static TaskTimer getTimer(IConfiguration config); static String JOB_NAME; }### Answer:
@Test public void testRunIndexManagement() throws Exception { String serializedIndexMetadata = "[{\"retentionType\": \"yearly\", \"retentionPeriod\": 3, \"indexName\": \"nf_errors_log\"}]"; when(config.getIndexMetadata()).thenReturn(serializedIndexMetadata); Map<String, IndexStats> indexStats = new HashMap<>(); indexStats.put("nf_errors_log2018", new IndexStats("nf_errors_log2018", new ShardStats[]{})); indexStats.put("nf_errors_log2017", new IndexStats("nf_errors_log2017", new ShardStats[]{})); indexStats.put("nf_errors_log2016", new IndexStats("nf_errors_log2016", new ShardStats[]{})); indexStats.put("nf_errors_log2015", new IndexStats("nf_errors_log2015", new ShardStats[]{})); indexStats.put("nf_errors_log2014", new IndexStats("nf_errors_log2014", new ShardStats[]{})); indexStats.put("nf_errors_log2013", new IndexStats("nf_errors_log2013", new ShardStats[]{})); indexStats.put("nf_errors_log2012", new IndexStats("nf_errors_log2012", new ShardStats[]{})); IndicesStatsResponse indicesStatsResponse = mock(IndicesStatsResponse.class); when(indicesStatsResponse.getIndices()).thenReturn(indexStats); doReturn(indicesStatsResponse).when(elasticsearchIndexManager).getIndicesStatsResponse(elasticsearchClient); elasticsearchIndexManager.runIndexManagement(); verify(elasticsearchIndexManager, times(1)).checkIndexRetention(any(Client.class), anySet(), any(IndexMetadata.class), any(DateTime.class)); verify(elasticsearchIndexManager, times(1)).deleteIndices(any(Client.class), eq("nf_errors_log2012"), eq(AUTO_CREATE_INDEX_TIMEOUT)); verify(elasticsearchIndexManager, times(1)).deleteIndices(any(Client.class), eq("nf_errors_log2013"), eq(AUTO_CREATE_INDEX_TIMEOUT)); verify(elasticsearchIndexManager, times(0)).preCreateIndex(any(Client.class), any(IndexMetadata.class), any(DateTime.class)); }