@Test public void returnsTheRestrictedConstituenciesForUser() throws Exception { Constituency rugby = constituency().withName("Rugby").build(); Constituency covSouth = constituency().withName("Coventry South").build(); Ward henley = ward().withWardName("Henley").withConstituency(covSouth).build(); User user = user() .withRole(Role.USER) .withConstituencies(newHashSet(rugby)) .withWards(newHashSet(henley)) .build(); UserRestrictedConstituencies constituencies = underTest.getVisibleConstituenciesByUserWithWardContext(user); assertThat(constituencies.getConstituencies(), hasItem(covSouth)); assertThat(constituencies.getConstituencies(), hasItem(rugby)); verifyZeroInteractions(constituencyRepository); }
public UserRestrictedConstituencies getVisibleConstituenciesByUserWithWardContext(User user) { Set<Constituency> wardConstituencies = user.getWards() .stream() .map(Ward::getConstituency) .collect(toSet()); wardConstituencies.addAll(user.getConstituencies()); return new UserRestrictedConstituencies(wardConstituencies); }
ConstituencyService { public UserRestrictedConstituencies getVisibleConstituenciesByUserWithWardContext(User user) { Set<Constituency> wardConstituencies = user.getWards() .stream() .map(Ward::getConstituency) .collect(toSet()); wardConstituencies.addAll(user.getConstituencies()); return new UserRestrictedConstituencies(wardConstituencies); } }
ConstituencyService { public UserRestrictedConstituencies getVisibleConstituenciesByUserWithWardContext(User user) { Set<Constituency> wardConstituencies = user.getWards() .stream() .map(Ward::getConstituency) .collect(toSet()); wardConstituencies.addAll(user.getConstituencies()); return new UserRestrictedConstituencies(wardConstituencies); } @Autowired  ConstituencyService(ConstituencyRepository constituencyRepository); }
ConstituencyService { public UserRestrictedConstituencies getVisibleConstituenciesByUserWithWardContext(User user) { Set<Constituency> wardConstituencies = user.getWards() .stream() .map(Ward::getConstituency) .collect(toSet()); wardConstituencies.addAll(user.getConstituencies()); return new UserRestrictedConstituencies(wardConstituencies); } @Autowired  ConstituencyService(ConstituencyRepository constituencyRepository); UserRestrictedConstituencies getVisibleConstituenciesByUserWithWardContext(User user); @Transactional(readOnly = true) UserRestrictedConstituencies getVisibleConstituenciesByUser(User user, int limit); @Transactional(readOnly = true) List<Constituency> searchUserRestrictedConstituencies(User user, String searchTerm); @Transactional(readOnly = true) Try<List<Constituency>> constituenciesByName(User permissible, String name, int limit); Try<Constituency> getByCodeRestrictedByAssociation(String code, User user); @Transactional(readOnly = true) Try<Constituency> getByCode(String code); }
ConstituencyService { public UserRestrictedConstituencies getVisibleConstituenciesByUserWithWardContext(User user) { Set<Constituency> wardConstituencies = user.getWards() .stream() .map(Ward::getConstituency) .collect(toSet()); wardConstituencies.addAll(user.getConstituencies()); return new UserRestrictedConstituencies(wardConstituencies); } @Autowired  ConstituencyService(ConstituencyRepository constituencyRepository); UserRestrictedConstituencies getVisibleConstituenciesByUserWithWardContext(User user); @Transactional(readOnly = true) UserRestrictedConstituencies getVisibleConstituenciesByUser(User user, int limit); @Transactional(readOnly = true) List<Constituency> searchUserRestrictedConstituencies(User user, String searchTerm); @Transactional(readOnly = true) Try<List<Constituency>> constituenciesByName(User permissible, String name, int limit); Try<Constituency> getByCodeRestrictedByAssociation(String code, User user); @Transactional(readOnly = true) Try<Constituency> getByCode(String code);  }