SystemCommanderClient implements Closeable { @Override public void close() { try { jmxConnector.close(); } catch (IOException ignored) { } } SystemCommanderClient(final JMXConnector jmxConnector, final MBeanConnector mBeanConnector); SystemCommanderMBean getRemote(final String contextName); @Override void close();  }
@Test public void shouldCloseTheJmxConnectorOnTryWithResources() throws Exception { try(final SystemCommanderClient anotherSystemCommanderClient = new SystemCommanderClient(jmxConnector, mBeanConnector)) { assertThat(anotherSystemCommanderClient, is(notNullValue())); } verify(jmxConnector).close(); }