CompositeUserRoleListService implements IUserRoleListService { @Override public List<String> getAllUsers() { return collectResultsForOperation( new CompositeOperation() { @Override public List<String> perform( IUserRoleListService service ) { return service.getAllUsers(); } } ); } CompositeUserRoleListService( List<IUserRoleListService> delegates ); void setStrategy( STRATEGY strategy ); void setStrategy( String strategy ); STRATEGY getActiveStrategy(); @Override List<String> getAllRoles(); @Override List<String> getSystemRoles(); @Override List<String> getAllRoles( final ITenant tenant ); @Override List<String> getAllUsers(); @Override List<String> getAllUsers( final ITenant tenant ); @Override List<String> getUsersInRole( final ITenant tenant, final String role ); @Override List<String> getRolesForUser( final ITenant tenant, final String username );  }
@Test public void testGetAllUsers() throws Exception { List<String> allUsers = compositeService.getAllUsers(); assertEquals( 2, allUsers.size() ); compositeService.setStrategy( CompositeUserRoleListService.STRATEGY.ADDITIVE ); allUsers = compositeService.getAllUsers(); assertEquals( 3, allUsers.size() ); assertTrue( unsortedEqualArrays( allUsers.toArray( new String[allUsers.size()] ), new String[]{"user1", "suzy", "joe"} ) ); }
@Test public void testGetAllUsers2() throws Exception { CompositeUserRoleListService badCompositeService = new CompositeUserRoleListService( Arrays.asList( service1, null ) ); List<String> allUsers = badCompositeService.getAllUsers( null ); assertNotNull( allUsers ); assertTrue( allUsers instanceof List ); assertEquals( 0, allUsers.size() ); }
@Test public void testGetAllUsers3() throws Exception { IUserRoleListService badService = mock( IUserRoleListService.class ); CompositeUserRoleListService badCompositeService = new CompositeUserRoleListService( Arrays.asList( badService, badService ) ); List<String> allUsers = badCompositeService.getAllUsers( null ); assertNotNull( allUsers); assertTrue( allUsers instanceof List ); assertEquals( 0, allUsers.size() ); }