### Question:
JaxRsExceptionInterceptor { @AroundInvoke public Object intercept(final InvocationContext ctx) throws JaxRsResponseException { try { return ctx.proceed(); } catch (final Exception theException) { final AbstractJaxRsProvider theServer = (AbstractJaxRsProvider) ctx.getTarget(); throw convertException(theServer, theException); } } JaxRsExceptionInterceptor();   JaxRsExceptionInterceptor(final ExceptionHandlingInterceptor exceptionHandler); @AroundInvoke Object intercept(final InvocationContext ctx); JaxRsResponseException convertException(final AbstractJaxRsProvider theServer, final Throwable theException); Response convertExceptionIntoResponse(final JaxRsRequest theRequest, final JaxRsResponseException theException);  }### Answer:
@Test public void testInterceptWithBaseServerError() throws Throwable { NotImplementedOperationException thrownException = new NotImplementedOperationException("not implemented"); when(context.proceed()).thenThrow(thrownException); try { interceptor.intercept(context); fail(); } catch (BaseServerResponseException e) { assertEquals(e.getMessage(), thrownException.getMessage()); } }
@Test public void testIntercepWithServletError() throws Throwable { ExceptionHandlingInterceptor exceptionHandler = mock(ExceptionHandlingInterceptor.class); when(exceptionHandler.preProcessOutgoingException(any(RequestDetails.class), any(Throwable.class), isNull(HttpServletRequest.class))).thenThrow(new ServletException("someMessage")); interceptor = new JaxRsExceptionInterceptor(exceptionHandler); when(context.proceed()).thenThrow(new ServletException()); try { interceptor.intercept(context); fail(); } catch (BaseServerResponseException e) { assertTrue(e.getMessage().contains("someMessage")); } }
@Test public void testInterceptServletWithoutError() throws Throwable { Object expected = new Object(); when(context.proceed()).thenReturn(expected); Object result = interceptor.intercept(context); assertSame(expected, result); }