ElasticSearchBulkService implements Runnable { public void run(){ execute(); } ElasticSearchBulkService(List<AnomalyModel> anomalyModels); void run(); @VisibleForTesting void setElasticSearchClient(ElasticSearchClient elasticSearchClient); ElasticSearchClient getElasticSearchClient();  }
@Test public void testRun() throws IOException { AnomalyModel anomalyModel = AnomalyModel.newBuilder() .key("key") .value(100) .level("NORMAL") .uuid("test") .timestamp("date") .anomalyThresholds(null) .tags(null) .build(); anomalyModel = AnomalyModel.newBuilder(anomalyModel).build(); List<AnomalyModel> anomalyModels = new ArrayList<>(); anomalyModels.add(anomalyModel); BulkResponse bulkResponse = buildBulkResponseHappy(); when(client.bulk(any(BulkRequest.class), any(RequestOptions.class))).thenReturn(bulkResponse); when(client.close()).thenReturn(true); ElasticSearchBulkService elasticSearchBulkService = new ElasticSearchBulkService(anomalyModels); elasticSearchBulkService.setElasticSearchClient(client); elasticSearchBulkService.run(); verify(elasticSearchBulkService.getElasticSearchClient(), times(1)) .bulk(any(BulkRequest.class), any(RequestOptions.class)); }