DiagnosticServiceImpl implements DiagnosticService { @Override public void close() { try { delegate.close(); } catch (Exception e) { LOGGER.debug("Failed to close diagnostic entity", e); } try { connection.close(); } catch (Exception e) { LOGGER.debug("Failed to close diagnostic connection", e); } } DiagnosticServiceImpl(Connection connection, Diagnostics delegate, DiagnosticCodec<?> codec); @Override boolean isConnected(); @Override T getProxy(Class<T> type); @Override void close(); @Override String get(String name, String attribute); @Override void set(String name, String attribute, String arg); @Override String invoke(String name, String cmd); @Override String invokeWithArg(String name, String cmd, String arg); @Override LogicalServerState getLogicalServerState(); @Override String getInitialState(); @Override String getClusterState(); @Override String getConfig(); @Override String getProcessArguments(); @Override String getThreadDump(); @Override void terminateServer(); @Override void forceTerminateServer();  }
@Test public void test_close() throws IOException { service.close(); verify(diagnostics, times(1)).close(); verify(connection, times(1)).close(); }
@Test public void test_close_not_fail() throws IOException { doThrow(new IllegalStateException()).when(diagnostics).close(); service.close(); verify(diagnostics, times(1)).close(); verify(connection, times(1)).close(); reset(diagnostics); reset(connection); doThrow(new IllegalStateException()).when(connection).close(); service.close(); verify(diagnostics, times(1)).close(); verify(connection, times(1)).close(); }