@Test
public void exceptionTransformedToGoogleAdsException() {

  GoogleAdsClient client =
      GoogleAdsClient.newBuilder()
          .setCredentials(fakeCredentials)
          .setDeveloperToken(DEVELOPER_TOKEN)
          .setTransportChannelProvider(localChannelProvider)
          .setEnableGeneratedCatalog(enabledGeneratedCatalog)
          .build();
  Metadata.Key trailerKey =
      ApiCatalog.getDefault().getLatestVersion().getExceptionFactory().getTrailerKey();
  Metadata trailers = new Metadata();
  GoogleAdsFailure.Builder failure = GoogleAdsFailure.newBuilder();
  failure.addErrors(GoogleAdsError.newBuilder().setMessage("Test error message"));
  trailers.put(trailerKey, failure.build().toByteArray());
  StatusException rootCause = new StatusException(Status.UNKNOWN, trailers);
  mockService.addException(new ApiException(rootCause, GrpcStatusCode.of(Code.UNKNOWN), false));
  try (GoogleAdsServiceClient googleAdsServiceClient =
      client.getLatestVersion().createGoogleAdsServiceClient()) {
    googleAdsServiceClient.search("123", "select blah");
  } catch (GoogleAdsException ex) {
    // Expected
  }
}