GrpcLongRunningClient implements LongRunningClient { @Override public UnaryCallable<String, OperationSnapshot> getOperationCallable() { return TranslatingUnaryCallable.create( operationsStub.getOperationCallable(), new ApiFunction<String, GetOperationRequest>() { @Override public GetOperationRequest apply(String request) { return GetOperationRequest.newBuilder().setName(request).build(); } }, new ApiFunction<Operation, OperationSnapshot>() { @Override public OperationSnapshot apply(Operation operation) { return GrpcOperationSnapshot.create(operation); } }); } GrpcLongRunningClient(OperationsStub operationsStub); @Override UnaryCallable<String, OperationSnapshot> getOperationCallable(); @Override UnaryCallable<String, Void> cancelOperationCallable(); @Override UnaryCallable<String, Void> deleteOperationCallable(); static GrpcLongRunningClient create(OperationsStub operationsStub);  }
@Test public void get() { OperationsStub operationsStub = mock(OperationsStub.class); when(operationsStub.getOperationCallable()) .thenReturn( new UnaryCallable<GetOperationRequest, Operation>() { @Override public ApiFuture<Operation> futureCall( GetOperationRequest request, ApiCallContext context) { if (!request.getName().equals("poseidon")) { return ApiFutures.immediateFailedFuture( new IllegalStateException("Unexpected request: " + request)); } else { return ApiFutures.immediateFuture( Operation.newBuilder().setName("greece").build()); } } }); LongRunningClient longRunningClient = new GrpcLongRunningClient(operationsStub); Truth.assertThat(longRunningClient.getOperationCallable().call("poseidon").getName()) .isEqualTo("greece"); }