@Test public void keepAliveSubscriberWhoHasSubscriptions() { 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) .keepAlive(with(subscriber), with(any(AsyncCallback.class))); } }); pushChannel.onTime(); }
@Test(expected = SubscriberNotAliveException.class) public void unableToKeepSubscriberAlive() { 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) .keepAlive(with(subscriber), with(any(AsyncCallback.class))); will(asyncAction); } }); pushChannel.onTime(); context.checking( new Expectations() { { oneOf(timer).scheduleAction(with(any(Integer.class)), with(timerAction)); } }); asyncAction.onFailure(new RuntimeException()); context.checking( new Expectations() { { oneOf(pushChannelServiceAsync) .keepAlive(with(subscriber), with(any(AsyncCallback.class))); will(asyncAction); } }); timerAction.getValue().execute(); asyncAction.onFailure(new RuntimeException()); }
@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(); }