GH-594 - Deduplicate violations with the same message.

Moving away from exceptions as carriers for violations.
This commit is contained in:
Oliver Drotbohm
2024-05-16 12:20:44 +02:00
parent 551e117113
commit 2bf9f797ec
4 changed files with 61 additions and 35 deletions

View File

@@ -30,10 +30,25 @@ class ViolationsUnitTests {
void combinesExceptionMessages() {
Violations violations = Violations.NONE //
.and(new IllegalArgumentException("First")) //
.and(new IllegalArgumentException("Second"));
.and("First") //
.and("Second");
assertThat(violations.getMessage()) //
.isEqualTo("- First\n- Second");
}
@Test
void deduplicatesViolationsWithTheSameMessage() {
var violations = Violations.NONE
.and("First")
.and("First")
.and("Second")
.and(Violations.NONE.and("First")
.and("Second")
.and("Third"));
assertThat(violations.getMessages())
.containsExactlyInAnyOrder("First", "Second", "Third");
}
}