### Question:
DefaultPingSender implements PingSender { @Override public void sendPing() throws Exception { JestClient client = this.jestClientManager.getClient(); if (client != null) { client.execute(new CreateIndex.Builder(JestClientManager.INDEX).build()); PutMapping putMapping = new PutMapping.Builder(JestClientManager.INDEX, JestClientManager.TYPE, constructJSONMapping()).build(); client.execute(putMapping); Index index = new Index.Builder(constructIndexJSON()) .index(JestClientManager.INDEX) .type(JestClientManager.TYPE) .build(); JestResult result = client.execute(index); if (!result.isSucceeded()) { throw new Exception(result.getErrorMessage()); } } }  @Override void sendPing();  }### Answer:
@Test void sendPing() throws Exception { JestClient client = mock(JestClient.class); DocumentResult indexResult = new DocumentResult(new Gson()); indexResult.setSucceeded(true); when(client.execute(any(Index.class))).thenReturn(indexResult); when(this.jestManager.getClient()).thenReturn(client); PingDataProvider pingDataProvider = this.componentManager.registerMockComponent(PingDataProvider.class, "test"); this.pingSender.sendPing(); verify(pingDataProvider).provideMapping(); verify(pingDataProvider).provideData(); }
@Test void sendPingWhenClientNull() throws Exception { when(jestManager.getClient()).thenReturn(null); PingDataProvider pingDataProvider = this.componentManager.registerMockComponent(PingDataProvider.class, "test"); this.pingSender.sendPing(); verify(pingDataProvider, never()).provideMapping(); verify(pingDataProvider, never()).provideData(); }