### Question:
OAuthASResponse extends OAuthResponse { public static OAuthAuthorizationResponseBuilder authorizationResponse(HttpServletRequest request,int code) { return new OAuthAuthorizationResponseBuilder(request,code); } protected  OAuthASResponse(String uri, int responseStatus); static OAuthAuthorizationResponseBuilder authorizationResponse(HttpServletRequest request,int code); static OAuthTokenResponseBuilder tokenResponse(int code);  }### Answer:
@Test public void testAuthzResponse() throws Exception { HttpServletRequest request = createMock(HttpServletRequest.class); OAuthResponse oAuthResponse = OAuthASResponse.authorizationResponse(request,200) .location("http: .setCode("code") .setState("ok") .setParam("testValue", "value2") .buildQueryMessage(); String url = oAuthResponse.getLocationUri(); assertEquals("http: assertEquals(200, oAuthResponse.getResponseStatus()); }
@Test public void testAuthzResponseWithState() throws Exception { HttpServletRequest request = createMock(HttpServletRequest.class); expect(request.getParameter(OAuth.OAUTH_STATE)).andStubReturn("ok"); replay(request); OAuthResponse oAuthResponse = OAuthASResponse.authorizationResponse(request,200) .location("http: .setCode("code") .setParam("testValue", "value2") .buildQueryMessage(); String url = oAuthResponse.getLocationUri(); assertEquals("http: assertEquals(200, oAuthResponse.getResponseStatus()); }
@Test public void testAuthzImplicitResponseWithState() throws Exception { HttpServletRequest request = createMock(HttpServletRequest.class); expect(request.getParameter(OAuth.OAUTH_STATE)).andStubReturn("ok"); replay(request); OAuthResponse oAuthResponse = OAuthASResponse.authorizationResponse(request, 200) .location("http: .setAccessToken("access_111") .setTokenType("bearer") .setExpiresIn("400") .setParam("testValue", "value2") .buildQueryMessage(); String url = oAuthResponse.getLocationUri(); assertEquals("http: assertEquals(200, oAuthResponse.getResponseStatus()); }
@Test public void testHeaderResponse() throws Exception { HttpServletRequest request = createMock(HttpServletRequest.class); OAuthResponse oAuthResponse = OAuthASResponse.authorizationResponse(request,400).setCode("oauth_code") .setState("state_ok") .buildHeaderMessage(); String header = oAuthResponse.getHeader(OAuth.HeaderType.WWW_AUTHENTICATE); assertEquals("Bearer code=\"oauth_code\",state=\"state_ok\"", header); header = oAuthResponse.getHeaders().get(OAuth.HeaderType.WWW_AUTHENTICATE); assertEquals("Bearer code=\"oauth_code\",state=\"state_ok\"", header); }