  @Test public void send() {

    final AtomicReference<Throwable> callbackFailure = new AtomicReference<>();

    subscriptionTransport = new WebSocketSubscriptionTransport(webSocketRequest, webSocketFactory, new SubscriptionTransport.Callback() {
      @Override public void onConnected() {
      }

      @Override public void onFailure(Throwable t) {
        callbackFailure.set(t);
      }

      @Override public void onMessage(OperationServerMessage message) {
      }

      @Override public void onClosed() {
      }
    });

    subscriptionTransport.send(new OperationClientMessage.Init(Collections.<String, Object>emptyMap()));
    assertThat(callbackFailure.get()).isInstanceOf(IllegalStateException.class);
    callbackFailure.set(null);

    subscriptionTransport.connect();
    subscriptionTransport.send(new OperationClientMessage.Init(Collections.<String, Object>emptyMap()));
    assertThat(callbackFailure.get()).isNull();
    subscriptionTransport.disconnect(new OperationClientMessage.Terminate());

    subscriptionTransport.send(new OperationClientMessage.Init(Collections.<String, Object>emptyMap()));
    assertThat(callbackFailure.get()).isInstanceOf(IllegalStateException.class);
  }