### Question:
TransactionalSubscriptionService implements SubscriptionService { @Override public void toggleSubscription(SubscriptionAwareEntity entityToSubscribe) { JCUser current = userService.getCurrentUser(); if (entityToSubscribe.getSubscribers().contains(current)) { entityToSubscribe.getSubscribers().remove(current); } else { entityToSubscribe.getSubscribers().add(current); } saveChanges(entityToSubscribe); } TransactionalSubscriptionService(UserService userService,
                                            BranchDao branchDao,
                                            TopicDao topicDao); @Override void toggleTopicSubscription(Topic topic); @Override void toggleBranchSubscription(Branch branch); @Override void unsubscribeFromBranch(Branch branch); @Override void toggleSubscription(SubscriptionAwareEntity entityToSubscribe); @Override Collection<JCUser> getAllowedSubscribers(SubscriptionAwareEntity entity); @Override void subscribe(SubscriptionAwareEntity entityToSubscribe);  }### Answer:
@Test public void testToggleSubscriptionTopicCase() { service.toggleSubscription(topic); assertTrue(topic.getSubscribers().contains(user)); verify(topicDao).saveOrUpdate(topic); }
@Test public void testToggleSubscriptionTopicAlreadySubscribedTopicCase() { topic.getSubscribers().add(user); service.toggleSubscription(topic); assertFalse(topic.getSubscribers().contains(user)); verify(topicDao).saveOrUpdate(topic); }
@Test public void testToggleSubscriptionBranchCase() { service.toggleSubscription(branch); assertTrue(branch.getSubscribers().contains(user)); }
@Test public void testToggleSubscriptionAlreadySubscribedBranchCase() { branch.getSubscribers().add(user); service.toggleSubscription(branch); assertFalse(branch.getSubscribers().contains(user)); }