本文整理了Java中com.google.common.truth.ThrowableSubject.isSameAs()
方法的一些代码示例,展示了ThrowableSubject.isSameAs()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ThrowableSubject.isSameAs()
方法的具体详情如下:
包路径:com.google.common.truth.ThrowableSubject
类名称:ThrowableSubject
方法名:isSameAs
暂无
代码示例来源:origin: google/guava
@Override
public ListenableFuture<Integer> apply(Throwable t) throws Exception {
assertThat(t).isSameAs(raisedException);
return secondary;
}
});
代码示例来源:origin: google/guava
@Override
public Integer apply(Throwable t) {
assertThat(t).isSameAs(raisedException);
return 20;
}
});
代码示例来源:origin: google/guava
@Override
public ListenableFuture<Integer> apply(Throwable t) throws Exception {
assertThat(t).isSameAs(raisedException);
return immediateFuture(20);
}
});
代码示例来源:origin: google/guava
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);
}
}
代码示例来源:origin: google/guava
private static void assertExecutionException(Future<?> future, Exception expectedCause)
throws Exception {
try {
future.get();
fail("Expected ExecutionException");
} catch (ExecutionException e) {
assertThat(e).hasCauseThat().isSameAs(expectedCause);
}
}
代码示例来源:origin: google/guava
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);
}
}
代码示例来源:origin: google/guava
private void checkLoggedCause(Throwable t) {
assertThat(popLoggedThrowable()).hasCauseThat().isSameAs(t);
}
代码示例来源:origin: google/guava
@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);
}
}
代码示例来源:origin: google/guava
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);
}
}
代码示例来源:origin: google/guava
public void testGetCheckedUntimed_withGoodAndBadExceptionConstructor() throws Exception {
try {
getChecked(FAILED_FUTURE_CHECKED_EXCEPTION, ExceptionWithGoodAndBadConstructor.class);
fail();
} catch (ExceptionWithGoodAndBadConstructor expected) {
assertThat(expected).hasCauseThat().isSameAs(CHECKED_EXCEPTION);
}
}
代码示例来源:origin: google/guava
public void testGet_runtimeException() {
final RuntimeException e = new RuntimeException();
LoadingCache<Object, Object> map =
CacheBuilder.newBuilder()
.maximumSize(0)
.removalListener(listener)
.build(exceptionLoader(e));
try {
map.getUnchecked(new Object());
fail();
} catch (UncheckedExecutionException uee) {
assertThat(uee).hasCauseThat().isSameAs(e);
}
assertTrue(listener.isEmpty());
checkEmpty(map);
}
}
代码示例来源:origin: google/guava
public void testBulkLoadingExceptionWithCause() {
final Exception cause = new Exception();
final UncheckedExecutionException uee = new UncheckedExecutionException(cause);
final ExecutionException ee = new ExecutionException(cause);
LoadingCache<Object, Object> cacheUnchecked =
CacheBuilder.newBuilder().build(bulkLoader(exceptionLoader(uee)));
LoadingCache<Object, Object> cacheChecked =
CacheBuilder.newBuilder().build(bulkLoader(exceptionLoader(ee)));
try {
cacheUnchecked.getAll(asList(new Object()));
fail();
} catch (ExecutionException e) {
fail();
} catch (UncheckedExecutionException caughtEe) {
assertThat(caughtEe).hasCauseThat().isSameAs(uee);
}
try {
cacheChecked.getAll(asList(new Object()));
fail();
} catch (ExecutionException caughtEe) {
assertThat(caughtEe).hasCauseThat().isSameAs(ee);
}
}
代码示例来源:origin: google/guava
private static void assertFailed(AbstractFuture<Integer> future, Throwable expectedException)
throws InterruptedException, TimeoutException {
assertDone(future);
assertThat(future.isCancelled()).isFalse();
try {
getDone(future);
fail();
} catch (ExecutionException e) {
assertThat(e.getCause()).isSameAs(expectedException);
}
try {
getDoneFromTimeoutOverload(future);
fail();
} catch (ExecutionException e) {
assertThat(e).hasCauseThat().isSameAs(expectedException);
}
}
代码示例来源:origin: google/guava
public void testException() throws InterruptedException {
final Throwable failure = new Throwable();
AbstractFuture<String> future =
new AbstractFuture<String>() {
{
setException(failure);
}
};
ExecutionException ee1 = getExpectingExecutionException(future);
ExecutionException ee2 = getExpectingExecutionException(future);
// Ensure we get a unique execution exception on each get
assertNotSame(ee1, ee2);
assertThat(ee1).hasCauseThat().isSameAs(failure);
assertThat(ee2).hasCauseThat().isSameAs(failure);
checkStackTrace(ee1);
checkStackTrace(ee2);
}
代码示例来源:origin: google/guava
public void testSetException() throws Exception {
SettableFuture<Object> future = SettableFuture.create();
Exception e = new Exception("foobarbaz");
assertTrue(future.setException(e));
// Later attempts to set the future should return false.
assertFalse(future.set(23));
assertFalse(future.setException(new Exception("quux")));
assertFalse(future.setFuture(SettableFuture.create()));
// Check that the future has been set properly.
assertTrue(future.isDone());
assertFalse(future.isCancelled());
try {
future.get();
fail("Expected ExecutionException");
} catch (ExecutionException ee) {
assertThat(ee).hasCauseThat().isSameAs(e);
}
}
代码示例来源:origin: google/guava
public void testEvilFuture_setFuture() throws Exception {
final RuntimeException exception = new RuntimeException("you didn't say the magic word!");
AbstractFuture<String> evilFuture =
new AbstractFuture<String>() {
@Override
public void addListener(Runnable r, Executor e) {
throw exception;
}
};
AbstractFuture<String> normalFuture = new AbstractFuture<String>() {};
normalFuture.setFuture(evilFuture);
assertTrue(normalFuture.isDone());
try {
normalFuture.get();
fail();
} catch (ExecutionException e) {
assertThat(e).hasCauseThat().isSameAs(exception);
}
}
代码示例来源:origin: google/guava
public void testStart_failed() throws Exception {
final Exception exception = new Exception("deliberate");
AbstractIdleService service =
new DefaultService() {
@Override
protected void startUp() throws Exception {
throw exception;
}
};
try {
service.startAsync().awaitRunning();
fail();
} catch (RuntimeException e) {
assertThat(e).hasCauseThat().isSameAs(exception);
}
assertEquals(Service.State.FAILED, service.state());
}
代码示例来源:origin: google/guava
public void testStart_failed() {
final Exception exception = new Exception("deliberate");
TestService service =
new TestService() {
@Override
protected void startUp() throws Exception {
super.startUp();
throw exception;
}
};
assertEquals(0, service.startUpCalled);
try {
service.startAsync().awaitRunning();
fail();
} catch (RuntimeException e) {
assertThat(e).hasCauseThat().isSameAs(exception);
}
assertEquals(1, service.startUpCalled);
assertEquals(Service.State.FAILED, service.state());
assertThat(service.transitionStates).containsExactly(Service.State.STARTING);
}
代码示例来源:origin: google/guava
public void testStop_failed() throws Exception {
final Exception exception = new Exception("deliberate");
AbstractIdleService service =
new DefaultService() {
@Override
protected void shutDown() throws Exception {
throw exception;
}
};
service.startAsync().awaitRunning();
try {
service.stopAsync().awaitTerminated();
fail();
} catch (RuntimeException e) {
assertThat(e).hasCauseThat().isSameAs(exception);
}
assertEquals(Service.State.FAILED, service.state());
}
}
代码示例来源:origin: google/guava
public void testBulkLoadUncheckedException() throws ExecutionException {
Exception e = new RuntimeException();
CacheLoader<Object, Object> loader = exceptionLoader(e);
LoadingCache<Object, Object> cache =
CacheBuilder.newBuilder().recordStats().build(bulkLoader(loader));
CacheStats stats = cache.stats();
assertEquals(0, stats.missCount());
assertEquals(0, stats.loadSuccessCount());
assertEquals(0, stats.loadExceptionCount());
assertEquals(0, stats.hitCount());
try {
cache.getAll(asList(new Object()));
fail();
} catch (UncheckedExecutionException expected) {
assertThat(expected).hasCauseThat().isSameAs(e);
}
stats = cache.stats();
assertEquals(1, stats.missCount());
assertEquals(0, stats.loadSuccessCount());
assertEquals(1, stats.loadExceptionCount());
assertEquals(0, stats.hitCount());
}
内容来源于网络,如有侵权,请联系作者删除!