@Test public void doesntStackOverflowOnToBufferWriterBug_lessThanBytes() {

  class FooWriter implements WriteBuffer.Writer<Object> {
    @Override public int sizeInBytes(Object value) {
      return 2;
    }
    @Override public void write(Object value, WriteBuffer buffer) {
      buffer.writeByte('a');
      throw new RuntimeException("buggy");
    }
  }
  class Foo {
    @Override public String toString() {
      return new String(JsonWriter.write(new FooWriter(), this), UTF_8);
    }
  }
  Foo foo = new Foo();
  assertThatThrownBy(foo::toString)
      .isInstanceOf(AssertionError.class)
      .hasMessage("Bug found using FooWriter to write Foo as json. Wrote 1/2 bytes: a");
}