### Question:
MonitoringESDao { public void deleteIndices(final int retentionPeriodDays) { try { final Response response = requestIndices(); try (BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()))) { final String indicesToDelete = indices(reader) .map(this::withParsedDate) .filter(pair -> pair.right != null && olderThanRetentionPeriod(retentionPeriodDays, pair.right)) .map(pair -> pair.left) .collect(Collectors.joining(",")); lowLevelClient.performRequest(HttpMethod.DELETE.name(), "/" + indicesToDelete); } } catch (IOException e) { throw new PipelineException(e); } } @Autowired  MonitoringESDao(RestHighLevelClient client, RestClient lowLevelClient); Map<String, Double> loadMetrics(final ELKUsageMetric metric, final Collection<String> resourceIds,
                                           final LocalDateTime from, final LocalDateTime to); void deleteIndices(final int retentionPeriodDays); Optional<LocalDateTime> oldestIndexDate();  }### Answer:
@Test public void testDeleteIndices() { IntStream.range(1, 6) .mapToObj(NOW::minusDays) .map(date -> HEAPSTER_TOKEN + MonitoringESDao.DATE_FORMATTER.format(date)) .forEach(indexName -> { tryDelete(indexName, client); client.admin().indices().prepareCreate(indexName).get(); }); monitoringESDao.deleteIndices(3); String[] indices = client.admin().cluster() .prepareState().get() .getState().metaData().getConcreteAllIndices(); Assert.assertEquals(4, Arrays.stream(indices).filter(i -> i.startsWith(HEAPSTER_TOKEN)).count()); }