ResourceContext { public Principal authenticate() { return authenticate(false); } ResourceContext(HttpServletRequest request, HttpServletResponse response,
            Http.AuthorityList authorities, Authorizer authorizer); static void setSendMultipleWwwAuthenticateHeaders(boolean bSendMultipleHeaders); HttpServletRequest request(); HttpServletResponse response(); Principal principal(); Principal authenticate(); Principal authenticate(boolean optionalAuth); void authorize(String action, String resource, String trustedDomain); void sendAuthenticateChallenges(ResourceException exc); String getRequestDomain(); void setRequestDomain(String requestDomain);  }
@Test public void testAuthenticate() { HttpServletRequest httpServletRequest = Mockito.mock(HttpServletRequest.class); HttpServletResponse httpServletResponse = Mockito.mock(HttpServletResponse.class); Authorizer authorizer = Mockito.mock(Authorizer.class); Http.AuthorityList authorities = new Http.AuthorityList(); ResourceContext context = new ResourceContext(httpServletRequest, httpServletResponse, authorities, authorizer); context.checked = true; assertNull(context.authenticate()); }
@Test public void testAuthenticateOptionalAuth() { HttpServletRequest httpServletRequest = Mockito.mock(HttpServletRequest.class); HttpServletResponse httpServletResponse = Mockito.mock(HttpServletResponse.class); Authorizer authorizer = Mockito.mock(Authorizer.class); Http.AuthorityList authorities = new Http.AuthorityList(); ResourceContext context = new ResourceContext(httpServletRequest, httpServletResponse, authorities, authorizer); assertNull(context.authenticate(true)); context.checked = false; try { context.authenticate(false); fail(); } catch (ResourceException ex) { assertEquals(ex.getCode(), ResourceException.UNAUTHORIZED); } }