Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas committed Dec 18, 2024
1 parent b63792f commit ce52707
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,6 @@ public boolean reportProblem(P problem) {
throw new IllegalStateException("empty problem collector");
}

@Override
public Stream<P> problems() {
return Stream.empty();
}

@Override
public Stream<P> problems(BuilderProblem.Severity severity) {
return Stream.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,49 @@ void severityWarningDetection() {
assertFalse(collector.hasFatalProblems());
}

@Test
void lossy() {
ProblemCollector<BuilderProblem> collector = ProblemCollector.create(5);
IntStream.range(0, 5)
.forEach(i -> collector.reportProblem(new DefaultBuilderProblem(
"source", 0, 0, null, "message " + i, BuilderProblem.Severity.WARNING)));

// collector is "full" of warnings
assertFalse(collector.reportProblem(new DefaultBuilderProblem(
"source", 0, 0, null, "message", BuilderProblem.Severity.WARNING)));

// but collector will drop warning for more severe issues
assertTrue(collector.reportProblem(new DefaultBuilderProblem(
"source", 0, 0, null, "message", BuilderProblem.Severity.ERROR)));
assertTrue(collector.reportProblem(new DefaultBuilderProblem(
"source", 0, 0, null, "message", BuilderProblem.Severity.FATAL)));

// collector is full of warnings, errors and fatal (mixed)
assertFalse(collector.reportProblem(new DefaultBuilderProblem(
"source", 0, 0, null, "message", BuilderProblem.Severity.WARNING)));

// fill it up with fatal ones
IntStream.range(0, 5)
.forEach(i -> collector.reportProblem(new DefaultBuilderProblem(
"source", 0, 0, null, "message " + i, BuilderProblem.Severity.FATAL)));

// from now on, only counters work, problems are lost
assertFalse(collector.reportProblem(new DefaultBuilderProblem(
"source", 0, 0, null, "message", BuilderProblem.Severity.WARNING)));
assertFalse(collector.reportProblem(new DefaultBuilderProblem(
"source", 0, 0, null, "message", BuilderProblem.Severity.ERROR)));
assertFalse(collector.reportProblem(new DefaultBuilderProblem(
"source", 0, 0, null, "message", BuilderProblem.Severity.FATAL)));

assertEquals(17, collector.totalProblemsReported());
assertEquals(8, collector.problemsReportedFor(BuilderProblem.Severity.WARNING));
assertEquals(2, collector.problemsReportedFor(BuilderProblem.Severity.ERROR));
assertEquals(7, collector.problemsReportedFor(BuilderProblem.Severity.FATAL));

// but preserved problems count == capacity
assertEquals(5, collector.problems().count());
}

@Test
void moreSeverePushOutLeastSevere() {
ProblemCollector<BuilderProblem> collector = ProblemCollector.create(5);
Expand Down

0 comments on commit ce52707

Please sign in to comment.