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