@Test(expected=RuntimeException.class) public final void testGroupsPeopleAndUnknown() { List<StreamScope> bookmarks = new ArrayList<StreamScope>(); bookmarks.add(personScope); bookmarks.add(groupScope); bookmarks.add(otherScope); context.checking(new Expectations() { { oneOf(getPersonModelViewsByAccountIdsMapper).execute(with(any(List.class))); will(returnValue(Collections.singletonList(person))); oneOf(groupMapper).execute(with(any(List.class))); will(returnValue(Collections.singletonList(group))); } }); sut.transform(bookmarks).size(); context.assertIsSatisfied(); }
public List<StreamFilter> transform(final List<StreamScope> bookmarks) { List<String> personIds = new ArrayList<String>(); List<String> groupIds = new ArrayList<String>(); for (int i = 0; i < bookmarks.size(); i++) { ScopeType type = bookmarks.get(i).getScopeType(); switch (type) { case PERSON: personIds.add(bookmarks.get(i).getUniqueKey()); break; case GROUP: groupIds.add(bookmarks.get(i).getUniqueKey()); break; default: throw new RuntimeException("Unhandled type."); } } List<PersonModelView> people = null; if (personIds.size() > 0) { people = getPersonModelViewsByAccountIdsMapper.execute(personIds); } List<DomainGroupModelView> groups = null; if (groupIds.size() > 0) { groups = groupMapper.execute(groupIds); } final List<StreamFilter> filters = new ArrayList<StreamFilter>(); if (people != null) { for (PersonModelView person : people) { final String name = person.getDisplayName(); final String request = "{\"query\":{\"recipient\":[{\"type\":\"PERSON\",\"name\":\"" + person.getAccountId() + "\"}]}}"; filters.add(new BookmarkFilter(person.getStreamId(), name, request, person.getAvatarId(), person .getEntityId())); } } if (groups != null) { for (DomainGroupModelView group : groups) { final String name = group.getName(); final String request = "{\"query\":{\"recipient\":[{\"type\":\"GROUP\",\"name\":\"" + group.getShortName() + "\"}]}}"; filters.add(new BookmarkFilter(group.getStreamId(), name, request, group.getAvatarId(), group .getEntityId())); } } return filters; }
BookmarkStreamFilterTransformer implements Transformer<List<StreamScope>, List<StreamFilter>> { public List<StreamFilter> transform(final List<StreamScope> bookmarks) { List<String> personIds = new ArrayList<String>(); List<String> groupIds = new ArrayList<String>(); for (int i = 0; i < bookmarks.size(); i++) { ScopeType type = bookmarks.get(i).getScopeType(); switch (type) { case PERSON: personIds.add(bookmarks.get(i).getUniqueKey()); break; case GROUP: groupIds.add(bookmarks.get(i).getUniqueKey()); break; default: throw new RuntimeException("Unhandled type."); } } List<PersonModelView> people = null; if (personIds.size() > 0) { people = getPersonModelViewsByAccountIdsMapper.execute(personIds); } List<DomainGroupModelView> groups = null; if (groupIds.size() > 0) { groups = groupMapper.execute(groupIds); } final List<StreamFilter> filters = new ArrayList<StreamFilter>(); if (people != null) { for (PersonModelView person : people) { final String name = person.getDisplayName(); final String request = "{\"query\":{\"recipient\":[{\"type\":\"PERSON\",\"name\":\"" + person.getAccountId() + "\"}]}}"; filters.add(new BookmarkFilter(person.getStreamId(), name, request, person.getAvatarId(), person .getEntityId())); } } if (groups != null) { for (DomainGroupModelView group : groups) { final String name = group.getName(); final String request = "{\"query\":{\"recipient\":[{\"type\":\"GROUP\",\"name\":\"" + group.getShortName() + "\"}]}}"; filters.add(new BookmarkFilter(group.getStreamId(), name, request, group.getAvatarId(), group .getEntityId())); } } return filters; } }
BookmarkStreamFilterTransformer implements Transformer<List<StreamScope>, List<StreamFilter>> { public List<StreamFilter> transform(final List<StreamScope> bookmarks) { List<String> personIds = new ArrayList<String>(); List<String> groupIds = new ArrayList<String>(); for (int i = 0; i < bookmarks.size(); i++) { ScopeType type = bookmarks.get(i).getScopeType(); switch (type) { case PERSON: personIds.add(bookmarks.get(i).getUniqueKey()); break; case GROUP: groupIds.add(bookmarks.get(i).getUniqueKey()); break; default: throw new RuntimeException("Unhandled type."); } } List<PersonModelView> people = null; if (personIds.size() > 0) { people = getPersonModelViewsByAccountIdsMapper.execute(personIds); } List<DomainGroupModelView> groups = null; if (groupIds.size() > 0) { groups = groupMapper.execute(groupIds); } final List<StreamFilter> filters = new ArrayList<StreamFilter>(); if (people != null) { for (PersonModelView person : people) { final String name = person.getDisplayName(); final String request = "{\"query\":{\"recipient\":[{\"type\":\"PERSON\",\"name\":\"" + person.getAccountId() + "\"}]}}"; filters.add(new BookmarkFilter(person.getStreamId(), name, request, person.getAvatarId(), person .getEntityId())); } } if (groups != null) { for (DomainGroupModelView group : groups) { final String name = group.getName(); final String request = "{\"query\":{\"recipient\":[{\"type\":\"GROUP\",\"name\":\"" + group.getShortName() + "\"}]}}"; filters.add(new BookmarkFilter(group.getStreamId(), name, request, group.getAvatarId(), group .getEntityId())); } } return filters; } BookmarkStreamFilterTransformer(
            final DomainMapper<List<String>, List<PersonModelView>> inGetPersonModelViewsByAccountIdsMapper,
            final GetDomainGroupsByShortNames inGroupMapper); }
