@Test
  public void reopenChannelWhenTokenExpires() {

    final AsyncAction<String> asyncAction = new AsyncAction<String>();

    context.checking(
        new Expectations() {
          {
            oneOf(pushChannelServiceAsync)
                .connect(with(subscriber), with(any(AsyncCallback.class)));
            will(asyncAction);

            oneOf(channel).open(with("channelToken"), with(channelListener));
          }
        });

    pushChannel.connect();
    asyncAction.onSuccess("channelToken");

    context.checking(
        new Expectations() {
          {
            oneOf(pushChannelServiceAsync)
                .connect(with(subscriber), with(any(AsyncCallback.class)));
            will(asyncAction);

            oneOf(channel).open(with("newChannelToken"), with(channelListener));
          }
        });

    channelListener.getValue().onTokenExpire();
    asyncAction.onSuccess("newChannelToken");

    assertTrue(pushChannel.hasInitialConnection());
  }
  @Test
  public void openConnection() throws Exception {

    context.checking(
        new Expectations() {
          {
            oneOf(pushChannelServiceAsync)
                .connect(with(subscriber), with(any(AsyncCallback.class)));
            will(asyncAction);
          }
        });

    pushChannel.connect();
    assertTrue(pushChannel.hasInitialConnection());
  }
  @Test
  public void retryToOpenConnection() throws Exception {
    final AsyncAction<String> asyncAction = new AsyncAction<String>();

    context.checking(
        new Expectations() {
          {
            oneOf(pushChannelServiceAsync)
                .connect(with(subscriber), with(any(AsyncCallback.class)));
            will(asyncAction);

            oneOf(timer).reconnect(pushChannel);
          }
        });

    pushChannel.connect();
    asyncAction.onFailure(new RuntimeException());
  }