### Question:
ExceptionUtils { public static <T extends Throwable> Response convertFaultToResponse(T ex, Message currentMessage) { if (ex == null || currentMessage == null) { return null; } Message inMessage = currentMessage.getExchange().getInMessage(); Response response = null; if (ex instanceof WebApplicationException) { WebApplicationException webEx = (WebApplicationException)ex; if (webEx.getResponse().hasEntity() && webEx.getCause() == null && MessageUtils.getContextualBoolean(inMessage, SUPPORT_WAE_SPEC_OPTIMIZATION, true)) { response = webEx.getResponse(); } } if (response == null) { ExceptionMapper<T> mapper = ServerProviderFactory.getInstance(inMessage).createExceptionMapper(ex.getClass(), inMessage); if (mapper != null) { try { response = mapper.toResponse(ex); } catch (Throwable mapperEx) { inMessage.getExchange().put(JAXRSUtils.EXCEPTION_FROM_MAPPER, "true"); mapperEx.printStackTrace(); return Response.serverError().build(); } } } if (response == null) { Throwable unwrappedException = ex.getCause(); if (unwrappedException instanceof WebApplicationException) { WebApplicationException webEx = (WebApplicationException)unwrappedException; response = webEx.getResponse(); } } JAXRSUtils.setMessageContentType(currentMessage, response); return response; } private  ExceptionUtils(); static String getStackTrace(Throwable ex); static Class<?> getWebApplicationExceptionClass(Response exResponse,
                                                           Class<?> defaultExceptionType); static boolean propogateException(Message m); static Response convertFaultToResponse(T ex, Message currentMessage); static WebApplicationException toWebApplicationException(Throwable cause, Response response); static WebApplicationException toInternalServerErrorException(Throwable cause, Response response); static WebApplicationException toBadRequestException(Throwable cause, Response response); static WebApplicationException toNotFoundException(Throwable cause, Response response); static WebApplicationException toNotAuthorizedException(Throwable cause, Response response); static WebApplicationException toForbiddenException(Throwable cause, Response response); static WebApplicationException toNotAcceptableException(Throwable cause, Response response); static WebApplicationException toNotSupportedException(Throwable cause, Response response); static WebApplicationException toHttpException(Throwable cause, Response response); static WebApplicationException toWebApplicationException(Response response);  }### Answer:
@Test public void testConvertFaultToResponseWAEWithResponse() { Message m = createMessage(); WebApplicationException wae = new WebApplicationException(Response.ok("_fromWAE_", MediaType.TEXT_PLAIN_TYPE).build()); Response r = ExceptionUtils.convertFaultToResponse(wae, m); assertEquals(200, r.getStatus()); assertEquals(MediaType.TEXT_PLAIN_TYPE, r.getMediaType()); assertEquals("_fromWAE_", r.readEntity(String.class)); }
@Test public void testConvertFaultToResponseWAESubClassWithResponse() { Message m = createMessage(); BadRequestException wae = new BadRequestException(Response.status(400) .type(MediaType.TEXT_HTML) .entity("<em>fromBRE</em>") .build()); Response r = ExceptionUtils.convertFaultToResponse(wae, m); assertEquals(400, r.getStatus()); assertEquals(MediaType.TEXT_HTML_TYPE, r.getMediaType()); assertEquals("<em>fromBRE</em>", r.readEntity(String.class)); }