@Test public void testClose() throws Exception { prepareUsernamePasswordSession(); final CachedConnection connection = new CachedConnection(USERNAME, PASSWORD, SERVER_ADDRESS, librarian); assertThat(connection.isClosed()).isFalse(); final ChannelSftp closed = mock(ChannelSftp.class); when(closed.isClosed()).thenReturn(Boolean.TRUE); when(usernamePasswordSession.openChannel("sftp")).thenReturn(sftp).thenReturn(closed); when(usernamePasswordSession.openChannel("shell")).thenReturn(shell); connection.getSFtp(); connection.getSFtp(); connection.getShell(); connection.close(); assertThat(connection.isClosed()).isTrue(); verify(shell).disconnect(); verify(sftp).disconnect(); verify(closed, never()).disconnect(); verify(librarian).checkIn(connection); }
@Override public void close() { closed = true; for (final Channel channel : channels) { if (!channel.isClosed()) { channel.disconnect(); } } channels.clear(); librarian.checkIn(this); }
CachedConnection implements Connection { @Override public void close() { closed = true; for (final Channel channel : channels) { if (!channel.isClosed()) { channel.disconnect(); } } channels.clear(); librarian.checkIn(this); } }
CachedConnection implements Connection { @Override public void close() { closed = true; for (final Channel channel : channels) { if (!channel.isClosed()) { channel.disconnect(); } } channels.clear(); librarian.checkIn(this); } CachedConnection(final String username, final String password, final URI serverAddress,
            final ConnectionLibrarian<CachedConnection> librarian);  CachedConnection(final String username, final String salt, final URI privateKeyLocation,
            final URI serverAddress, final ConnectionLibrarian<CachedConnection> librarian); }
CachedConnection implements Connection { @Override public void close() { closed = true; for (final Channel channel : channels) { if (!channel.isClosed()) { channel.disconnect(); } } channels.clear(); librarian.checkIn(this); } CachedConnection(final String username, final String password, final URI serverAddress,
            final ConnectionLibrarian<CachedConnection> librarian);  CachedConnection(final String username, final String salt, final URI privateKeyLocation,
            final URI serverAddress, final ConnectionLibrarian<CachedConnection> librarian); @Override void close(); void closePhysical(); @Override boolean equals(final Object obj); @Override ChannelSftp getSFtp(); @Override ChannelShell getShell(); @Override int hashCode(); @Override boolean isClosed(); }
CachedConnection implements Connection { @Override public void close() { closed = true; for (final Channel channel : channels) { if (!channel.isClosed()) { channel.disconnect(); } } channels.clear(); librarian.checkIn(this); } CachedConnection(final String username, final String password, final URI serverAddress,
            final ConnectionLibrarian<CachedConnection> librarian);  CachedConnection(final String username, final String salt, final URI privateKeyLocation,
            final URI serverAddress, final ConnectionLibrarian<CachedConnection> librarian); @Override void close(); void closePhysical(); @Override boolean equals(final Object obj); @Override ChannelSftp getSFtp(); @Override ChannelShell getShell(); @Override int hashCode(); @Override boolean isClosed();  }