CachingUserRoleListServiceDecorator implements IUserRoleListService { @Override public List<String> getUsersInRole( final ITenant tenant, final String role ) { return performOperation( ALL_USERS + getTenantKey( tenant ) + role, new DelegateOperation() { @Override public List<String> perform() { return delegate.getUsersInRole( tenant, role ); } } ); } CachingUserRoleListServiceDecorator( IUserRoleListService delegate ); @Override List<String> getAllRoles(); @Override List<String> getSystemRoles(); @Override List<String> getRolesForUser( final ITenant tenant, final String username ); @Override List<String> getAllUsers( final ITenant tenant ); @Override List<String> getAllRoles( final ITenant tenant ); @Override List<String> getUsersInRole( final ITenant tenant, final String role ); @Override List<String> getAllUsers();  }
@Test public void testGetUsersInRole() throws Exception { IUserRoleListService mockService = mock( IUserRoleListService.class ); when( mockService.getUsersInRole( tenant, "ceo" ) ).thenReturn( Arrays.asList( "foo", "bar" ) ); CachingUserRoleListServiceDecorator decorator = new CachingUserRoleListServiceDecorator( mockService ); List<String> allRoles = decorator.getUsersInRole( tenant, "ceo" ); assertArrayEquals( "does not match", new String[] { "foo", "bar" }, allRoles.toArray() ); allRoles = decorator.getUsersInRole( tenant, "ceo" ); assertArrayEquals( "does not match", new String[] { "foo", "bar" }, allRoles.toArray() ); verify( mockService, times( 1 ) ).getUsersInRole( tenant, "ceo" ); }