com.google.common.truth.ThrowableSubject.isNull()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(70)

本文整理了Java中com.google.common.truth.ThrowableSubject.isNull()方法的一些代码示例,展示了ThrowableSubject.isNull()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ThrowableSubject.isNull()方法的具体详情如下:
包路径:com.google.common.truth.ThrowableSubject
类名称:ThrowableSubject
方法名:isNull

ThrowableSubject.isNull介绍

暂无

代码示例

代码示例来源:origin: google/guava

public void testTrustedGetFailure_Completed() {
 SettableFuture<String> future = SettableFuture.create();
 future.set("261");
 assertThat(future.tryInternalFastPathGetFailure()).isNull();
}

代码示例来源:origin: google/guava

public void testTrustedGetFailure_CanceledNoCause() {
 SettableFuture<String> future = SettableFuture.create();
 future.cancel(false);
 assertThat(future.tryInternalFastPathGetFailure()).isNull();
}

代码示例来源:origin: google/guava

public void testGetFailure_Failed() {
 AbstractFuture<String> future = new AbstractFuture<String>() {};
 final Throwable failure = new Throwable();
 future.setException(failure);
 assertThat(future.tryInternalFastPathGetFailure()).isNull();
}

代码示例来源:origin: google/guava

public void testGetFailure_CanceledNoCause() {
 AbstractFuture<String> future = new AbstractFuture<String>() {};
 future.cancel(false);
 assertThat(future.tryInternalFastPathGetFailure()).isNull();
}

代码示例来源:origin: google/guava

public void testGetFailure_Completed() {
 AbstractFuture<String> future = new AbstractFuture<String>() {};
 future.set("261");
 assertThat(future.tryInternalFastPathGetFailure()).isNull();
}

代码示例来源:origin: google/guava

public void testTrustedGetFailure_NotCompleted() {
 SettableFuture<String> future = SettableFuture.create();
 assertThat(future.isDone()).isFalse();
 assertThat(future.tryInternalFastPathGetFailure()).isNull();
}

代码示例来源:origin: google/guava

public void testGetFailure_NotCompleted() {
 AbstractFuture<String> future = new AbstractFuture<String>() {};
 assertThat(future.isDone()).isFalse();
 assertThat(future.tryInternalFastPathGetFailure()).isNull();
}

代码示例来源:origin: google/guava

@Override
public synchronized void terminated(State from) {
 assertEquals(from, Iterables.getLast(stateHistory, State.NEW));
 stateHistory.add(State.TERMINATED);
 assertEquals(State.TERMINATED, service.state());
 if (from == State.NEW) {
  try {
   service.awaitRunning();
   fail();
  } catch (IllegalStateException expected) {
   assertThat(expected).hasCauseThat().isNull();
   assertThat(expected)
     .hasMessageThat()
     .isEqualTo("Expected the service " + service + " to be RUNNING, but was TERMINATED");
  }
 }
 completionLatch.countDown();
}

代码示例来源:origin: google/guava

@Override
public synchronized void stopping(State from) {
 assertEquals(from, Iterables.getLast(stateHistory));
 stateHistory.add(State.STOPPING);
 if (from == State.STARTING) {
  try {
   service.awaitRunning();
   fail();
  } catch (IllegalStateException expected) {
   assertThat(expected).hasCauseThat().isNull();
   assertThat(expected)
     .hasMessageThat()
     .isEqualTo("Expected the service " + service + " to be RUNNING, but was STOPPING");
  }
 }
 assertNotSame(from, service.state());
}

代码示例来源:origin: robolectric/robolectric

@Test
public void shouldBeAbleToBeUsedFromDifferentThread() {
  final CountDownLatch sync = new CountDownLatch(1);
  final Throwable[] error = {null};
  new Thread() {
    @Override
    public void run() {
      try {
        executeQuery("select * from table_name");
      } catch (Throwable e) {
        e.printStackTrace();
        error[0] = e;
      } finally {
        sync.countDown();
      }
    }
  }
      .start();
  try {
    sync.await();
  } catch (InterruptedException e) {
    throw new RuntimeException(e);
  }
  assertThat(error[0]).isNull();
}

代码示例来源:origin: googleapis/google-cloud-java

private void verifyOk(ApiFuture<?> result) {
 Throwable error = null;
 try {
  result.get(FLUSH_PERIOD.plus(DELAY_BUFFER).toMillis(), TimeUnit.MILLISECONDS);
 } catch (ExecutionException e) {
  error = e.getCause();
 } catch (Throwable t) {
  error = t;
 }
 assertThat(error).isNull();
}

代码示例来源:origin: google/guava

@GwtIncompatible
public void testImmediateCancelledFutureStack() throws Exception {
 ListenableFuture<String> future = CallerClass1.makeImmediateCancelledFuture();
 assertTrue(future.isCancelled());
 try {
  CallerClass2.get(future);
  fail();
 } catch (CancellationException expected) {
  // There should be two CancellationException chained together.  The outer one should have the
  // stack trace of where the get() call was made, and the inner should have the stack trace of
  // where the immediateCancelledFuture() call was made.
  List<StackTraceElement> stackTrace = ImmutableList.copyOf(expected.getStackTrace());
  assertFalse(Iterables.any(stackTrace, hasClassName(CallerClass1.class)));
  assertTrue(Iterables.any(stackTrace, hasClassName(CallerClass2.class)));
  // See AbstractFutureCancellationCauseTest for how to set causes.
  assertThat(expected.getCause()).isNull();
 }
}

