### Question:
TopicHibernateDao extends GenericDao<Topic> implements TopicDao { @Override public Collection<JCUser> getAllowedSubscribers(SubscriptionAwareEntity entity) { @SuppressWarnings("unchecked") Set<JCUser> foundUsers = new HashSet<JCUser>(session() .getNamedQuery("getAllowedSubscribersForTopic") .setParameter("topic", entity) .list()); return foundUsers; } TopicHibernateDao(SessionFactory sessionFactory); @Override Page<Topic> getTopicsUpdatedSince(DateTime timeStamp, PageRequest pageRequest, JCUser user); @Override Page<Topic> getUnansweredTopics(PageRequest pageRequest, JCUser user); @Override Topic getLastUpdatedTopicInBranch(Branch branch); @Override Page<Topic> getTopics(Branch branch, PageRequest pageRequest); @Override int countTopics(Branch branch); @Override Collection<JCUser> getAllowedSubscribers(SubscriptionAwareEntity entity); @Override List<Long> getForbiddenBranchesIds(JCUser user); @Override List<Long> getAllowedBranchesIds(JCUser user);  }### Answer:
@Test public void testGetSubscribersWithAllowedPermission() { Topic topic = createAndSaveTopicWithSubscribers(); JCUser subscriber = topic.getTopicStarter(); PersistedObjectsFactory.createAndSaveViewTopicsBranchesEntity( topic.getBranch().getId(), String.valueOf(subscriber.getGroups().get(0).getId()), true); assertEquals(dao.getAllowedSubscribers(topic).size(), 1, "Should return subscribers which are contained in some group with VIEW_TOPIC permission and not contained in any group with disallowed VIEW_TOPIC permission."); }
@Test public void testGetSubscribersWithDisallowedPermission() { Topic topic = createAndSaveTopicWithSubscribers(); JCUser subscriber = topic.getTopicStarter(); PersistedObjectsFactory.createAndSaveViewTopicsBranchesEntity( topic.getBranch().getId(), String.valueOf(subscriber.getGroups().get(0).getId()), false); assertEquals(dao.getAllowedSubscribers(topic).size(), 0, "Should not return subscribers which are contained in any group with disallowed VIEW_TOPIC permission."); }
@Test public void testGetSubscribersWithAllowedAndDisallowedPermission() { Topic topic = createAndSaveTopicWithSubscribers(); JCUser subscriber = topic.getTopicStarter(); PersistedObjectsFactory.createAndSaveViewTopicsBranchesEntity( topic.getBranch().getId(), String.valueOf(subscriber.getGroups().get(0).getId()), false); PersistedObjectsFactory.createAndSaveViewTopicsBranchesEntity( topic.getBranch().getId(), String.valueOf(subscriber.getGroups().get(1).getId()), true); assertEquals(dao.getAllowedSubscribers(topic).size(), 0, "Should not return subscribers which are contained in any group with disallowed VIEW_TOPIC permission."); }
@Test public void testGetSubscribersWithoutAllowedAndDisallowedPermission() { Topic topic = createAndSaveTopicWithSubscribers(); assertEquals(dao.getAllowedSubscribers(topic).size(), 0, "Should not return subscribers which are not contained in any group with VIEW_TOPIC permission."); }