Add boundary tests for JsonValueWriter max nesting depth#49662
Conversation
| @Test | ||
| void shouldRejectStartingObjectWhenCurrentDepthExceedsMaxDepth() { | ||
| StringBuilder out = new StringBuilder(); | ||
| JsonValueWriter writer = new JsonValueWriter(out, 2); | ||
|
|
||
| writer.start(Series.OBJECT); | ||
| writer.start(Series.OBJECT); | ||
| writer.start(Series.OBJECT); | ||
|
|
||
| assertThatIllegalStateException().isThrownBy(() -> writer.start(Series.OBJECT)) | ||
| .withMessageContaining("JSON nesting depth (3)") | ||
| .withMessageContaining("exceeds maximum depth of 2"); | ||
| } |
There was a problem hiding this comment.
This test doesn't seem to add much as the exception case is covered by the existing tests. Why do you feel it's needed?
| @Test | ||
| void shouldRejectStartingArrayWhenCurrentDepthExceedsMaxDepth() { | ||
| StringBuilder out = new StringBuilder(); | ||
| JsonValueWriter writer = new JsonValueWriter(out, 2); | ||
|
|
||
| writer.start(Series.ARRAY); | ||
| writer.start(Series.ARRAY); | ||
| writer.start(Series.ARRAY); | ||
|
|
||
| assertThatIllegalStateException().isThrownBy(() -> writer.start(Series.ARRAY)) | ||
| .withMessageContaining("JSON nesting depth (3)") | ||
| .withMessageContaining("exceeds maximum depth of 2"); | ||
| } |
There was a problem hiding this comment.
This test doesn't seem to add much as the exception case is covered by the existing tests. Why do you feel it's needed?
|
Thanks for the feedback. The intention of these tests was to exercise the max nesting depth check However, I agree that this overlaps with the existing coverage, so I’ve removed Please let me know if further adjustments would be helpful. |
Verify behavior at the maxNestingDepth boundary. Signed-off-by: Joowon-Seo <[email protected]> See spring-projectsgh-49662
0a96475 to
7f0136f
Compare
Verify behavior at the maxNestingDepth boundary. Signed-off-by: Joowon-Seo <[email protected]> See spring-projectsgh-49662
7f0136f to
5679882
Compare
5679882 to
3717468
Compare
|
Thank you, @Joowon-Seo. |
This change adds boundary tests for JsonValueWriter max nesting depth.
Existing tests verify that exceeding the maximum depth eventually results
in an exception, but they do not assert the exact boundary at which nesting
is still allowed.
The new tests verify that starting a new series when the current depth
equals maxNestingDepth is still allowed, and that an exception is thrown
when attempting to start another series beyond that point.
This helps to better define the current behavior and guard against regressions.