google / gson

A Java serialization/deserialization library to convert Java Objects into JSON and back
Apache License 2.0
23.16k stars 4.27k forks source link

Add Assertions to Validate `testWriterCloseIsIdempotent` Test for JsonWriter's Idempotency #2652

Closed Codegass closed 4 months ago

Codegass commented 4 months ago

Purpose

Closes #2650

This PR aims to enhance the clarity and completeness of the testWriterCloseIsIdempotent method in the JsonWriter class's unit tests. It introduces explicit assertions to verify the idempotency of the close method by ensuring the output remains unchanged after multiple calls. This change addresses a potential gap in our current testing strategy by providing a more explicit demonstration of the close method's behavior.

Description

In the existing implementation of the testWriterCloseIsIdempotent test, we call the close method on JsonWriter twice to check for idempotency but do not assert the outcome explicitly. This PR adds assertions to this test method to explicitly verify that the content of the StringWriter remains the same after the second call to close. This provides a clearer and more definitive confirmation of the method's idempotency. The modification aims to improve our test's expressiveness without altering the functionality of the JsonWriter class.

Changes made:

Checklist