### Question:
IndexingUtils { public static boolean isAuthorized(UserRegistry registry, String resourcePath, String action) throws RegistryException{ UserRealm userRealm = registry.getUserRealm(); String userName = registry.getUserName(); try { if (!userRealm.getAuthorizationManager().isUserAuthorized(userName, resourcePath, action)) { return false; } } catch (UserStoreException e) { throw new RegistryException("Error at Authorizing " + resourcePath + " with user " + userName + ":" + e.getMessage(), e); } return true; }  static boolean isAuthorized(UserRegistry registry, String resourcePath, String action); static byte[] readBytesFromInputSteam(InputStream in); static byte[] getByteContent(Resource resource, String sourceURL); static String getLoggedInUserName();  }### Answer:
@Test public void isAuthorized() throws Exception { UserRegistry registry = mock(UserRegistry.class); AuthorizationManager authManager = mock(AuthorizationManager.class); when(authManager.isUserAuthorized("admin", "/_system/governance/trunk/api/test", ActionConstants .GET)).thenReturn(Boolean.TRUE); RegistryRealm registryRealm = PowerMockito.mock(RegistryRealm.class); when(registryRealm.getAuthorizationManager()).thenReturn(authManager); when(registry.getUserRealm()).thenReturn(registryRealm); when(registry.getUserName()).thenReturn("admin"); assertTrue(IndexingUtils.isAuthorized(registry, "/_system/governance/trunk/api/test", ActionConstants .GET)); assertFalse(IndexingUtils.isAuthorized(registry, "/_system/governance/trunk/api/test1", ActionConstants .GET)); assertFalse(IndexingUtils.isAuthorized(registry, "/_system/governance/trunk/api/test", ActionConstants.PUT)); assertFalse(IndexingUtils.isAuthorized(registry, null, ActionConstants.PUT)); }