@Test public void test1() { final ActivityDTO a1 = context.mock(ActivityDTO.class, "a1"); final ActivityDTO a2 = context.mock(ActivityDTO.class, "a2"); final ActivityDTO a3 = context.mock(ActivityDTO.class, "a3"); final ActivityDTO a4 = context.mock(ActivityDTO.class, "a4"); final CommentDTO c1 = context.mock(CommentDTO.class, "c1"); final CommentDTO c2 = context.mock(CommentDTO.class, "c2"); final CommentDTO c3 = context.mock(CommentDTO.class, "c3"); final CommentDTO c4 = context.mock(CommentDTO.class, "c4"); final PersonModelView p1 = context.mock(PersonModelView.class, "p1"); final PersonModelView p3 = context.mock(PersonModelView.class, "p3"); final PersonModelView p5 = context.mock(PersonModelView.class, "p5"); final List<CommentDTO> a4c = Collections.singletonList(c4); 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(null)); allowing(a2).getFirstComment(); will(returnValue(c1)); allowing(a2).getLastComment(); will(returnValue(null)); allowing(a3).getComments(); will(returnValue(null)); allowing(a3).getFirstComment(); will(returnValue(c2)); allowing(a3).getLastComment(); will(returnValue(c3)); allowing(a4).getComments(); will(returnValue(a4c)); allowing(c1).getAuthorId(); will(returnValue(1L)); allowing(c2).getAuthorId(); will(returnValue(3L)); allowing(c3).getAuthorId(); will(returnValue(1L)); allowing(c4).getAuthorId(); will(returnValue(5L)); oneOf(personMapper).execute(with(new EasyMatcher<List<Long>>() { @Override protected boolean isMatch(final List<Long> inTestObject) { return inTestObject.size() == 3 && inTestObject.contains(1L) && inTestObject.contains(3L) && inTestObject.contains(5L); } })); will(returnValue(Arrays.asList(p1, p3, p5))); allowing(p1).getId(); will(returnValue(1L)); allowing(p3).getId(); will(returnValue(3L)); allowing(p5).getId(); will(returnValue(5L)); allowing(p1).isAccountLocked(); will(returnValue(true)); allowing(p3).isAccountLocked(); will(returnValue(false)); allowing(p5).isAccountLocked(); will(returnValue(false)); oneOf(c1).setAuthorActive(false); oneOf(c2).setAuthorActive(true); oneOf(c3).setAuthorActive(false); oneOf(c4).setAuthorActive(true); } }); IsCommentAuthorLockedFilter sut = new IsCommentAuthorLockedFilter(personMapper); sut.filter(Arrays.asList(a1, a2, a3, a4), 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);  }