AbstractErrorUtils { public List<GoogleAdsErrorT> getGoogleAdsErrors(long operationIndex, Status partialFailureStatus) throws InvalidProtocolBufferException { List<GoogleAdsErrorT> result = new ArrayList(); for (Any detail : partialFailureStatus.getDetailsList()) { GoogleAdsFailureT failure = getGoogleAdsFailure(detail); result.addAll(getGoogleAdsErrors(operationIndex, failure)); } return result; }  List<GoogleAdsErrorT> getGoogleAdsErrors(long operationIndex, Status partialFailureStatus); List<GoogleAdsErrorT> getGoogleAdsErrors(
      long operationIndex, GoogleAdsFailureT googleAdsFailure); GoogleAdsFailureT getGoogleAdsFailure(Any detail); boolean isPartialFailureResult(Message message); abstract List<FieldPathElementT> getFieldPathElements(GoogleAdsErrorT googleAdsError); abstract List<GoogleAdsErrorT> getGoogleAdsErrors(GoogleAdsFailureT googleAdsFailure); abstract Class<GoogleAdsFailureT> getGoogleAdsFailureClass();  }
@Test public void getGoogleAdsErrors_includesWhen_operationSet() throws InvalidProtocolBufferException { MockPath path = MockPath.newBuilder() .setIndex(Int64Value.newBuilder().setValue(0)) .setFieldName(operationsFieldName) .build(); MockError error = MockError.newBuilder().addLocation(path).build(); MockFailure failure = MockFailure.newBuilder().addErrors(error).build(); Status status = Status.newBuilder().addDetails(Any.pack(failure)).build(); List<MockError> result = impl.getGoogleAdsErrors(0, status); assertEquals(1, result.size()); assertEquals(error, result.get(0)); }
@Test public void getGoogleAdsErrors_omitsWhen_operationNotSet() throws InvalidProtocolBufferException { MockPath path = MockPath.newBuilder().setFieldName("someotherfield").build(); MockError error = MockError.newBuilder().addLocation(path).build(); MockFailure failure = MockFailure.newBuilder().addErrors(error).build(); Status status = Status.newBuilder().addDetails(Any.pack(failure)).build(); List<MockError> result = impl.getGoogleAdsErrors(0, status); assertEquals(0, result.size()); }
@Test public void getGoogleAdsErrors_omitsWhen_missingIndex() throws InvalidProtocolBufferException { MockPath path = MockPath.newBuilder().setFieldName(operationsFieldName).build(); MockError error = MockError.newBuilder().addLocation(path).build(); MockFailure failure = MockFailure.newBuilder().addErrors(error).build(); Status status = Status.newBuilder().addDetails(Any.pack(failure)).build(); List<MockError> result = impl.getGoogleAdsErrors(0, status); assertEquals(0, result.size()); }
@Test public void getGoogleAdsErrors_omitsWhen_missingFieldName() throws InvalidProtocolBufferException { MockPath path = MockPath.newBuilder().setIndex(Int64Value.newBuilder().setValue(0).build()).build(); MockError error = MockError.newBuilder().addLocation(path).build(); MockFailure failure = MockFailure.newBuilder().addErrors(error).build(); Status status = Status.newBuilder().addDetails(Any.pack(failure)).build(); List<MockError> result = impl.getGoogleAdsErrors(0, status); assertEquals(0, result.size()); }
@Test public void getGoogleAdsErrors_omitsWhen_operationIndexOutOfSequenceInPaths() throws InvalidProtocolBufferException { MockPath path0 = MockPath.newBuilder().setFieldName("someotherfield").build(); MockPath path1 = MockPath.newBuilder() .setIndex(Int64Value.newBuilder().setValue(0)) .setFieldName(operationsFieldName) .build(); MockError error = MockError.newBuilder().addLocation(path0).addLocation(path1).build(); MockFailure failure = MockFailure.newBuilder().addErrors(error).build(); Status status = Status.newBuilder().addDetails(Any.pack(failure)).build(); List<MockError> result = impl.getGoogleAdsErrors(0, status); assertEquals(0, result.size()); }
@Test public void getGoogleAdsErrors_includesWhen_operationIndexOutOfSequenceInErrors() throws InvalidProtocolBufferException { MockPath path0 = MockPath.newBuilder() .setIndex(Int64Value.newBuilder().setValue(0)) .setFieldName(operationsFieldName) .build(); MockPath path1 = MockPath.newBuilder() .setIndex(Int64Value.newBuilder().setValue(1)) .setFieldName(operationsFieldName) .build(); MockError error0 = MockError.newBuilder().addLocation(path0).build(); MockError error1 = MockError.newBuilder().addLocation(path1).build(); MockFailure failure = MockFailure.newBuilder().addErrors(error1).addErrors(error0).build(); Status status = Status.newBuilder().addDetails(Any.pack(failure)).build(); List<MockError> result = impl.getGoogleAdsErrors(0, status); assertEquals(1, result.size()); assertEquals(error0, result.get(0)); }
@Test public void getGoogleAdsErrors_noDuplicates_ofSameError() throws InvalidProtocolBufferException { MockPath path0 = MockPath.newBuilder() .setIndex(Int64Value.newBuilder().setValue(0)) .setFieldName(operationsFieldName) .build(); MockPath path1 = MockPath.newBuilder() .setIndex(Int64Value.newBuilder().setValue(0)) .setFieldName(operationsFieldName) .build(); MockError error0 = MockError.newBuilder().addLocation(path0).build(); MockError error1 = MockError.newBuilder().addLocation(path1).build(); MockFailure failure = MockFailure.newBuilder().addErrors(error0).addErrors(error1).build(); Status status = Status.newBuilder().addDetails(Any.pack(failure)).build(); List<MockError> result = impl.getGoogleAdsErrors(0, status); assertEquals(1, result.size()); assertEquals(error0, result.get(0)); }
@Test public void getGoogleAdsErrors_duplicates_whenErrorsDiffer() throws InvalidProtocolBufferException { MockPath path0 = MockPath.newBuilder() .setIndex(Int64Value.newBuilder().setValue(0)) .setFieldName(operationsFieldName) .build(); MockPath path1 = MockPath.newBuilder() .setIndex(Int64Value.newBuilder().setValue(0)) .setFieldName(operationsFieldName) .build(); MockPath path2 = MockPath.newBuilder().setFieldName("somethingelse").build(); MockError error0 = MockError.newBuilder().addLocation(path0).build(); MockError error1 = MockError.newBuilder().addLocation(path1).addLocation(path2).build(); MockFailure failure = MockFailure.newBuilder().addErrors(error0).addErrors(error1).build(); Status status = Status.newBuilder().addDetails(Any.pack(failure)).build(); List<MockError> result = impl.getGoogleAdsErrors(0, status); assertEquals(2, result.size()); assertEquals(error0, result.get(0)); assertEquals(error1, result.get(1)); }