### Question:
AuthenticationServiceV1 { @Post public Response authenticate(@Contextual Context context, @Contextual Request httpRequest) { if (!isSupportedMediaType(httpRequest)) { if (DEBUG.errorEnabled()) { DEBUG.error("AuthenticationService :: Unable to handle media type request : " + ContentTypeHeader.valueOf(httpRequest).getType()); } return handleErrorResponse(httpRequest, Status.UNSUPPORTED_MEDIA_TYPE, null); } final HttpServletResponse response = getHttpServletResponse(context); Form urlQueryString = getUrlQueryString(httpRequest); final String sessionUpgradeSSOTokenId = urlQueryString.getFirst("sessionUpgradeSSOTokenId"); try { if (!StringUtils.isEmpty(sessionUpgradeSSOTokenId)) { SSOTokenManager.getInstance().createSSOToken(sessionUpgradeSSOTokenId); } JsonValue jsonContent; try { jsonContent = getJsonContent(httpRequest); } catch (IOException e) { DEBUG.message("AuthenticationService.authenticate() :: JSON parsing error", e); return handleErrorResponse(httpRequest, Status.BAD_REQUEST, e); } final HttpServletRequest request = getHttpServletRequest(context, jsonContent); JsonValue jsonResponse; if (jsonContent != null && jsonContent.size() > 0) { jsonResponse = restAuthenticationHandler.continueAuthentication(request, response, jsonContent, sessionUpgradeSSOTokenId); } else { final String authIndexType = urlQueryString.getFirst("authIndexType"); final String authIndexValue = urlQueryString.getFirst("authIndexValue"); jsonResponse = restAuthenticationHandler.initiateAuthentication(request, response, authIndexType, authIndexValue, sessionUpgradeSSOTokenId); } return createResponse(jsonResponse); } catch (RestAuthResponseException e) { DEBUG.message("AuthenticationService.authenticate() :: Exception from CallbackHandler", e); return handleErrorResponse(httpRequest, Status.valueOf(e.getStatusCode()), e); } catch (RestAuthException e) { DEBUG.message("AuthenticationService.authenticate() :: Rest Authentication Exception", e); return handleErrorResponse(httpRequest, Status.valueOf(e.getStatusCode()), e); } catch (SSOException e) { return handleErrorResponse(httpRequest, Status.BAD_REQUEST, e); } catch (IOException e) { DEBUG.error("AuthenticationService.authenticate() :: Internal Error", e); return handleErrorResponse(httpRequest, Status.INTERNAL_SERVER_ERROR, e); } } @Inject  AuthenticationServiceV1(RestAuthenticationHandler restAuthenticationHandler); @Post Response authenticate(@Contextual Context context, @Contextual Request httpRequest);  }### Answer:
@Test public void shouldFailAuthenticationWithUnsupportedMediaTypeMessage() throws IOException { AttributesContext context = new AttributesContext(new SessionContext(new RootContext(), mock(Session.class))); Request httpRequest = new Request(); httpRequest.setEntity("<xml></xml>"); httpRequest.getHeaders().put(ContentTypeHeader.NAME, "application/xml"); Response response = authServiceV1.authenticate(context, httpRequest); assertThat(response.getStatus()).isEqualTo(Status.UNSUPPORTED_MEDIA_TYPE); assertThat(json(response.getEntity().getJson())).stringAt("errorMessage").isEqualTo("Unsupported Media Type"); }