DetailsFetcherFactory { public ANMDetailsFetcher detailsFetcher(List<String> roles) { if(roles.contains(PHC_USER_ROLE)) { return phcUserDetailsFetcher; } return scUserDetailsFetcher; } @Autowired  DetailsFetcherFactory(SCUserDetailsFetcher scUserDetailsFetcher,
                                 PHCUserDetailsFetcher phcUserDetailsFetcher); ANMDetailsFetcher detailsFetcher(List<String> roles);  }
@Test public void shouldReturnPHCDetailsFetcherWhenUserRoleIsPHCUser() { ANMDetailsFetcher anmDetailsFetcher = detailsFetcherFactory.detailsFetcher(asList("ROLE_PHC_USER", "ROLE_USER")); assertTrue(anmDetailsFetcher instanceof PHCUserDetailsFetcher); }
@Test public void shouldReturnPHCDetailsFetcherWhenUserRoleIsSCUser() { ANMDetailsFetcher anmDetailsFetcher = detailsFetcherFactory.detailsFetcher(asList("ROLE_USER")); assertTrue(anmDetailsFetcher instanceof SCUserDetailsFetcher); }