### Question:
ElasticsearchClientService { @PreDestroy public void destroy() { try { if (client != null) { client.close(); client = null; log.info("Elasticsearch Search Client is closed"); } } finally { if (node != null) { node.close(); node = null; log.info("Elasticsearch Search Node is closed"); } } }  Node createEmbeddedNode(String name, Properties settings); Client getClient(); @PreDestroy void destroy(); void checkHealthOfCluster(Client client);  }### Answer:
@Test public void destroy() { ElasticsearchClientService tested = getTested(); Client clientMock = Mockito.mock(Client.class); Node nodeMock = Mockito.mock(Node.class); tested.destroy(); tested.client = clientMock; tested.node = null; tested.destroy(); Mockito.verify(clientMock).close(); Mockito.reset(nodeMock, clientMock); tested.client = null; tested.node = nodeMock; tested.destroy(); Mockito.verify(nodeMock).close(); Mockito.reset(nodeMock, clientMock); tested.client = clientMock; tested.node = nodeMock; tested.destroy(); Mockito.verify(nodeMock).close(); Mockito.verify(clientMock).close(); Mockito.reset(nodeMock, clientMock); tested.client = clientMock; tested.node = nodeMock; Mockito.doThrow(new RuntimeException()).when(clientMock).close(); try { tested.destroy(); } catch (Exception e) { } Mockito.verify(nodeMock).close(); Mockito.verify(clientMock).close(); Mockito.reset(nodeMock, clientMock); tested.client = clientMock; tested.node = nodeMock; Mockito.doThrow(new RuntimeException()).when(nodeMock).close(); try { tested.destroy(); } catch (Exception e) { } Mockito.verify(nodeMock).close(); Mockito.verify(clientMock).close(); }