@Test public void testFollowing() { final List<Long> idList = new ArrayList<Long>(Arrays.asList(1L, 2L, 3L)); final List<FollowerStatusable> fsList = new ArrayList<FollowerStatusable>(Arrays.asList(fs1, fs2, fs3)); final Long idInList = 1L; context.checking(new Expectations() { { oneOf(fs1).getEntityType(); will(returnValue(EntityType.PERSON)); oneOf(personIdsFollowedByPrincipalMapper).execute(currentUserId); will(returnValue(idList)); oneOf(fs1).getEntityId(); will(returnValue(idInList)); oneOf(fs1).setFollowerStatus(FollowerStatus.FOLLOWING); oneOf(fs2).getEntityType(); will(returnValue(EntityType.GROUP)); oneOf(groupIdsFollowedByPrincipalMapper).execute(currentUserId); will(returnValue(idList)); oneOf(fs2).getEntityId(); will(returnValue(idInList)); oneOf(fs2).setFollowerStatus(FollowerStatus.FOLLOWING); oneOf(fs3).getEntityType(); will(returnValue(EntityType.NOTSET)); oneOf(fs3).setFollowerStatus(FollowerStatus.NOTSPECIFIED); } }); sut.execute(currentUserId, fsList, null); context.assertIsSatisfied(); }
public List<T> execute(final Long inCurrentUserId, final List<T> inFollowerStatusables, final FollowerStatus inDefaultStatus) { FollowerStatus defaultStatus = inDefaultStatus == null ? FollowerStatus.NOTSPECIFIED : inDefaultStatus; List<Long> personIds = null; List<Long> groupIds = null; long entityId; for (FollowerStatusable fs : inFollowerStatusables) { switch (fs.getEntityType()) { case PERSON: if (personIds == null) { personIds = personIdsFollowedByPrincipalMapper.execute(inCurrentUserId); } entityId = fs.getEntityId(); if (entityId != inCurrentUserId && personIds.contains(entityId)) { fs.setFollowerStatus(FollowerStatus.FOLLOWING); } else { fs.setFollowerStatus(FollowerStatus.NOTFOLLOWING); } break; case GROUP: if (groupIds == null) { groupIds = groupIdsFollowedByPrincipalMapper.execute(inCurrentUserId); } fs.setFollowerStatus(groupIds.contains(fs.getEntityId()) ? FollowerStatus.FOLLOWING : FollowerStatus.NOTFOLLOWING); break; default: fs.setFollowerStatus(defaultStatus); break; } } return inFollowerStatusables; }
FollowerStatusPopulator { public List<T> execute(final Long inCurrentUserId, final List<T> inFollowerStatusables, final FollowerStatus inDefaultStatus) { FollowerStatus defaultStatus = inDefaultStatus == null ? FollowerStatus.NOTSPECIFIED : inDefaultStatus; List<Long> personIds = null; List<Long> groupIds = null; long entityId; for (FollowerStatusable fs : inFollowerStatusables) { switch (fs.getEntityType()) { case PERSON: if (personIds == null) { personIds = personIdsFollowedByPrincipalMapper.execute(inCurrentUserId); } entityId = fs.getEntityId(); if (entityId != inCurrentUserId && personIds.contains(entityId)) { fs.setFollowerStatus(FollowerStatus.FOLLOWING); } else { fs.setFollowerStatus(FollowerStatus.NOTFOLLOWING); } break; case GROUP: if (groupIds == null) { groupIds = groupIdsFollowedByPrincipalMapper.execute(inCurrentUserId); } fs.setFollowerStatus(groupIds.contains(fs.getEntityId()) ? FollowerStatus.FOLLOWING : FollowerStatus.NOTFOLLOWING); break; default: fs.setFollowerStatus(defaultStatus); break; } } return inFollowerStatusables; } }
FollowerStatusPopulator { public List<T> execute(final Long inCurrentUserId, final List<T> inFollowerStatusables, final FollowerStatus inDefaultStatus) { FollowerStatus defaultStatus = inDefaultStatus == null ? FollowerStatus.NOTSPECIFIED : inDefaultStatus; List<Long> personIds = null; List<Long> groupIds = null; long entityId; for (FollowerStatusable fs : inFollowerStatusables) { switch (fs.getEntityType()) { case PERSON: if (personIds == null) { personIds = personIdsFollowedByPrincipalMapper.execute(inCurrentUserId); } entityId = fs.getEntityId(); if (entityId != inCurrentUserId && personIds.contains(entityId)) { fs.setFollowerStatus(FollowerStatus.FOLLOWING); } else { fs.setFollowerStatus(FollowerStatus.NOTFOLLOWING); } break; case GROUP: if (groupIds == null) { groupIds = groupIdsFollowedByPrincipalMapper.execute(inCurrentUserId); } fs.setFollowerStatus(groupIds.contains(fs.getEntityId()) ? FollowerStatus.FOLLOWING : FollowerStatus.NOTFOLLOWING); break; default: fs.setFollowerStatus(defaultStatus); break; } } return inFollowerStatusables; } FollowerStatusPopulator(final DomainMapper<Long, List<Long>> inPersonIdsFollowedByPrincipalMapper,
            final DomainMapper<Long, List<Long>> inGroupIdsFollowedByPrincipalMapper); }