BookmarkStreamFilterTransformer implements Transformer<List<StreamScope>, List<StreamFilter>> { public List<StreamFilter> transform(final List<StreamScope> bookmarks) { List<String> personIds = new ArrayList<String>(); List<String> groupIds = new ArrayList<String>(); for (int i = 0; i < bookmarks.size(); i++) { ScopeType type = bookmarks.get(i).getScopeType(); switch (type) { case PERSON: personIds.add(bookmarks.get(i).getUniqueKey()); break; case GROUP: groupIds.add(bookmarks.get(i).getUniqueKey()); break; default: throw new RuntimeException("Unhandled type."); } } List<PersonModelView> people = null; if (personIds.size() > 0) { people = getPersonModelViewsByAccountIdsMapper.execute(personIds); } List<DomainGroupModelView> groups = null; if (groupIds.size() > 0) { groups = groupMapper.execute(groupIds); } final List<StreamFilter> filters = new ArrayList<StreamFilter>(); if (people != null) { for (PersonModelView person : people) { final String name = person.getDisplayName(); final String request = "{\"query\":{\"recipient\":[{\"type\":\"PERSON\",\"name\":\"" + person.getAccountId() + "\"}]}}"; filters.add(new BookmarkFilter(person.getStreamId(), name, request, person.getAvatarId(), person .getEntityId())); } } if (groups != null) { for (DomainGroupModelView group : groups) { final String name = group.getName(); final String request = "{\"query\":{\"recipient\":[{\"type\":\"GROUP\",\"name\":\"" + group.getShortName() + "\"}]}}"; filters.add(new BookmarkFilter(group.getStreamId(), name, request, group.getAvatarId(), group .getEntityId())); } } return filters; } BookmarkStreamFilterTransformer(
            final DomainMapper<List<String>, List<PersonModelView>> inGetPersonModelViewsByAccountIdsMapper,
            final GetDomainGroupsByShortNames inGroupMapper); List<StreamFilter> transform(final List<StreamScope> bookmarks); }
BookmarkStreamFilterTransformer implements Transformer<List<StreamScope>, List<StreamFilter>> { public List<StreamFilter> transform(final List<StreamScope> bookmarks) { List<String> personIds = new ArrayList<String>(); List<String> groupIds = new ArrayList<String>(); for (int i = 0; i < bookmarks.size(); i++) { ScopeType type = bookmarks.get(i).getScopeType(); switch (type) { case PERSON: personIds.add(bookmarks.get(i).getUniqueKey()); break; case GROUP: groupIds.add(bookmarks.get(i).getUniqueKey()); break; default: throw new RuntimeException("Unhandled type."); } } List<PersonModelView> people = null; if (personIds.size() > 0) { people = getPersonModelViewsByAccountIdsMapper.execute(personIds); } List<DomainGroupModelView> groups = null; if (groupIds.size() > 0) { groups = groupMapper.execute(groupIds); } final List<StreamFilter> filters = new ArrayList<StreamFilter>(); if (people != null) { for (PersonModelView person : people) { final String name = person.getDisplayName(); final String request = "{\"query\":{\"recipient\":[{\"type\":\"PERSON\",\"name\":\"" + person.getAccountId() + "\"}]}}"; filters.add(new BookmarkFilter(person.getStreamId(), name, request, person.getAvatarId(), person .getEntityId())); } } if (groups != null) { for (DomainGroupModelView group : groups) { final String name = group.getName(); final String request = "{\"query\":{\"recipient\":[{\"type\":\"GROUP\",\"name\":\"" + group.getShortName() + "\"}]}}"; filters.add(new BookmarkFilter(group.getStreamId(), name, request, group.getAvatarId(), group .getEntityId())); } } return filters; } BookmarkStreamFilterTransformer(
            final DomainMapper<List<String>, List<PersonModelView>> inGetPersonModelViewsByAccountIdsMapper,
            final GetDomainGroupsByShortNames inGroupMapper); List<StreamFilter> transform(final List<StreamScope> bookmarks);  }