Skip to content

Add boundary tests for JsonValueWriter max nesting depth#49662

Merged
wilkinsona merged 2 commits intospring-projects:3.5.xfrom
Joowon-Seo:test/json-value-writer-nesting-boundary
Mar 19, 2026
Merged

Add boundary tests for JsonValueWriter max nesting depth#49662
wilkinsona merged 2 commits intospring-projects:3.5.xfrom
Joowon-Seo:test/json-value-writer-nesting-boundary

Conversation

@Joowon-Seo
Copy link
Copy Markdown
Contributor

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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 19, 2026
Comment on lines +316 to +328
@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");
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment on lines +346 to +358
@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");
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@Joowon-Seo
Copy link
Copy Markdown
Contributor Author

Thanks for the feedback.

The intention of these tests was to exercise the max nesting depth check
directly via the start(...) method, rather than indirectly through write(...),
to make the boundary behavior more explicit.

However, I agree that this overlaps with the existing coverage, so I’ve removed
the additional exception tests and kept the ones that focus on the boundary
condition where nesting is still allowed.

Please let me know if further adjustments would be helpful.

@wilkinsona wilkinsona added this to the 3.5.x milestone Mar 19, 2026
@wilkinsona wilkinsona added type: task A general task and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 19, 2026
@wilkinsona wilkinsona self-assigned this Mar 19, 2026
Verify behavior at the maxNestingDepth boundary.

Signed-off-by: Joowon-Seo <[email protected]>

See spring-projectsgh-49662
@wilkinsona wilkinsona changed the base branch from main to 3.5.x March 19, 2026 18:22
@wilkinsona wilkinsona force-pushed the test/json-value-writer-nesting-boundary branch from 0a96475 to 7f0136f Compare March 19, 2026 18:22
wilkinsona pushed a commit to Joowon-Seo/spring-boot that referenced this pull request Mar 19, 2026
Verify behavior at the maxNestingDepth boundary.

Signed-off-by: Joowon-Seo <[email protected]>

See spring-projectsgh-49662
@wilkinsona wilkinsona force-pushed the test/json-value-writer-nesting-boundary branch from 7f0136f to 5679882 Compare March 19, 2026 18:25
@wilkinsona wilkinsona force-pushed the test/json-value-writer-nesting-boundary branch from 5679882 to 3717468 Compare March 19, 2026 18:26
@wilkinsona wilkinsona modified the milestones: 3.5.x, 3.5.13 Mar 19, 2026
@wilkinsona wilkinsona merged commit 47aa60d into spring-projects:3.5.x Mar 19, 2026
1 check failed
@wilkinsona
Copy link
Copy Markdown
Member

Thank you, @Joowon-Seo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: task A general task

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants