### Question:
NotificationService { public void sendNotificationAboutRemovingTopic(Topic topic) { subscribedEntityChanged(topic.getBranch()); Collection<JCUser> subscribers = subscriptionService.getAllowedSubscribers(topic); Collection<JCUser> branchSubscribers = subscriptionService.getAllowedSubscribers(topic.getBranch()); subscribers.removeAll(branchSubscribers); String curUser = userService.getCurrentUser().getUsername(); this.filterSubscribers(subscribers, topic); for (JCUser subscriber : subscribers) { mailService.sendRemovingTopicMail(subscriber, topic, curUser); } } NotificationService(
            UserService userService,
            MailService mailService,
            SubscriptionService subscriptionService,
            PluginLoader pluginLoader); void subscribedEntityChanged(SubscriptionAwareEntity entity); void sendNotificationAboutTopicMoved(Topic topic); void sendNotificationAboutRemovingTopic(Topic topic); void sendNotificationAboutTopicCreated(Topic topic);  }### Answer:
@Test public void testTopicRemovedTopicSubscribers() { topic.setSubscribers(new HashSet<JCUser>()); topic.getSubscribers().add(user1); topic.getSubscribers().add(user2); when(subscriptionService.getAllowedSubscribers(topic)).thenReturn(topic.getSubscribers()); service.sendNotificationAboutRemovingTopic(topic); verify(mailService).sendRemovingTopicMail(user1, topic, currentUser.getUsername()); verify(mailService).sendRemovingTopicMail(user2, topic, currentUser.getUsername()); }
@Test public void testTopicRemovedCurrentUserIsTopicSubscriber() { topic.setSubscribers(new HashSet<JCUser>()); topic.getSubscribers().add(currentUser); topic.getSubscribers().add(user1); when(subscriptionService.getAllowedSubscribers(topic)).thenReturn(topic.getSubscribers()); service.sendNotificationAboutRemovingTopic(topic); verify(mailService, never()).sendRemovingTopicMail(currentUser, topic, currentUser.getUsername()); verify(mailService).sendRemovingTopicMail(user1, topic, currentUser.getUsername()); }
@Test public void testTopicRemovedBranchSubscribers() { branch.setSubscribers(new HashSet<JCUser>()); branch.getSubscribers().add(user1); branch.getSubscribers().add(user2); when(subscriptionService.getAllowedSubscribers(branch)).thenReturn(branch.getSubscribers()); service.sendNotificationAboutRemovingTopic(topic); verify(mailService).sendUpdatesOnSubscription(user1, branch); verify(mailService).sendUpdatesOnSubscription(user2, branch); }
@Test public void testTopicRemovedCurrentUserIsBranchSubscriber() { branch.setSubscribers(new HashSet<JCUser>()); branch.getSubscribers().add(currentUser); branch.getSubscribers().add(user1); when(subscriptionService.getAllowedSubscribers(branch)).thenReturn(branch.getSubscribers()); service.sendNotificationAboutRemovingTopic(topic); verify(mailService, never()).sendUpdatesOnSubscription(currentUser, branch); verify(mailService).sendUpdatesOnSubscription(user1, branch); }
@Test public void testTopicRemovedUserSubscribedToBranchAndTopic() { branch.setSubscribers(new HashSet<JCUser>()); branch.getSubscribers().add(user1); branch.getSubscribers().add(user2); topic.getSubscribers().add(user2); topic.getSubscribers().add(user3); when(subscriptionService.getAllowedSubscribers(branch)).thenReturn(branch.getSubscribers()); when(subscriptionService.getAllowedSubscribers(topic)).thenReturn(topic.getSubscribers()); service.sendNotificationAboutRemovingTopic(topic); verify(mailService).sendUpdatesOnSubscription(user1, branch); verify(mailService, never()).sendRemovingTopicMail(user1, topic, currentUser.getUsername()); verify(mailService, never()).sendRemovingTopicMail(user2, topic, currentUser.getUsername()); verify(mailService).sendUpdatesOnSubscription(user2, branch); verify(mailService).sendRemovingTopicMail(user3, topic, currentUser.getUsername()); verify(mailService, never()).sendUpdatesOnSubscription(user3, branch); }