### Question:
PolicyExceptionMapper implements ExceptionMapper<TException> { @Override public final Response toResponse(TException exception) { if (exception instanceof NotFoundException) { return Response.status(Response.Status.NOT_FOUND).build(); } else if (noSessionIdInQueryStringOrPathParam() && inARequestWhereWeExpectContext()) { LOG.error(MessageFormat.format("No Session Id found for request to: {0}", httpServletRequest.getRequestURI()), exception); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } return handleException(exception); } PolicyExceptionMapper(); @Context void setUriInfo(UriInfo uriInfo); @Context void setHttpServletRequest(HttpServletRequest httpServletRequest); @Override final Response toResponse(TException exception);  }### Answer:
@Test public void shouldReturnInternalServerErrorWhenThereIsNoSessionIdAndTheRequestUriIsNotAKnownNoContextPath() { when(servletRequest.getParameter(Urls.SharedUrls.SESSION_ID_PARAM)).thenReturn(""); when(servletRequest.getParameter(Urls.SharedUrls.RELAY_STATE_PARAM)).thenReturn(""); when(uriInfo.getPathParameters()).thenReturn(new StringKeyIgnoreCaseMultivaluedMap<>()); String unknownUri = UUID.randomUUID().toString(); when(servletRequest.getRequestURI()).thenReturn(unknownUri); Response response = mapper.toResponse(new RuntimeException("We don't expect to see this message")); assertThat(response.getStatus()).isEqualTo(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); }
@Test public void shouldReturnResponseStatusOfNotFoundWhenANotFoundExceptionIsThrown() { Response response = mapper.toResponse(new NotFoundException()); assertThat(response.getStatus()).isEqualTo(Response.Status.NOT_FOUND.getStatusCode()); }