FollowerStatusPopulator { public List<T> execute(final Long inCurrentUserId, final List<T> inFollowerStatusables, final FollowerStatus inDefaultStatus) { FollowerStatus defaultStatus = inDefaultStatus == null ? FollowerStatus.NOTSPECIFIED : inDefaultStatus; List<Long> personIds = null; List<Long> groupIds = null; long entityId; for (FollowerStatusable fs : inFollowerStatusables) { switch (fs.getEntityType()) { case PERSON: if (personIds == null) { personIds = personIdsFollowedByPrincipalMapper.execute(inCurrentUserId); } entityId = fs.getEntityId(); if (entityId != inCurrentUserId && personIds.contains(entityId)) { fs.setFollowerStatus(FollowerStatus.FOLLOWING); } else { fs.setFollowerStatus(FollowerStatus.NOTFOLLOWING); } break; case GROUP: if (groupIds == null) { groupIds = groupIdsFollowedByPrincipalMapper.execute(inCurrentUserId); } fs.setFollowerStatus(groupIds.contains(fs.getEntityId()) ? FollowerStatus.FOLLOWING : FollowerStatus.NOTFOLLOWING); break; default: fs.setFollowerStatus(defaultStatus); break; } } return inFollowerStatusables; } FollowerStatusPopulator(final DomainMapper<Long, List<Long>> inPersonIdsFollowedByPrincipalMapper,
            final DomainMapper<Long, List<Long>> inGroupIdsFollowedByPrincipalMapper); List<T> execute(final Long inCurrentUserId, final List<T> inFollowerStatusables,
            final FollowerStatus inDefaultStatus); }
FollowerStatusPopulator { public List<T> execute(final Long inCurrentUserId, final List<T> inFollowerStatusables, final FollowerStatus inDefaultStatus) { FollowerStatus defaultStatus = inDefaultStatus == null ? FollowerStatus.NOTSPECIFIED : inDefaultStatus; List<Long> personIds = null; List<Long> groupIds = null; long entityId; for (FollowerStatusable fs : inFollowerStatusables) { switch (fs.getEntityType()) { case PERSON: if (personIds == null) { personIds = personIdsFollowedByPrincipalMapper.execute(inCurrentUserId); } entityId = fs.getEntityId(); if (entityId != inCurrentUserId && personIds.contains(entityId)) { fs.setFollowerStatus(FollowerStatus.FOLLOWING); } else { fs.setFollowerStatus(FollowerStatus.NOTFOLLOWING); } break; case GROUP: if (groupIds == null) { groupIds = groupIdsFollowedByPrincipalMapper.execute(inCurrentUserId); } fs.setFollowerStatus(groupIds.contains(fs.getEntityId()) ? FollowerStatus.FOLLOWING : FollowerStatus.NOTFOLLOWING); break; default: fs.setFollowerStatus(defaultStatus); break; } } return inFollowerStatusables; } FollowerStatusPopulator(final DomainMapper<Long, List<Long>> inPersonIdsFollowedByPrincipalMapper,
            final DomainMapper<Long, List<Long>> inGroupIdsFollowedByPrincipalMapper); List<T> execute(final Long inCurrentUserId, final List<T> inFollowerStatusables,
            final FollowerStatus inDefaultStatus);  }