@Test public void test2() { final ActivityDTO a1 = context.mock(ActivityDTO.class, "a1"); final ActivityDTO a2 = context.mock(ActivityDTO.class, "a2"); final DomainMapper personMapper = context.mock(DomainMapper.class, "personMapper"); context.checking(new Expectations() { { allowing(a1).getComments(); will(returnValue(null)); allowing(a1).getFirstComment(); will(returnValue(null)); allowing(a1).getLastComment(); will(returnValue(null)); allowing(a2).getComments(); will(returnValue(Collections.emptyList())); allowing(a2).getFirstComment(); will(returnValue(null)); allowing(a1).getLastComment(); will(returnValue(null)); } }); IsCommentAuthorLockedFilter sut = new IsCommentAuthorLockedFilter(personMapper); sut.filter(Arrays.asList(a1, a2), null); context.assertIsSatisfied(); }
@Override public void filter(final List<ActivityDTO> inActivities, final PersonModelView inCurrentUserAccount) { Collection<CommentDTO> comments = new ArrayList<CommentDTO>(); for (ActivityDTO activity : inActivities) { if (activity.getComments() != null) { comments.addAll(activity.getComments()); } else if (activity.getFirstComment() != null) { comments.add(activity.getFirstComment()); if (activity.getLastComment() != null) { comments.add(activity.getLastComment()); } } } if (comments.isEmpty()) { return; } Set<Long> ids = new HashSet<Long>(); for (CommentDTO comment : comments) { ids.add(comment.getAuthorId()); } List<PersonModelView> peopleList = getPeopleMapper.execute(new CollectionListAdapter<Long>(ids)); HashMap<Long, Boolean> peopleIndex = new HashMap<Long, Boolean>(); for (PersonModelView person : peopleList) { peopleIndex.put(person.getId(), person.isAccountLocked()); } for (CommentDTO comment : comments) { comment.setAuthorActive(!peopleIndex.get(comment.getAuthorId())); } }
IsCommentAuthorLockedFilter implements ActivityFilter { @Override public void filter(final List<ActivityDTO> inActivities, final PersonModelView inCurrentUserAccount) { Collection<CommentDTO> comments = new ArrayList<CommentDTO>(); for (ActivityDTO activity : inActivities) { if (activity.getComments() != null) { comments.addAll(activity.getComments()); } else if (activity.getFirstComment() != null) { comments.add(activity.getFirstComment()); if (activity.getLastComment() != null) { comments.add(activity.getLastComment()); } } } if (comments.isEmpty()) { return; } Set<Long> ids = new HashSet<Long>(); for (CommentDTO comment : comments) { ids.add(comment.getAuthorId()); } List<PersonModelView> peopleList = getPeopleMapper.execute(new CollectionListAdapter<Long>(ids)); HashMap<Long, Boolean> peopleIndex = new HashMap<Long, Boolean>(); for (PersonModelView person : peopleList) { peopleIndex.put(person.getId(), person.isAccountLocked()); } for (CommentDTO comment : comments) { comment.setAuthorActive(!peopleIndex.get(comment.getAuthorId())); } } }
IsCommentAuthorLockedFilter implements ActivityFilter { @Override public void filter(final List<ActivityDTO> inActivities, final PersonModelView inCurrentUserAccount) { Collection<CommentDTO> comments = new ArrayList<CommentDTO>(); for (ActivityDTO activity : inActivities) { if (activity.getComments() != null) { comments.addAll(activity.getComments()); } else if (activity.getFirstComment() != null) { comments.add(activity.getFirstComment()); if (activity.getLastComment() != null) { comments.add(activity.getLastComment()); } } } if (comments.isEmpty()) { return; } Set<Long> ids = new HashSet<Long>(); for (CommentDTO comment : comments) { ids.add(comment.getAuthorId()); } List<PersonModelView> peopleList = getPeopleMapper.execute(new CollectionListAdapter<Long>(ids)); HashMap<Long, Boolean> peopleIndex = new HashMap<Long, Boolean>(); for (PersonModelView person : peopleList) { peopleIndex.put(person.getId(), person.isAccountLocked()); } for (CommentDTO comment : comments) { comment.setAuthorActive(!peopleIndex.get(comment.getAuthorId())); } } IsCommentAuthorLockedFilter(final DomainMapper<Collection<Long>, List<PersonModelView>> inGetPeopleMapper); }
IsCommentAuthorLockedFilter implements ActivityFilter { @Override public void filter(final List<ActivityDTO> inActivities, final PersonModelView inCurrentUserAccount) { Collection<CommentDTO> comments = new ArrayList<CommentDTO>(); for (ActivityDTO activity : inActivities) { if (activity.getComments() != null) { comments.addAll(activity.getComments()); } else if (activity.getFirstComment() != null) { comments.add(activity.getFirstComment()); if (activity.getLastComment() != null) { comments.add(activity.getLastComment()); } } } if (comments.isEmpty()) { return; } Set<Long> ids = new HashSet<Long>(); for (CommentDTO comment : comments) { ids.add(comment.getAuthorId()); } List<PersonModelView> peopleList = getPeopleMapper.execute(new CollectionListAdapter<Long>(ids)); HashMap<Long, Boolean> peopleIndex = new HashMap<Long, Boolean>(); for (PersonModelView person : peopleList) { peopleIndex.put(person.getId(), person.isAccountLocked()); } for (CommentDTO comment : comments) { comment.setAuthorActive(!peopleIndex.get(comment.getAuthorId())); } } IsCommentAuthorLockedFilter(final DomainMapper<Collection<Long>, List<PersonModelView>> inGetPeopleMapper); @Override void filter(final List<ActivityDTO> inActivities, final PersonModelView inCurrentUserAccount); }
IsCommentAuthorLockedFilter implements ActivityFilter { @Override public void filter(final List<ActivityDTO> inActivities, final PersonModelView inCurrentUserAccount) { Collection<CommentDTO> comments = new ArrayList<CommentDTO>(); for (ActivityDTO activity : inActivities) { if (activity.getComments() != null) { comments.addAll(activity.getComments()); } else if (activity.getFirstComment() != null) { comments.add(activity.getFirstComment()); if (activity.getLastComment() != null) { comments.add(activity.getLastComment()); } } } if (comments.isEmpty()) { return; } Set<Long> ids = new HashSet<Long>(); for (CommentDTO comment : comments) { ids.add(comment.getAuthorId()); } List<PersonModelView> peopleList = getPeopleMapper.execute(new CollectionListAdapter<Long>(ids)); HashMap<Long, Boolean> peopleIndex = new HashMap<Long, Boolean>(); for (PersonModelView person : peopleList) { peopleIndex.put(person.getId(), person.isAccountLocked()); } for (CommentDTO comment : comments) { comment.setAuthorActive(!peopleIndex.get(comment.getAuthorId())); } } IsCommentAuthorLockedFilter(final DomainMapper<Collection<Long>, List<PersonModelView>> inGetPeopleMapper); @Override void filter(final List<ActivityDTO> inActivities, final PersonModelView inCurrentUserAccount);  }