@Test
public void testFailed() throws Exception {

  OperationFuture<String, Integer> future =
      OperationFutures.<String, Integer>immediateOperationFuture(
          FakeOperationSnapshot.newBuilder()
              .setName("myName")
              .setDone(true)
              .setMetadata(42)
              .setErrorCode(FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT))
              .build());
  assertThat(future.getName()).isEqualTo("myName");
  assertThat(future.getMetadata().get()).isEqualTo(42);
  try {
    future.get();
    fail();
  } catch (ExecutionException e) {
    assertThat(e.getCause()).isInstanceOf(ApiException.class);
  }
}