ResubscribingLiveDataClient implements LiveDataClient { @Override public void unsubscribe(UserPrincipal user, LiveDataSpecification spec, LiveDataListener listener) { _subscriptions.remove(new Subscription(user, spec, listener)); _delegate.unsubscribe(user, spec, listener); } ResubscribingLiveDataClient(LiveDataClient delegate); @Override void subscribe(UserPrincipal user, LiveDataSpecification spec, LiveDataListener listener); @Override void subscribe(UserPrincipal user, Collection<LiveDataSpecification> specs, LiveDataListener listener); @Override void unsubscribe(UserPrincipal user, LiveDataSpecification spec, LiveDataListener listener); @Override void unsubscribe(UserPrincipal user, Collection<LiveDataSpecification> specs, LiveDataListener listener); @Override LiveDataSubscriptionResponse snapshot(UserPrincipal user, LiveDataSpecification spec, long timeout); @Override Collection<LiveDataSubscriptionResponse> snapshot(UserPrincipal user,
                                                           Collection<LiveDataSpecification> specs,
                                                           long timeout); @Override String getDefaultNormalizationRuleSetId(); @Override void close(); @Override boolean isEntitled(UserPrincipal user, LiveDataSpecification spec); @Override Map<LiveDataSpecification, Boolean> isEntitled(UserPrincipal user, Collection<LiveDataSpecification> specs); void resubscribe();  }
@Test public void unsubscribe() { LiveDataClient delegate = mock(LiveDataClient.class); ResubscribingLiveDataClient client = new ResubscribingLiveDataClient(delegate); Listener listener = new Listener(); client.subscribe(UserPrincipal.getTestUser(), SPEC1, listener); client.subscribe(UserPrincipal.getTestUser(), SPEC2, listener); client.unsubscribe(UserPrincipal.getTestUser(), SPEC1, listener); verify(delegate).subscribe(UserPrincipal.getTestUser(), SPEC1, listener); verify(delegate).subscribe(UserPrincipal.getTestUser(), SPEC2, listener); verify(delegate).unsubscribe(UserPrincipal.getTestUser(), SPEC1, listener); reset(delegate); client.resubscribe(); verify(delegate).subscribe(UserPrincipal.getTestUser(), SPEC2, listener); }