JAXBMarshalExceptionMapper extends CandlepinExceptionMapper implements ExceptionMapper<JAXBMarshalException> { @Override public Response toResponse(JAXBMarshalException exception) { Status status = Response.Status.INTERNAL_SERVER_ERROR; if (exception.getResponse() != null) { status = Response.Status.fromStatusCode( exception.getResponse().getStatus()); } return getDefaultBuilder(exception, status, determineBestMediaType()).build(); }  @Override Response toResponse(JAXBMarshalException exception);  }
@Test public void handleExceptionWithoutResponse() { JAXBMarshalException nfe = new JAXBMarshalException("unacceptable"); JAXBMarshalExceptionMapper nfem = injector.getInstance(JAXBMarshalExceptionMapper.class); Response r = nfem.toResponse(nfe); assertEquals(500, r.getStatus()); verifyMessage(r, rtmsg("unacceptable")); }
@Test public void handleExceptionWithResponse() { Response mockr = mock(Response.class); when(mockr.getStatus()).thenReturn(500); JAXBMarshalException nfe = new JAXBMarshalException("unacceptable", mockr); JAXBMarshalExceptionMapper nfem = injector.getInstance(JAXBMarshalExceptionMapper.class); Response r = nfem.toResponse(nfe); assertEquals(500, r.getStatus()); verifyMessage(r, rtmsg("unacceptable")); }