UserUtil implements UserConstants { @Nullable public static <T extends Authorizable> T castAuthorizable(@Nullable Authorizable authorizable, Class<T> authorizableClass) throws AuthorizableTypeException { if (authorizable == null) { return null; } if (authorizableClass != null && authorizableClass.isInstance(authorizable)) { return authorizableClass.cast(authorizable); } else { throw new AuthorizableTypeException("Invalid authorizable type '" + ((authorizableClass == null) ? "null" : authorizableClass) + '\''); } } private  UserUtil(); static boolean isAdmin(@NotNull ConfigurationParameters parameters, @NotNull String userId); @NotNull static String getAdminId(@NotNull ConfigurationParameters parameters); @NotNull static String getAnonymousId(@NotNull ConfigurationParameters parameters); static boolean isType(@Nullable Tree authorizableTree, @NotNull AuthorizableType type); @Nullable static AuthorizableType getType(@NotNull Tree authorizableNode); @Nullable static AuthorizableType getType(@Nullable String primaryTypeName); static boolean isSystemUser(@Nullable Tree authorizableTree); @Nullable static String getAuthorizableRootPath(@NotNull ConfigurationParameters parameters,
                                                 @Nullable AuthorizableType type); @Nullable static String getAuthorizableId(@NotNull Tree authorizableTree); @NotNull static String getAuthorizableId(@NotNull Tree authorizableTree, @NotNull AuthorizableType type); @Nullable static T castAuthorizable(@Nullable Authorizable authorizable, Class<T> authorizableClass); static int getImportBehavior(@NotNull ConfigurationParameters config);  }
@Test public void testCastNullAuthorizable() throws Exception { assertNull(UserUtil.castAuthorizable(null, null)); assertNull(UserUtil.castAuthorizable(null, User.class)); assertNull(UserUtil.castAuthorizable(null, Group.class)); }
@Test(expected = AuthorizableTypeException.class) public void testCastNullClass() throws Exception { UserUtil.castAuthorizable(Mockito.mock(User.class), null); }
@Test(expected = AuthorizableTypeException.class) public void testCastUserToGroup() throws Exception { UserUtil.castAuthorizable(Mockito.mock(User.class), Group.class); }
@Test(expected = AuthorizableTypeException.class) public void testCastGroupToUser() throws Exception { UserUtil.castAuthorizable(Mockito.mock(Group.class), User.class); }
@Test(expected = AuthorizableTypeException.class) public void testCastAuthorizableToUser() throws Exception { UserUtil.castAuthorizable(Mockito.mock(Authorizable.class), User.class); }
@Test(expected = AuthorizableTypeException.class) public void testCastAuthorizableToGroup() throws Exception { UserUtil.castAuthorizable(Mockito.mock(Authorizable.class), Group.class); }
@Test public void testCastUserToUser() throws Exception { UserUtil.castAuthorizable(Mockito.mock(User.class), User.class); }
@Test public void testCastUserToAuthorizable() throws Exception { UserUtil.castAuthorizable(Mockito.mock(User.class), Authorizable.class); }
@Test public void testCastGroupToGroup() throws Exception { UserUtil.castAuthorizable(Mockito.mock(Group.class), Group.class); }
@Test public void testCastGroupToAuthorizable() throws Exception { UserUtil.castAuthorizable(Mockito.mock(Group.class), Authorizable.class); }