### Question:
TransactionalSubscriptionService implements SubscriptionService { @Override public Collection<JCUser> getAllowedSubscribers(SubscriptionAwareEntity entity){ if (entity instanceof Topic) { return this.topicDao.getAllowedSubscribers(entity); } else if (entity instanceof Post) { Post post = (Post) entity; Collection<JCUser> subscribers = topicDao.getAllowedSubscribers(post.getTopic()); if (subscribers.contains(post.getUserCreated())) { List<JCUser> arrayList = new ArrayList<>(1); arrayList.add(post.getUserCreated()); return arrayList; } else { return new ArrayList<>(); } } else{ return this.branchDao.getAllowedSubscribers(entity); } } 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 testGetAllowedSubscribersForTopic() { when(topicDao.getAllowedSubscribers(topic)).thenReturn(Collections.singleton(user)); assertTrue(service.getAllowedSubscribers(topic).contains(user)); verify(topicDao).getAllowedSubscribers(topic); }
@Test public void testGetAllowedSubscribersForBranch() { when(branchDao.getAllowedSubscribers(branch)).thenReturn(Collections.singleton(user)); assertTrue(service.getAllowedSubscribers(branch).contains(user)); verify(branchDao).getAllowedSubscribers(branch); }