SiriClientSubscriptionManager implements StatusProviderService { synchronized void removeSubscription(SubscriptionId subscriptionId) { ClientSubscriptionInstance instance = _activeSubscriptions.remove(subscriptionId); if (instance == null) { _log.warn("subscription has already been removed: {}", subscriptionId); return; } ScheduledFuture<?> expirationTask = instance.getExpirationTask(); if (expirationTask != null) { expirationTask.cancel(true); } ClientSubscriptionChannel channel = instance.getChannel(); Set<SubscriptionId> subscriptions = channel.getSubscriptions(); subscriptions.remove(instance.getSubscriptionId()); if (subscriptions.isEmpty()) { _log.debug("channel has no more subscriptions: {}", channel.getAddress()); _checkStatusManager.resetCheckStatusTask(channel, 0); _heartbeatManager.resetHeartbeat(channel, 0); _activeChannels.remove(channel.getAddress()); } }  @Inject void setSchedulingService(SchedulingService schedulingService); @Inject void setHeartbeatManager(HeartbeatManager heartbeatManager); void registerPendingSubscription(SiriClientRequest request,
      SubscriptionRequest subscriptionRequest); void clearPendingSubscription(SiriClientRequest request,
      SubscriptionRequest subscriptionRequest); void handleSubscriptionResponse(SubscriptionResponseStructure response); boolean isSubscriptionActive(SubscriptionId subscriptionId); boolean isSubscriptionActiveForModuleDelivery(
      AbstractServiceDeliveryStructure moduleDelivery); void recordServiceDeliveryStatistics(ServiceDelivery serviceDelivery); SiriChannelInfo getChannelInfoForServiceDelivery(
      ServiceDelivery serviceDelivery); void handleTerminateSubscriptionResponse(
      TerminateSubscriptionResponseStructure response); void terminateAllSubscriptions(
      boolean waitForTerminateSubscriptionResponseOnExit); void handleCheckStatusNotification(
      CheckStatusResponseStructure response); void handleHeartbeatNotification(
      HeartbeatNotificationStructure heartbeat); @Override void getStatus(Map<String, String> status);  }
@Test public void testRemoveSubscription() { SubscriptionResponseStructure response = new SubscriptionResponseStructure(); StatusResponseStructure status = new StatusResponseStructure(); SubscriptionId subscriptionId = new SubscriptionId("subscriberA", "subscriptionB"); ESiriModuleType moduleType = ESiriModuleType.VEHICLE_MONITORING; SiriClientRequest originalSubscriptionRequest = new SiriClientRequest(); originalSubscriptionRequest.setTargetUrl("http: originalSubscriptionRequest.setInitialTerminationDuration(60 * 1000); @SuppressWarnings("unchecked") ScheduledFuture<Object> expirationTask = Mockito.mock(ScheduledFuture.class); Mockito.when( _schedulingService.schedule(Mockito.any(Runnable.class), Mockito.anyLong(), Mockito.any(TimeUnit.class))).thenReturn( expirationTask); _manager.upgradePendingSubscription(response, status, subscriptionId, moduleType, originalSubscriptionRequest); _manager.removeSubscription(subscriptionId); assertFalse(_manager.isSubscriptionActive(subscriptionId)); Mockito.verify(_checkStatusManager, Mockito.times(2)).resetCheckStatusTask( Mockito.any(ClientSubscriptionChannel.class), Mockito.eq(0)); Mockito.verify(_heartbeatManager, Mockito.times(2)).resetHeartbeat( Mockito.any(ClientSubscriptionChannel.class), Mockito.eq(0)); Mockito.verify(expirationTask).cancel(true); }