本文整理了Java中com.google.common.truth.ThrowableSubject.isEqualTo()
方法的一些代码示例,展示了ThrowableSubject.isEqualTo()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ThrowableSubject.isEqualTo()
方法的具体详情如下:
包路径:com.google.common.truth.ThrowableSubject
类名称:ThrowableSubject
方法名:isEqualTo
暂无
代码示例来源:origin: google/guava
public void testTrustedGetFailure_Failed() {
SettableFuture<String> future = SettableFuture.create();
Throwable failure = new Throwable();
future.setException(failure);
assertThat(future.tryInternalFastPathGetFailure()).isEqualTo(failure);
}
代码示例来源:origin: google/guava
public void testGetCheckedUntimed_ExecutionExceptionChecked() {
try {
getChecked(FAILED_FUTURE_CHECKED_EXCEPTION, TwoArgConstructorException.class);
fail();
} catch (TwoArgConstructorException expected) {
assertThat(expected).hasCauseThat().isEqualTo(CHECKED_EXCEPTION);
}
}
代码示例来源:origin: google/guava
public void testGetCheckedTimed_ExecutionExceptionChecked() {
try {
getChecked(FAILED_FUTURE_CHECKED_EXCEPTION, TwoArgConstructorException.class, 0, SECONDS);
fail();
} catch (TwoArgConstructorException expected) {
assertThat(expected).hasCauseThat().isEqualTo(CHECKED_EXCEPTION);
}
}
代码示例来源:origin: google/guava
public void testRunWithTimeout_wrapsUncheckedException() throws Exception {
RuntimeException exception = new RuntimeException("test");
try {
timeLimiter.runWithTimeout(runnableThrowing(exception), DELAY_MS, TimeUnit.MILLISECONDS);
fail("Expected UncheckedExecutionException");
} catch (UncheckedExecutionException e) {
assertThat(e.getCause()).isEqualTo(exception);
}
}
代码示例来源:origin: google/guava
public void testGetCheckedUntimed_ExecutionExceptionUnchecked()
throws TwoArgConstructorException {
try {
getChecked(FAILED_FUTURE_UNCHECKED_EXCEPTION, TwoArgConstructorException.class);
fail();
} catch (UncheckedExecutionException expected) {
assertThat(expected).hasCauseThat().isEqualTo(UNCHECKED_EXCEPTION);
}
}
代码示例来源:origin: google/guava
public void testGetCheckedUntimed_ExecutionExceptionOtherThrowable() {
try {
getChecked(FAILED_FUTURE_OTHER_THROWABLE, TwoArgConstructorException.class);
fail();
} catch (TwoArgConstructorException expected) {
assertThat(expected).hasCauseThat().isEqualTo(OTHER_THROWABLE);
}
}
代码示例来源:origin: google/guava
public void testGetCheckedTimed_ExecutionExceptionUnchecked() throws TwoArgConstructorException {
try {
getChecked(FAILED_FUTURE_UNCHECKED_EXCEPTION, TwoArgConstructorException.class, 0, SECONDS);
fail();
} catch (UncheckedExecutionException expected) {
assertThat(expected).hasCauseThat().isEqualTo(UNCHECKED_EXCEPTION);
}
}
代码示例来源:origin: google/guava
public void testGetCheckedTimed_ExecutionExceptionError() throws TwoArgConstructorException {
try {
getChecked(FAILED_FUTURE_ERROR, TwoArgConstructorException.class, 0, SECONDS);
fail();
} catch (ExecutionError expected) {
assertThat(expected).hasCauseThat().isEqualTo(ERROR);
}
}
代码示例来源:origin: google/guava
public void testGetCheckedUntimed_ExecutionExceptionError() throws TwoArgConstructorException {
try {
getChecked(FAILED_FUTURE_ERROR, TwoArgConstructorException.class);
fail();
} catch (ExecutionError expected) {
assertThat(expected).hasCauseThat().isEqualTo(ERROR);
}
}
代码示例来源:origin: google/guava
public void testGetCheckedTimed_ExecutionExceptionOtherThrowable() {
try {
getChecked(FAILED_FUTURE_OTHER_THROWABLE, TwoArgConstructorException.class, 0, SECONDS);
fail();
} catch (TwoArgConstructorException expected) {
assertThat(expected).hasCauseThat().isEqualTo(OTHER_THROWABLE);
}
}
代码示例来源:origin: google/guava
public void testCallWithTimeout_wrapsCheckedException() throws Exception {
Exception exception = new SampleCheckedException();
try {
timeLimiter.callWithTimeout(callableThrowing(exception), DELAY_MS, TimeUnit.MILLISECONDS);
fail("Expected ExecutionException");
} catch (ExecutionException e) {
assertThat(e.getCause()).isEqualTo(exception);
}
}
代码示例来源:origin: google/guava
public void testCallWithTimeout_wrapsUncheckedException() throws Exception {
Exception exception = new RuntimeException("test");
try {
timeLimiter.callWithTimeout(callableThrowing(exception), DELAY_MS, TimeUnit.MILLISECONDS);
fail("Expected UncheckedExecutionException");
} catch (UncheckedExecutionException e) {
assertThat(e.getCause()).isEqualTo(exception);
}
}
代码示例来源:origin: google/guava
public void testRunUninterruptiblyWithTimeout_wrapsUncheckedException() throws Exception {
RuntimeException exception = new RuntimeException("test");
try {
timeLimiter.runUninterruptiblyWithTimeout(
runnableThrowing(exception), DELAY_MS, TimeUnit.MILLISECONDS);
fail("Expected UncheckedExecutionException");
} catch (UncheckedExecutionException e) {
assertThat(e.getCause()).isEqualTo(exception);
}
}
代码示例来源:origin: google/guava
public void testFailed() {
Exception failureCause = new Exception();
try {
getDone(immediateFailedFuture(failureCause));
fail();
} catch (ExecutionException expected) {
assertThat(expected).hasCauseThat().isEqualTo(failureCause);
}
}
代码示例来源:origin: google/guava
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);
}
}
代码示例来源:origin: google/guava
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());
}
代码示例来源:origin: google/guava
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());
}
代码示例来源:origin: google/guava
public void testThrowingServiceStopAndWait_runThrowing() throws Exception {
RunThrowingService service = new RunThrowingService();
RecordingListener listener = RecordingListener.record(service);
service.startAsync();
try {
service.awaitTerminated();
fail();
} catch (IllegalStateException e) {
assertEquals(service.exception, service.failureCause());
assertThat(e).hasCauseThat().isEqualTo(service.exception);
}
assertEquals(
ImmutableList.of(State.STARTING, State.RUNNING, State.FAILED), listener.getStateHistory());
}
代码示例来源:origin: google/guava
public void testFailingServiceStopAndWait_runFailing() throws Exception {
RunFailingService service = new RunFailingService();
RecordingListener listener = RecordingListener.record(service);
service.startAsync();
try {
service.awaitRunning();
fail();
} catch (IllegalStateException e) {
assertEquals(EXCEPTION, service.failureCause());
assertThat(e).hasCauseThat().isEqualTo(EXCEPTION);
}
assertEquals(
ImmutableList.of(State.STARTING, State.RUNNING, State.FAILED), listener.getStateHistory());
}
代码示例来源:origin: google/guava
public void testServiceThrowOnRun() throws Exception {
ThrowOnRunService service = new ThrowOnRunService();
service.startAsync();
try {
service.awaitTerminated();
fail();
} catch (IllegalStateException expected) {
executionThread.join();
assertThat(expected).hasCauseThat().isEqualTo(service.failureCause());
assertThat(expected).hasCauseThat().hasMessageThat().isEqualTo("kaboom!");
}
assertTrue(service.shutDownCalled);
assertEquals(Service.State.FAILED, service.state());
}
内容来源于网络,如有侵权,请联系作者删除!