### Question:
SoupBinTCPSession implements Closeable { public int receive() throws IOException { int bytes = channel.read(rxBuffer); if (bytes <= 0) return bytes; rxBuffer.flip(); while (parse()); rxBuffer.compact(); receivedData(); return bytes; } protected  SoupBinTCPSession(Clock clock, SocketChannel channel, int maxPayloadLength,
            byte heartbeatPacketType); SocketChannel getChannel(); int receive(); void keepAlive(); @Override void close();  }### Answer:
@Test public void loginAccepted() throws Exception { loginAccepted.setSession("foo"); loginAccepted.setSequenceNumber(123); server.accept(loginAccepted); while (clientStatus.collect().size() != 1) client.receive(); assertEquals(asList(new LoginAccepted(" foo", 123)), clientStatus.collect()); }
@Test public void loginRejected() throws Exception { loginRejected.rejectReasonCode = SoupBinTCP.LOGIN_REJECT_CODE_NOT_AUTHORIZED; server.reject(loginRejected); while (clientStatus.collect().size() != 1) client.receive(); assertEquals(asList(new LoginRejected(SoupBinTCP.LOGIN_REJECT_CODE_NOT_AUTHORIZED)), clientStatus.collect()); }
@Test public void endOfSession() throws Exception { server.endSession(); while (clientStatus.collect().size() != 1) client.receive(); assertEquals(asList(new EndOfSession()), clientStatus.collect()); }
@Test public void loginRequest() throws Exception { loginRequest.setUsername("foo"); loginRequest.setPassword("bar"); loginRequest.setRequestedSession("baz"); loginRequest.setRequestedSequenceNumber(123); client.login(loginRequest); while (serverStatus.collect().size() != 1) server.receive(); assertEquals(asList(new LoginRequest("foo ", "bar ", " baz", 123)), serverStatus.collect()); }
@Test public void logoutRequest() throws Exception { client.logout(); while (serverStatus.collect().size() != 1) server.receive(); assertEquals(asList(new LogoutRequest()), serverStatus.collect()); }