### Question:
ClassResourceImpl extends XWikiResource implements ClassResource { @Override public Class getClass(String wikiName, String className) throws XWikiRestException { String database = Utils.getXWikiContext(componentManager).getWikiId(); try { Utils.getXWikiContext(componentManager).setWikiId(wikiName); DocumentReference classReference = this.resolver.resolve(className, new WikiReference(wikiName)); this.authorization.checkAccess(Right.VIEW, classReference); com.xpn.xwiki.api.Class xwikiClass = Utils.getXWikiApi(componentManager).getClass(classReference); if (xwikiClass == null) { throw new WebApplicationException(Status.NOT_FOUND); } return this.utils.toRestClass(uriInfo.getBaseUri(), xwikiClass); } catch (XWikiException e) { throw new XWikiRestException(e); } catch (AccessDeniedException e) { throw new WebApplicationException(e, Status.UNAUTHORIZED); } finally { Utils.getXWikiContext(componentManager).setWikiId(database); } }  @Override Class getClass(String wikiName, String className);  }### Answer:
@Test public void authorizedClassesOnly() throws XWikiRestException, AccessDeniedException { DocumentReference protectedReference = new DocumentReference("xwiki", "XWiki", "Protected"); doThrow(new AccessDeniedException(xcontext.getUserReference(), protectedReference)).when( authorization).checkAccess(eq(Right.VIEW), eq(protectedReference)); String protectedClass = "XWiki.Protected"; for (String availableClass : availableClasses) { try { Class aClass = resource.getClass("xwiki", availableClass); if (availableClass.equals(protectedClass)) { fail(); } else { assertEquals(availableClass, aClass.getId()); } } catch (WebApplicationException e) { if (availableClass.equals(protectedClass)) { assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), e.getResponse().getStatus()); } else { throw e; } } } }