UserManagerFacade implements UserManager { @Override public Authorizable getAuthorizable(final String id) throws RepositoryException { Authorizable internal = delegate.getAuthorizable(id); return AuthorizableFacade.ensureBestWrapper(internal); } UserManagerFacade(final @NotNull UserManager delegate); @Override boolean isAutoSave(); @Override Authorizable getAuthorizable(final String id); @Override T getAuthorizable(final String id, final Class<T> authorizableClass); @Override Authorizable getAuthorizable(final Principal principal); @Override Authorizable getAuthorizableByPath(final String path); @Override Iterator<Authorizable> findAuthorizables(final String relPath, final String value); @Override Iterator<Authorizable> findAuthorizables(final String relPath, final String value, final int searchType); @Override Iterator<Authorizable> findAuthorizables(final Query query); @Override User createUser(final String userID, final String password); @Override User createUser(final String userID, final String password, final Principal principal, final String intermediatePath); @Override User createSystemUser(final String userID, final String intermediatePath); @Override Group createGroup(final String groupID); @Override Group createGroup(final Principal principal); @Override Group createGroup(final Principal principal, final String intermediatePath); @Override Group createGroup(final String groupID, final Principal principal, final String intermediatePath); @Override void autoSave(final boolean enable);  }
@Test(expected = AuthorizableTypeException.class) public void testGetAuthorizableThrows() throws Exception { UserManager delegate = mock(UserManager.class); UserManagerFacade facade = getFacade(delegate); final AuthorizableFacadeTest.SuperAuthz superValue = mock(AuthorizableFacadeTest.SuperAuthz.class); when(delegate.getAuthorizable("foo", AuthorizableFacadeTest.SuperAuthz.class)).thenReturn(superValue); facade.getAuthorizable("foo", AuthorizableFacadeTest.SuperAuthz.class); }
@Test public void testGetAuthorizable() throws Exception { UserManager delegate = mock(UserManager.class); UserManagerFacade facade = getFacade(delegate); final User userValue = mock(User.class); when(userValue.getID()).thenReturn("foo"); final Group groupValue = mock(Group.class); when(groupValue.getID()).thenReturn("bar"); when(delegate.getAuthorizable(anyString(), isNull())).thenReturn(null); when(delegate.getAuthorizable("foo", User.class)).thenReturn(userValue); when(delegate.getAuthorizable("foo", Authorizable.class)).thenReturn(userValue); when(delegate.getAuthorizable("bar", Group.class)).thenReturn(groupValue); when(delegate.getAuthorizable("bar", Authorizable.class)).thenReturn(groupValue); assertNull("is null", facade.getAuthorizable("", null)); Authorizable userFacadeAuthz = facade.getAuthorizable("foo", Authorizable.class); assertTrue("is user facade", userFacadeAuthz instanceof UserFacade); assertEquals("is same id", "foo", userFacadeAuthz.getID()); User userFacade = facade.getAuthorizable("foo", User.class); assertTrue("is user facade", userFacade instanceof UserFacade); assertEquals("is same id", "foo", userFacade.getID()); Authorizable groupFacadeAuthz = facade.getAuthorizable("bar", Authorizable.class); assertTrue("is group facade", groupFacadeAuthz instanceof GroupFacade); assertEquals("is same id", "bar", groupFacadeAuthz.getID()); Group groupFacade = facade.getAuthorizable("bar", Group.class); assertTrue("is group facade", groupFacade instanceof GroupFacade); assertEquals("is same id", "bar", groupFacade.getID()); }