コード例 #1
0
  @Test(expected = UnableToUnsubscribeFromEventException.class)
  public void unableToUnsubscribeFromEvent() {

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

            oneOf(timer).scheduleAction(with(any(Integer.class)), with(timerAction));
          }
        });

    pushChannel.unsubscribe(event.TYPE, unsubscribeCallback);
    asyncAction.onFailure(new RuntimeException());

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

            never(timer);
          }
        });

    timerAction.getValue().execute();
    asyncAction.onFailure(null);

    assertThat(unsubscribeCallback.timesCalled, is(0));
  }
コード例 #2
0
  @Test
  public void unsubscribeFromEvent() {

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

    pushChannel.unsubscribe(event.TYPE, unsubscribeCallback);
    asyncAction.onSuccess(null);

    assertThat(unsubscribeCallback.timesCalled, is(1));
  }
コード例 #3
0
  @Test
  public void subscriberWithoutSubscriptionsIsNotKeptAlive() {

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

    pushChannel.subscribe(event.TYPE, subscribeCallback);
    asyncAction.onSuccess(null);

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

    pushChannel.unsubscribe(event.TYPE, unsubscribeCallback);
    asyncAction.onSuccess(null);

    context.checking(
        new Expectations() {
          {
            never(timer);
            never(pushChannelServiceAsync);
          }
        });

    pushChannel.onTime();
  }