@Override public void oneDeclared() throws SomeCheckedException { try { methodThatThrowsUndeclaredChecked(); } catch (Throwable t) { Throwables.propagateIfPossible(t, SomeCheckedException.class); throw new SomeChainingException(t); } } };
@Override public void oneDeclared() throws SomeCheckedException { try { methodThatThrowsUnchecked(); } catch (Throwable t) { Throwables.propagateIfPossible(t, SomeCheckedException.class); throw new SomeChainingException(t); } } };
@Override public void noneDeclared() { try { methodThatThrowsUndeclaredChecked(); } catch (Throwable t) { Throwables.propagateIfPossible(t); throw new SomeChainingException(t); } } };
@Override public void twoDeclared() throws SomeCheckedException, SomeOtherCheckedException { try { methodThatThrowsOtherChecked(); } catch (Throwable t) { Throwables.propagateIfPossible(t, SomeCheckedException.class, SomeOtherCheckedException.class); throw new SomeChainingException(t); } } };
@Override public void noneDeclared() { try { methodThatThrowsUndeclaredChecked(); } catch (Throwable t) { Throwables.propagateIfPossible(t); throw new SomeChainingException(t); } } };
public void testGetRootCause_SingleWrapped() { SomeCheckedException cause = new SomeCheckedException(); SomeChainingException exception = new SomeChainingException(cause); assertSame(cause, Throwables.getRootCause(exception)); }
@Override public void twoDeclared() throws SomeCheckedException, SomeOtherCheckedException { try { methodThatThrowsUnchecked(); } catch (Throwable t) { Throwables.propagateIfPossible(t, SomeCheckedException.class, SomeOtherCheckedException.class); throw new SomeChainingException(t); } } };
@Override public void noneDeclared() { try { methodThatThrowsUnchecked(); } catch (Throwable t) { Throwables.propagateIfPossible(t); throw new SomeChainingException(t); } } };
@Override public void noneDeclared() { try { methodThatDoesntThrowAnything(); } catch (Throwable t) { Throwables.propagateIfPossible(t); throw new SomeChainingException(t); } } };
@GwtIncompatible // Throwables.getCauseAs(Throwable, Class) public void testGetCauseAs() { SomeCheckedException cause = new SomeCheckedException(); SomeChainingException thrown = new SomeChainingException(cause); assertThat(thrown).hasCauseThat().isSameAs(cause); assertThat(Throwables.getCauseAs(thrown, SomeCheckedException.class)).isSameAs(cause); assertThat(Throwables.getCauseAs(thrown, Exception.class)).isSameAs(cause); try { Throwables.getCauseAs(thrown, IllegalStateException.class); fail("Should have thrown CCE"); } catch (ClassCastException expected) { assertThat(expected).hasCauseThat().isSameAs(thrown); } }
public void testGetRootCause_DoubleWrapped() { SomeCheckedException cause = new SomeCheckedException(); SomeChainingException exception = new SomeChainingException(new SomeChainingException(cause)); assertSame(cause, Throwables.getRootCause(exception)); }
@Override public void twoDeclared() throws SomeCheckedException, SomeOtherCheckedException { try { methodThatThrowsUnchecked(); } catch (Throwable t) { Throwables.propagateIfPossible( t, SomeCheckedException.class, SomeOtherCheckedException.class); throw new SomeChainingException(t); } } };
@Override public void twoDeclared() throws SomeCheckedException, SomeOtherCheckedException { try { methodThatDoesntThrowAnything(); } catch (Throwable t) { Throwables.propagateIfPossible( t, SomeCheckedException.class, SomeOtherCheckedException.class); throw new SomeChainingException(t); } } };
@Override public void oneDeclared() throws SomeCheckedException { try { methodThatThrowsChecked(); } catch (Throwable t) { Throwables.propagateIfPossible(t, SomeCheckedException.class); throw new SomeChainingException(t); } } };
@Override public void oneDeclared() throws SomeCheckedException { try { methodThatDoesntThrowAnything(); } catch (Throwable t) { // yes, this block is never reached, but for purposes of illustration // we're keeping it the same in each test Throwables.propagateIfPossible(t, SomeCheckedException.class); throw new SomeChainingException(t); } } };
@Override public void noneDeclared() { try { methodThatThrowsUnchecked(); } catch (Throwable t) { Throwables.propagateIfPossible(t); throw new SomeChainingException(t); } } };
@Override public void noneDeclared() { try { methodThatDoesntThrowAnything(); } catch (Throwable t) { Throwables.propagateIfPossible(t); throw new SomeChainingException(t); } } };
public void testGetRootCause_SingleWrapped() { SomeCheckedException cause = new SomeCheckedException(); SomeChainingException exception = new SomeChainingException(cause); assertSame(cause, Throwables.getRootCause(exception)); }
@Override public void twoDeclared() throws SomeCheckedException, SomeOtherCheckedException { try { methodThatThrowsOtherChecked(); } catch (Throwable t) { Throwables.propagateIfPossible( t, SomeCheckedException.class, SomeOtherCheckedException.class); throw new SomeChainingException(t); } } };
@Override public void twoDeclared() throws SomeCheckedException, SomeOtherCheckedException { try { methodThatThrowsChecked(); } catch (Throwable t) { Throwables.propagateIfPossible( t, SomeCheckedException.class, SomeOtherCheckedException.class); throw new SomeChainingException(t); } } };