CRestException extends RuntimeException { public static RuntimeException handle(Throwable e) { if (e instanceof CRestException) { return handle((CRestException) e); }else if (e instanceof RequestException) { return handle((RequestException) e); } else if (e instanceof IllegalArgumentException) { return handle((IllegalArgumentException) e); } else if (e instanceof IllegalStateException) { return handle((IllegalStateException) e); } else if (e instanceof InvocationTargetException) { return handle((InvocationTargetException) e); } else { return new CRestException(e.getMessage(), e); } } CRestException();  CRestException(String message);  CRestException(String message, Throwable cause); static RuntimeException handle(Throwable e); static RuntimeException handle(CRestException e); static RuntimeException handle(RequestException e); static RuntimeException handle(IllegalArgumentException e); static RuntimeException handle(IllegalStateException e); static RuntimeException handle(InvocationTargetException e);  }
@Test public void handleAnyExceptionShouldWrapItInCRestException(){ Throwable e = new Throwable("msg"); RuntimeException actual = CRestException.handle(e); assertEquals(CRestException.class, actual.getClass()); assertSame(e, actual.getCause()); assertSame("msg", actual.getMessage()); }
@Test public void handleCRestExceptionShouldReturnIt(){ CRestException e = new CRestException(); assertSame(e, CRestException.handle(e)); }
@Test public void handleCRestExceptionThrowableShouldReturnIt(){ Throwable e = new CRestException(); assertSame(e, CRestException.handle(e)); }
@Test public void handleRequestExceptionWithCauseShouldHandleIt(){ CRestException cause = new CRestException(); RequestException e = new RequestException(cause); assertSame(cause, CRestException.handle(e)); }
@Test public void handleRequestExceptionThrowableWithCauseShouldHandleIt(){ CRestException cause = new CRestException(); Throwable e = new RequestException(cause); assertSame(cause, CRestException.handle(e)); }
@Test public void handleRequestExceptionWithoutCauseShouldReturnIt(){ RequestException e = new RequestException("msg", null); RuntimeException actual = CRestException.handle(e); assertEquals(CRestException.class, actual.getClass()); assertSame(e, actual.getCause()); assertSame("msg", actual.getMessage()); }
@Test public void handleRequestExceptionThrowableWithoutCauseShouldReturnIt(){ Throwable e = new RequestException("msg", null); RuntimeException actual = CRestException.handle(e); assertEquals(CRestException.class, actual.getClass()); assertSame(e, actual.getCause()); assertSame("msg", actual.getMessage()); }
@Test public void handleIllegalArgumentExceptionShouldReturnIt(){ IllegalArgumentException e = new IllegalArgumentException(); assertSame(e, CRestException.handle(e)); }
@Test public void handleIllegalArgumentExceptionThrowableShouldReturnIt(){ Throwable e = new IllegalArgumentException(); assertSame(e, CRestException.handle(e)); }
@Test public void handleIllegalStateExceptionShouldReturnIt(){ IllegalStateException e = new IllegalStateException(); assertSame(e, CRestException.handle(e)); }
@Test public void handleIllegalStateExceptionThrowableShouldReturnIt(){ Throwable e = new IllegalStateException(); assertSame(e, CRestException.handle(e)); }
@Test public void handleInvocationTargetExceptionShouldHandleCause(){ CRestException expected = new CRestException(); RequestException cause = new RequestException(expected); InvocationTargetException e = new InvocationTargetException(cause); assertSame(expected, CRestException.handle(e)); }
@Test public void handleInvocationTargetExceptionThrowableShouldHandleCause(){ CRestException expected = new CRestException(); RequestException cause = new RequestException(expected); Throwable e = new InvocationTargetException(cause); assertSame(expected, CRestException.handle(e)); }