use of com.google.protobuf.Option in project gax-java by googleapis.
the class HttpJsonOperationSnapshotCallableTest method futureCallTestException.
@Test
public void futureCallTestException() throws InterruptedException {
Option request = Option.newBuilder().setName("Arizona").build();
Field field = Field.newBuilder().setName("Georgia").build();
ApiCallContext context = mock(ApiCallContext.class);
OperationSnapshot operationSnapshot = HttpJsonOperationSnapshot.newBuilder().setName("California").setMetadata(2).setDone(true).setResponse("Florida").setError(0, "no error").build();
SettableApiFuture<Field> settableApiFuture = SettableApiFuture.create();
settableApiFuture.setException(new RuntimeException("Seattle"));
when(operationSnapshotFactory.create(request, field)).thenReturn(operationSnapshot);
when(innerCallable.futureCall(request, context)).thenReturn(settableApiFuture);
try {
operationSnapCallable.futureCall(request, context).get();
Assert.fail("Exception should have been thrown");
} catch (ExecutionException e) {
Truth.assertThat(e).hasMessageThat().contains("Seattle");
}
}
use of com.google.protobuf.Option in project gax-java by googleapis.
the class HttpJsonOperationSnapshotCallableTest method futureCallTest.
@Test
public void futureCallTest() throws ExecutionException, InterruptedException {
Option request = Option.newBuilder().setName("Arizona").build();
Field field = Field.newBuilder().setName("Georgia").build();
ApiCallContext context = mock(ApiCallContext.class);
OperationSnapshot operationSnapshot = HttpJsonOperationSnapshot.newBuilder().setName("California").setMetadata(2).setDone(true).setResponse("Florida").setError(0, "no error").build();
SettableApiFuture<Field> settableApiFuture = SettableApiFuture.create();
settableApiFuture.set(field);
when(operationSnapshotFactory.create(request, field)).thenReturn(operationSnapshot);
when(innerCallable.futureCall(request, context)).thenReturn(settableApiFuture);
ApiFuture<OperationSnapshot> futureCall = operationSnapCallable.futureCall(request, context);
Truth.assertThat(futureCall.get().getName()).isEqualTo("California");
}
Aggregations