CachingUserRoleListServiceDecorator implements IUserRoleListService { @Override public List<String> getAllRoles() { return performOperation( ALL_ROLES, ALL_ROLES_OPERATION ); } 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 testGetAllRoles() throws Exception { IUserRoleListService mockService = mock( IUserRoleListService.class ); when( mockService.getAllRoles() ).thenReturn( Arrays.asList( "foo", "bar" ) ); CachingUserRoleListServiceDecorator decorator = new CachingUserRoleListServiceDecorator( mockService ); List<String> allRoles = decorator.getAllRoles(); assertArrayEquals( "does not match", new String[] { "foo", "bar" }, allRoles.toArray() ); allRoles = decorator.getAllRoles(); assertArrayEquals( "does not match", new String[] { "foo", "bar" }, allRoles.toArray() ); verify( mockService, times( 1 ) ).getAllRoles(); }
@Test public void testGetAllRoles1() throws Exception { IUserRoleListService mockService = mock( IUserRoleListService.class ); when( mockService.getAllRoles( tenant ) ).thenReturn( Arrays.asList( "foo", "bar" ) ); CachingUserRoleListServiceDecorator decorator = new CachingUserRoleListServiceDecorator( mockService ); List<String> allRoles = decorator.getAllRoles( tenant ); assertArrayEquals( "does not match", new String[] { "foo", "bar" }, allRoles.toArray() ); allRoles = decorator.getAllRoles( tenant ); assertArrayEquals( "does not match", new String[] { "foo", "bar" }, allRoles.toArray() ); verify( mockService, times( 1 ) ).getAllRoles( tenant ); }