@Test public void closeConnection() { StreamConnectionId streamConnectionId = StreamConnectionId.of("foo"); final StreamConnection streamConnection = streamConnectionManager .openConnection(streamConnectionId); assertThat(streamConnectionManager.closeConnection(streamConnectionId)).get().isEqualTo(streamConnection); assertThat(streamConnectionManager.closeConnection(streamConnectionId)).get().isEqualTo(streamConnection); }
public Optional<StreamConnection> closeConnection(final StreamConnectionId streamConnectionId) { Objects.requireNonNull(streamConnectionId); return Optional.ofNullable(connections.get(streamConnectionId)) .map(connectionToClose -> { connectionToClose.closeConnection(); return connectionToClose; }); }
StreamConnectionManager { public Optional<StreamConnection> closeConnection(final StreamConnectionId streamConnectionId) { Objects.requireNonNull(streamConnectionId); return Optional.ofNullable(connections.get(streamConnectionId)) .map(connectionToClose -> { connectionToClose.closeConnection(); return connectionToClose; }); } }
StreamConnectionManager { public Optional<StreamConnection> closeConnection(final StreamConnectionId streamConnectionId) { Objects.requireNonNull(streamConnectionId); return Optional.ofNullable(connections.get(streamConnectionId)) .map(connectionToClose -> { connectionToClose.closeConnection(); return connectionToClose; }); }  }
StreamConnectionManager { public Optional<StreamConnection> closeConnection(final StreamConnectionId streamConnectionId) { Objects.requireNonNull(streamConnectionId); return Optional.ofNullable(connections.get(streamConnectionId)) .map(connectionToClose -> { connectionToClose.closeConnection(); return connectionToClose; }); }  StreamConnection openConnection(final StreamConnectionId streamConnectionId); Optional<StreamConnection> closeConnection(final StreamConnectionId streamConnectionId); }
StreamConnectionManager { public Optional<StreamConnection> closeConnection(final StreamConnectionId streamConnectionId) { Objects.requireNonNull(streamConnectionId); return Optional.ofNullable(connections.get(streamConnectionId)) .map(connectionToClose -> { connectionToClose.closeConnection(); return connectionToClose; }); }  StreamConnection openConnection(final StreamConnectionId streamConnectionId); Optional<StreamConnection> closeConnection(final StreamConnectionId streamConnectionId);  }