### Question:
QuestionSubscribersFilter implements SubscribersFilter { @Override public void filter(Collection<JCUser> users, SubscriptionAwareEntity entity) { if (entity instanceof Post && ((Post)entity).getTopic().getType().equals(QuestionsAndAnswersPlugin.TOPIC_TYPE)) { JCUser postCreator = ((Post)entity).getUserCreated(); boolean containsCreator = users.contains(postCreator); users.clear(); if (containsCreator) { users.add(((Post) entity).getUserCreated()); } } }  @Override void filter(Collection<JCUser> users, SubscriptionAwareEntity entity);  }### Answer:
@Test public void questionSubscribersFilterShouldNotChangeRecepientsIfBranchSubscribersFilters() { Branch branch = new Branch("name", "description"); JCUser user1 = new JCUser("name1", "email1@example.com", "pwd1"); JCUser user2 = new JCUser("name2", "email2@example.com", "pwd2"); QuestionSubscribersFilter filter = new QuestionSubscribersFilter(); List<JCUser> users = new ArrayList<>(Arrays.asList(user1, user2)); filter.filter(users, branch); assertEquals(users.size(), 2); assertTrue(users.contains(user1)); assertTrue(users.contains(user2)); }
@Test public void questionSubscribersFilterShouldNotChangeRecepientsIfTopicSubscribersFilters() { Topic topic = new Topic(); JCUser user1 = new JCUser("name1", "email1@example.com", "pwd1"); JCUser user2 = new JCUser("name2", "email2@example.com", "pwd2"); QuestionSubscribersFilter filter = new QuestionSubscribersFilter(); List<JCUser> users = new ArrayList<>(Arrays.asList(user1, user2)); filter.filter(users, topic); assertEquals(users.size(), 2); assertTrue(users.contains(user1)); assertTrue(users.contains(user2)); }
@Test public void questionSubscribersFilterShouldNotChangeRecepientsIfPostFomTopicWithOtherType() { Post post = getInTopicWithType("Some amazing topic"); JCUser user1 = new JCUser("name1", "email1@example.com", "pwd1"); JCUser user2 = new JCUser("name2", "email2@example.com", "pwd2"); QuestionSubscribersFilter filter = new QuestionSubscribersFilter(); List<JCUser> users = new ArrayList<>(Arrays.asList(user1, user2)); filter.filter(users, post); assertEquals(users.size(), 2); assertTrue(users.contains(user1)); assertTrue(users.contains(user2)); }
@Test public void questionSubscribersFilterShouldLeaveOnlyPostAuthorInIfPostSubscribersFilters() { Post post = getInTopicWithType(QuestionsAndAnswersPlugin.TOPIC_TYPE); JCUser user1 = new JCUser("name1", "email1@example.com", "pwd1"); JCUser user2 = new JCUser("name2", "email2@example.com", "pwd2"); QuestionSubscribersFilter filter = new QuestionSubscribersFilter(); List<JCUser> users = new ArrayList<>(Arrays.asList(user1, user2, post.getUserCreated())); filter.filter(users, post); assertEquals(users.size(), 1); assertTrue(users.contains(post.getUserCreated())); }