### Question:
BranchHibernateDao extends GenericDao<Branch> implements BranchDao { @Override public Collection<JCUser> getAllowedSubscribers(SubscriptionAwareEntity entity){ @SuppressWarnings("unchecked") Set<JCUser> foundUsers = new HashSet(session() .getNamedQuery("getAllowedSubscribersForBranch") .setParameter("branch", entity) .list()); return foundUsers; } BranchHibernateDao(SessionFactory sessionFactory); @SuppressWarnings("unchecked") @Override List<Branch> getAllBranches(); @Override int getCountPostsInBranch(Branch branch); @Override Collection<JCUser> getAllowedSubscribers(SubscriptionAwareEntity entity);  }### Answer:
@Test public void testGetSubscribersWithAllowedPermission() { JCUser subscriber = PersistedObjectsFactory.getDefaultUserWithGroups(); branch.getSubscribers().add(subscriber); session.save(branch); PersistedObjectsFactory.createAndSaveViewTopicsBranchesEntity( branch.getId(), String.valueOf(subscriber.getGroups().get(0).getId()), true); assertEquals(dao.getAllowedSubscribers(branch).size(), 1, "Should return subscribers which are contained in some group with VIEW_TOPIC permission."); }
@Test public void testGetSubscribersWithDisallowedPermission() { JCUser subscriber = PersistedObjectsFactory.getDefaultUserWithGroups(); branch.getSubscribers().add(subscriber); session.save(branch); PersistedObjectsFactory.createAndSaveViewTopicsBranchesEntity( branch.getId(), String.valueOf(subscriber.getGroups().get(0).getId()), false); assertEquals(dao.getAllowedSubscribers(branch).size(), 0, "Should not return subscribers which are contained in any group with disallowed VIEW_TOPIC permission."); }
@Test public void testGetSubscribersWithAllowedAndDisallowedPermission() { JCUser subscriber = PersistedObjectsFactory.getDefaultUserWithGroups(); branch.getSubscribers().add(subscriber); session.save(branch); PersistedObjectsFactory.createAndSaveViewTopicsBranchesEntity( branch.getId(), String.valueOf(subscriber.getGroups().get(0).getId()), false); PersistedObjectsFactory.createAndSaveViewTopicsBranchesEntity( branch.getId(), String.valueOf(subscriber.getGroups().get(1).getId()), true); assertEquals(dao.getAllowedSubscribers(branch).size(), 0, "Should not return subscribers which are contained in any group with disallowed VIEW_TOPIC permission."); }
@Test public void testGetSubscribersWithoutAllowedAndDisallowedPermission() { JCUser subscriber = PersistedObjectsFactory.getDefaultUserWithGroups(); branch.getSubscribers().add(subscriber); session.save(branch); assertEquals(dao.getAllowedSubscribers(branch).size(), 0, "Should not return subscribers which are not contained in any group with allowed VIEW_TOPIC permission."); }