public void testGetRootCause_Loop() { Exception cause = new Exception(); Exception exception = new Exception(cause); cause.initCause(exception); try { Throwables.getRootCause(cause); fail("Should have throw IAE"); } catch (IllegalArgumentException expected) { assertThat(expected).hasCauseThat().isSameAs(cause); } }
public void testGetCasualChainLoop() { Exception cause = new Exception(); Exception exception = new Exception(cause); cause.initCause(exception); try { Throwables.getCausalChain(cause); fail("Should have throw IAE"); } catch (IllegalArgumentException expected) { assertThat(expected).hasCauseThat().isSameAs(cause); } }
public void testGetCheckedUntimed_ExecutionExceptionChecked() { try { getChecked(FAILED_FUTURE_CHECKED_EXCEPTION, TwoArgConstructorException.class); fail(); } catch (TwoArgConstructorException expected) { assertThat(expected).hasCauseThat().isEqualTo(CHECKED_EXCEPTION); } }
public void testGetCheckedTimed_withGoodAndBadExceptionConstructor() { try { getChecked( FAILED_FUTURE_CHECKED_EXCEPTION, ExceptionWithGoodAndBadConstructor.class, 1, TimeUnit.SECONDS); fail(); } catch (ExceptionWithGoodAndBadConstructor expected) { assertThat(expected).hasCauseThat().isSameAs(CHECKED_EXCEPTION); } }
public void testGetCheckedTimed_ExecutionExceptionChecked() { try { getChecked(FAILED_FUTURE_CHECKED_EXCEPTION, TwoArgConstructorException.class, 0, SECONDS); fail(); } catch (TwoArgConstructorException expected) { assertThat(expected).hasCauseThat().isEqualTo(CHECKED_EXCEPTION); } }
public void testGetCheckedUntimed_ExecutionExceptionUnchecked() throws TwoArgConstructorException { try { getChecked(FAILED_FUTURE_UNCHECKED_EXCEPTION, TwoArgConstructorException.class); fail(); } catch (UncheckedExecutionException expected) { assertThat(expected).hasCauseThat().isEqualTo(UNCHECKED_EXCEPTION); } }
public void testGetCheckedUntimed_ExecutionExceptionError() throws TwoArgConstructorException { try { getChecked(FAILED_FUTURE_ERROR, TwoArgConstructorException.class); fail(); } catch (ExecutionError expected) { assertThat(expected).hasCauseThat().isEqualTo(ERROR); } }
public void testGetCheckedTimed_ExecutionExceptionOtherThrowable() { try { getChecked(FAILED_FUTURE_OTHER_THROWABLE, TwoArgConstructorException.class, 0, SECONDS); fail(); } catch (TwoArgConstructorException expected) { assertThat(expected).hasCauseThat().isEqualTo(OTHER_THROWABLE); } }
public void testGetCheckedUntimed_ExecutionExceptionOtherThrowable() { try { getChecked(FAILED_FUTURE_OTHER_THROWABLE, TwoArgConstructorException.class); fail(); } catch (TwoArgConstructorException expected) { assertThat(expected).hasCauseThat().isEqualTo(OTHER_THROWABLE); } }
public void testGetCheckedUntimed_withGoodAndBadExceptionConstructor() throws Exception { try { getChecked(FAILED_FUTURE_CHECKED_EXCEPTION, ExceptionWithGoodAndBadConstructor.class); fail(); } catch (ExceptionWithGoodAndBadConstructor expected) { assertThat(expected).hasCauseThat().isSameAs(CHECKED_EXCEPTION); } }
public void testFailed() { Exception failureCause = new Exception(); try { getDone(immediateFailedFuture(failureCause)); fail(); } catch (ExecutionException expected) { assertThat(expected).hasCauseThat().isEqualTo(failureCause); } }
public void testGetCheckedUntimed_exceptionClassUsedInitCause() { try { getChecked(FAILED_FUTURE_CHECKED_EXCEPTION, ExceptionWithoutThrowableConstructor.class); fail(); } catch (ExceptionWithoutThrowableConstructor expected) { assertThat(expected).hasMessageThat().contains("mymessage"); assertThat(expected).hasCauseThat().isEqualTo(CHECKED_EXCEPTION); } }
public void testNewDataInput_readFullyAndThenSome() { ByteArrayDataInput in = ByteStreams.newDataInput(bytes); byte[] actual = new byte[bytes.length * 2]; try { in.readFully(actual); fail("expected exception"); } catch (IllegalStateException ex) { assertThat(ex).hasCauseThat().isInstanceOf(EOFException.class); } }
/** * This test reproduces the bug in canonicalizeWildcardType() when the type variable is * recursively bounded. */ public void testRecursiveWildcardSubtypeBug() throws Exception { try { new RecursiveTypeBoundBugExample<>().testAllDeclarations(); fail(); } catch (Exception e) { assertThat(e).hasCauseThat().isInstanceOf(AssertionError.class); } }
public void testInvokeSubscriberMethod_exceptionWrapping() throws Throwable { Method method = getTestSubscriberMethod("exceptionThrowingMethod"); Subscriber subscriber = Subscriber.create(bus, this, method); try { subscriber.invokeSubscriberMethod(FIXTURE_ARGUMENT); fail("Subscribers whose methods throw must throw InvocationTargetException"); } catch (InvocationTargetException expected) { assertThat(expected).hasCauseThat().isInstanceOf(IntentionalException.class); } }
public void testNewDataInput_readByte() { ByteArrayDataInput in = ByteStreams.newDataInput(bytes); for (int i = 0; i < bytes.length; i++) { assertEquals(bytes[i], in.readByte()); } try { in.readByte(); fail("expected exception"); } catch (IllegalStateException ex) { assertThat(ex).hasCauseThat().isInstanceOf(EOFException.class); } }
public void testNewDataInput_readUnsignedByte() { ByteArrayDataInput in = ByteStreams.newDataInput(bytes); for (int i = 0; i < bytes.length; i++) { assertEquals(bytes[i], in.readUnsignedByte()); } try { in.readUnsignedByte(); fail("expected exception"); } catch (IllegalStateException ex) { assertThat(ex).hasCauseThat().isInstanceOf(EOFException.class); } }
@Override public void testNulls() throws Exception { try { super.testNulls(); } catch (AssertionFailedError e) { assertWithMessage("Method did not throw null pointer OR element not in graph exception.") .that(e) .hasCauseThat() .hasMessageThat() .contains(ERROR_ELEMENT_NOT_IN_GRAPH); } }
public void testFailingServiceStartAndWait() throws Exception { StartFailingService service = new StartFailingService(); RecordingListener listener = RecordingListener.record(service); try { service.startAsync().awaitRunning(); fail(); } catch (IllegalStateException e) { assertEquals(EXCEPTION, service.failureCause()); assertThat(e).hasCauseThat().isEqualTo(EXCEPTION); } assertEquals(ImmutableList.of(State.STARTING, State.FAILED), listener.getStateHistory()); }
public void testThrowingServiceStartAndWait() throws Exception { StartThrowingService service = new StartThrowingService(); RecordingListener listener = RecordingListener.record(service); try { service.startAsync().awaitRunning(); fail(); } catch (IllegalStateException e) { assertEquals(service.exception, service.failureCause()); assertThat(e).hasCauseThat().isEqualTo(service.exception); } assertEquals(ImmutableList.of(State.STARTING, State.FAILED), listener.getStateHistory()); }