Code that interacts with ByteBuffer objects could benefit a lot from an improved and dedicated ByteBuffer assertion. Typical assertions are:
String (with CharSet defaulting), byte[], ByteBuffer variantsThe assertion could also benefit from a dedicated formatter that represents the buffer in a human-readable format. Currently, we get something like:
expected value: java.nio.HeapByteBuffer[pos=0 lim=7 cap=7]; actual value: java.nio.HeapByteBuffer[pos=0 lim=7 cap=7]
And this allows no diagnosis (except when using a debugger) what happened.
ByteBuffer buf = …
assertThat(buf).equalsTo("some-string");
assertThat(buf).equalsTo("some-string", Charset.defaultCharset());
assertThat(buf).contains("some-string");
assertThat(buf).contains("some-string", Charset.defaultCharset());
assertThat(buf).starts/endsWith("some-string");
That would be valuable, I agree!
If possible I would like to take a stab at it!
Most helpful comment
If possible I would like to take a stab at it!