Add unit tests for ByteArrayBuffer extension functions#251
Conversation
There was a problem hiding this comment.
Pull request overview
Adds unit test coverage for ByteArrayBuffer extension functions in core to ensure serialization/deserialization and buffer helpers behave as expected (per #119).
Changes:
- Introduced
ByteArrayBufferTestcoveringputValue,getValue,getValueOrNull,hasRemaining, andByteArray.buffer(). - Added parameterized coverage across multiple primitive types and ordering modes (ASC/DESC).
- Added assertions for null-handling behavior and ASC vs DESC byte differences.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| buffer.setPosition(0) | ||
|
|
||
| assertTrue(buffer.hasRemaining()) | ||
| } | ||
|
|
There was a problem hiding this comment.
hasRemaining should return true when data exists is currently a vacuous assertion: after ByteArray(BUFFER_SIZE).buffer() and setPosition(0), remaining is still BUFFER_SIZE, so hasRemaining() would be true even if nothing had been written. Consider asserting on a read-buffer created from buffer.toByteArray().buffer() (so length reflects bytes actually written), and/or add a separate case like ByteArray(0).buffer() to verify hasRemaining() is false for an empty buffer.
| buffer.setPosition(0) | |
| assertTrue(buffer.hasRemaining()) | |
| } | |
| val writtenBytes = buffer.toByteArray() | |
| val readBuffer = writtenBytes.buffer() | |
| assertTrue(readBuffer.hasRemaining()) | |
| } | |
| @Test | |
| fun `hasRemaining should return false for empty buffer`() { | |
| val buffer = ByteArray(0).buffer() | |
| assertFalse(buffer.hasRemaining()) | |
| } |
There was a problem hiding this comment.
@kimsunho2000
The current assertion is vacuous — since the buffer is backed by ByteArray(BUFFER_SIZE), remaining is always BUFFER_SIZE after setPosition(0) regardless of what was written. Consider switching to buffer.toByteArray().buffer() so the assertion actually reflects bytes written.
Also, if the intent was to cover the empty-buffer case, it might be worth adding a separate test like ByteArray(0).buffer() to explicitly verify hasRemaining() returns false.
|
@zipdoki Please review when you get a chance. |
| type: double | ||
| value: "3.14159" | ||
| """ | ||
| } |
There was a problem hiding this comment.
@kimsunho2000
nit: two small consistency things — indent the YAML to match the @ObjectSource style used in EdgeStateMapperTest, and add byte/short to cover the uncovered serialize paths.
|
Thanks for the review! @zipdoki I'll update the code and push it soon. |
|
@zipdoki
Also, I added one more test beyond the issue requirements:
Please let me know if there's anything else to improve. Thanks! |
zipdoki
left a comment
There was a problem hiding this comment.
@kimsunho2000
LGTM 👍
Thanks for your continued contributions!
Summary
Add unit tests for
ByteArrayBufferextension functions defined inByteArrayBuffer.kt.Closes #119
Changes
ByteArrayBufferTest.ktatcore/src/test/kotlin/com/kakao/actionbase/core/codec/Test Plan
putValue and getValue should round trip in ascending orderputValue and getValue should round trip in descending ordergetValue should throw IllegalStateException when value is nullgetValueOrNull should return null when value is nullhasRemaining should return true when data existshasRemaining should return false after data is consumedhasRemaining should return false for empty bufferbuffer should create ByteArrayBuffer from ByteArrayputValue should produce different bytes for asc and desc orderputValue and getValue should maintain order for multiple valuesHow to Test
./gradlew spotlessApply
./gradlew :core:test