GoogleAdsExceptionTransformation implements ExceptionTransformingCallable.ExceptionTransformation { @Override public Throwable transform(ApiException apiException) { for (Version version : catalog.getSupportedVersions()) { Optional<? extends BaseGoogleAdsException> result = version.getExceptionFactory().createGoogleAdsException(apiException); if (result.isPresent()) { return result.get(); } } return apiException; }  @Override Throwable transform(ApiException apiException);  }
@Test public void loadsAllVersions() { for (Version version : catalog.getSupportedVersions()) { Message expectedFailure = version.getExceptionFactory().createGoogleAdsFailure(); ApiException exception = getApiExceptionForVersion( version.getExceptionFactory().getTrailerKey(), expectedFailure.toByteArray()); Throwable result = transformation.transform(exception); Message actualFailure = ((BaseGoogleAdsException) result).getGoogleAdsFailure(); assertEquals(expectedFailure, actualFailure); } }
@Test public void handlesNoRootCause() { ApiException exception = new ApiException(null, GrpcStatusCode.of(Code.UNKNOWN), false); Throwable result = transformation.transform(exception); assertEquals(exception, result); }
@Test public void handlesNullTrailers() { ApiException exception = new ApiException( new StatusException(Status.UNKNOWN), GrpcStatusCode.of(Code.UNKNOWN), false); Throwable result = transformation.transform(exception); assertEquals(exception, result); }
@Test public void handlesEmptyTrailers() { for (Version version : catalog.getSupportedVersions()) { ApiException exception = getApiExceptionForVersion(version.getExceptionFactory().getTrailerKey(), null); Throwable result = transformation.transform(exception); assertEquals(exception, result); } }
@Test public void failsGracefullyWithUnparsableFailureProto() { for (Version version : catalog.getSupportedVersions()) { ApiException exception = getApiExceptionForVersion( version.getExceptionFactory().getTrailerKey(), new byte[] {0, 1, 2, 3}); Throwable result = transformation.transform(exception); assertEquals(exception, result); } }