CandlepinExceptionMapper { protected ResponseBuilder getDefaultBuilder(Throwable exception, Status status) { return getDefaultBuilder(exception, status, determineBestMediaType()); }  MediaType determineBestMediaType();  }
@Test public void defaultBuilder() { IOException ioe = new IOException("fake io exception"); RuntimeException re = new RuntimeException("oops", ioe); ResponseBuilder bldr = cem.getDefaultBuilder(re, null, MediaType.APPLICATION_ATOM_XML_TYPE); Response r = bldr.build(); ExceptionMessage em = (ExceptionMessage) r.getEntity(); assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), r.getStatus()); assertEquals(MediaType.APPLICATION_ATOM_XML_TYPE, r.getMetadata().get("Content-Type").get(0)); assertTrue(em.getDisplayMessage().startsWith("Runtime Error " + re.getMessage())); }
@Test public void handleArrayIndexException() { Throwable nostack = mock(Throwable.class); when(nostack.getMessage()).thenReturn("no stack trace"); when(nostack.getStackTrace()).thenReturn(null); Response r = cem.getDefaultBuilder(nostack, null, MediaType.APPLICATION_JSON_TYPE).build(); ExceptionMessage em = (ExceptionMessage) r.getEntity(); assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), r.getStatus()); assertEquals("Runtime Error no stack trace", em.getDisplayMessage()); assertEquals(MediaType.APPLICATION_JSON_TYPE, r.getMetadata().get("Content-Type").get(0)); }