### Question:
ExecutionResultToProtoAsync { public static <T extends Message> CompletableFuture<ProtoExecutionResult<T>> toProtoExecutionResult( T message, CompletableFuture<ExecutionResult> executionResultCompletableFuture) { return executionResultCompletableFuture.thenApply( executionResult -> ProtoExecutionResult.create( QueryResponseToProto.buildMessage(message, executionResult.getData()), errorsToProto(executionResult.getErrors()))); }  static CompletableFuture<ProtoExecutionResult<T>> toProtoExecutionResult(
          T message, CompletableFuture<ExecutionResult> executionResultCompletableFuture); static CompletableFuture<T> toProtoMessage(
      T message, CompletableFuture<ExecutionResult> executionResultCompletableFuture);  }### Answer:
@Test public void toProtoExecutionResultShouldReturnData() throws ExecutionException, InterruptedException { CompletableFuture<ProtoExecutionResult<Proto1>> executionResultCompletableFuture = ExecutionResultToProtoAsync.toProtoExecutionResult( Proto1.getDefaultInstance(), CompletableFuture.completedFuture( ExecutionResultImpl.newExecutionResult() .data( ImmutableMap.of( "id", "abc", "intField", 123, "testProto", ImmutableMap.of( "innerId", "abc_inner", "enums", ImmutableList.of("FOO")))) .build())); ProtoTruth.assertThat(executionResultCompletableFuture.get().message()) .isEqualTo( Proto1.newBuilder() .setId("abc") .setIntField(123) .setTestProto( Proto2.newBuilder() .setInnerId("abc_inner") .addEnumsValue(Proto2.TestEnum.FOO_VALUE)) .build()); Truth.assertThat(executionResultCompletableFuture.get().errors()).isEmpty(); }
@Test public void toProtoExecutionResultShouldReturnDataAndError() throws ExecutionException, InterruptedException { ExceptionWhileDataFetching exceptionWhileDataFetching = new ExceptionWhileDataFetching( ExecutionPath.rootPath(), new RuntimeException("hello world"), new SourceLocation(10, 20)); CompletableFuture<ProtoExecutionResult<Proto1>> executionResultCompletableFuture = ExecutionResultToProtoAsync.toProtoExecutionResult( Proto1.getDefaultInstance(), CompletableFuture.completedFuture( ExecutionResultImpl.newExecutionResult() .data( ImmutableMap.of( "id", "abc", "intField", 123, "testProto", ImmutableMap.of( "innerId", "abc_inner", "enums", ImmutableList.of("FOO")))) .addError(exceptionWhileDataFetching) .build())); ProtoTruth.assertThat(executionResultCompletableFuture.get().message()) .isEqualTo( Proto1.newBuilder() .setId("abc") .setIntField(123) .setTestProto( Proto2.newBuilder() .setInnerId("abc_inner") .addEnumsValue(Proto2.TestEnum.FOO_VALUE)) .build()); ProtoTruth.assertThat(executionResultCompletableFuture.get().errors()) .containsExactly( GraphqlError.newBuilder() .setMessage("Exception while fetching data () : hello world") .addLocations( com.google.api.graphql.SourceLocation.newBuilder().setLine(10).setColumn(20)) .setType(ErrorType.DATA_FETCHING_EXCEPTION) .build()); }