代码示例来源:origin: google/ExoPlayer

@Test
public void testConnectResponseBeforeTimeout() throws Exception {
 long startTimeMs = SystemClock.elapsedRealtime();
 final ConditionVariable startCondition = buildUrlRequestStartedCondition();
 final CountDownLatch openLatch = new CountDownLatch(1);
 AtomicReference<Exception> exceptionOnTestThread = new AtomicReference<>();
 new Thread() {
  @Override
  public void run() {
   try {
    dataSourceUnderTest.open(testDataSpec);
   } catch (HttpDataSourceException e) {
    exceptionOnTestThread.set(e);
   } finally {
    openLatch.countDown();
   }
  }
 }.start();
 startCondition.block();
 // We should still be trying to open.
 assertNotCountedDown(openLatch);
 // We should still be trying to open as we approach the timeout.
 SystemClock.setCurrentTimeMillis(startTimeMs + TEST_CONNECT_TIMEOUT_MS - 1);
 assertNotCountedDown(openLatch);
 // The response arrives just in time.
 dataSourceUnderTest.urlRequestCallback.onResponseStarted(mockUrlRequest, testUrlResponseInfo);
 openLatch.await();
 assertThat(exceptionOnTestThread.get()).isNull();
}

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void testOneToManyAuto() throws InterruptedException {
 MockResponseObserver<String> outerObserver = new MockResponseObserver<>(true);
 ReframingResponseObserver<String, String> middleware =
   new ReframingResponseObserver<>(outerObserver, new DasherizingReframer(2));
 ServerStreamingStashCallable<String, String> innerCallable =
   new ServerStreamingStashCallable<>(ImmutableList.of("a", "b"));
 innerCallable.call("request", middleware);
 Truth.assertThat(outerObserver.popNextResponse()).isEqualTo("a-b");
 Truth.assertThat(outerObserver.isDone()).isTrue();
 Truth.assertThat(outerObserver.getFinalError()).isNull();
}

代码示例来源:origin: google/guava

public void testCancel_notDoneNoInterrupt() throws Exception {
 InterruptibleFuture future = new InterruptibleFuture();
 assertTrue(future.cancel(false));
 assertTrue(future.isCancelled());
 assertTrue(future.isDone());
 assertFalse(future.wasInterrupted());
 assertFalse(future.interruptTaskWasCalled);
 try {
  future.get();
  fail("Expected CancellationException");
 } catch (CancellationException e) {
  // See AbstractFutureCancellationCauseTest for how to set causes
  assertThat(e).hasCauseThat().isNull();
 }
}

代码示例来源:origin: google/guava

public void testCancel_notDoneInterrupt() throws Exception {
 InterruptibleFuture future = new InterruptibleFuture();
 assertTrue(future.cancel(true));
 assertTrue(future.isCancelled());
 assertTrue(future.isDone());
 assertTrue(future.wasInterrupted());
 assertTrue(future.interruptTaskWasCalled);
 try {
  future.get();
  fail("Expected CancellationException");
 } catch (CancellationException e) {
  // See AbstractFutureCancellationCauseTest for how to set causes
  assertThat(e).hasCauseThat().isNull();
 }
}

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void testOneToMany() throws InterruptedException {
 MockResponseObserver<String> outerObserver = new MockResponseObserver<>(false);
 ReframingResponseObserver<String, String> middleware =
   new ReframingResponseObserver<>(outerObserver, new DasherizingReframer(2));
 ServerStreamingStashCallable<String, String> innerCallable =
   new ServerStreamingStashCallable<>(ImmutableList.of("a", "b"));
 innerCallable.call("request", middleware);
 Preconditions.checkState(outerObserver.popNextResponse() == null);
 outerObserver.getController().request(1);
 Truth.assertThat(outerObserver.popNextResponse()).isEqualTo("a-b");
 Truth.assertThat(outerObserver.isDone()).isTrue();
 Truth.assertThat(outerObserver.getFinalError()).isNull();
}

代码示例来源:origin: googleapis/google-cloud-java

Truth.assertThat(outerObserver.getFinalError()).isNull();
 error = e.getCause();
Truth.assertThat(error).isNull();

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void readRowRetryCodesMustMatch() {
 EnhancedBigtableStubSettings.Builder builder =
   EnhancedBigtableStubSettings.newBuilder()
     .setProjectId("my-project")
     .setInstanceId("my-instance");
 builder.readRowsSettings().setRetryableCodes(Code.DEADLINE_EXCEEDED);
 builder.readRowSettings().setRetryableCodes(Code.ABORTED);
 Exception actualError = null;
 try {
  builder.build();
 } catch (Exception e) {
  actualError = e;
 }
 assertThat(actualError).isNotNull();
 builder.readRowSettings().setRetryableCodes(Code.DEADLINE_EXCEEDED);
 actualError = null;
 try {
  builder.build();
 } catch (Exception e) {
  actualError = e;
 }
 assertThat(actualError).isNull();
}

代码示例来源:origin: JakeWharton/retrofit2-reactor-adapter

@Test public void response() {
 Response<String> response = Response.success("Hi");
 Result<String> result = Result.response(response);
 assertThat(result.isError()).isFalse();
 assertThat(result.error()).isNull();
 assertThat(result.response()).isSameAs(response);
}

相关文章