Skip to content

Commit

Permalink
Merge pull request #1473 from CMSgov/feature/QPPSE-2784-Remove_Duplic…
Browse files Browse the repository at this point in the history
…ate_Error_Details

QPPSE-2784: Fix duplication in error details
  • Loading branch information
sivaksb authored Nov 6, 2024
2 parents 050f4a6 + 2c9fecd commit f104bd7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.base.MoreObjects;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;

/**
Expand Down Expand Up @@ -34,6 +35,13 @@ public AllErrors(List<Error> errors) {
* @return All the {@code Error}s.
*/
public List<Error> getErrors() {
if (null == errors) return errors;
errors.forEach(error -> {
if (!error.getDetails().isEmpty()) {
List<Detail> details = new ArrayList<>(new LinkedHashSet<>(error.getDetails()));
error.setDetails(details);
}
});
return errors;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,17 @@ void testArgConstructor() {
assertThat(new AllErrors(errors).getErrors())
.containsAtLeastElementsIn(errors);
}

@Test
void testGetErrorDuplicateDetails() {
AllErrors objectUnderTest = new AllErrors();
List<Detail> details = new ArrayList<Detail>();
details.add(new Detail("test"));
details.add(new Detail("test"));
Error error = new Error();
error.setDetails(details);
objectUnderTest.addError(error);
assertWithMessage("The error details should be one")
.that(objectUnderTest.getErrors().get(0).getDetails()).hasSize(1);
}
}

0 comments on commit f104bd7

Please sign in to comment.