@Test public void doesntStackOverflowOnToBufferWriterBug_Overflow() {

  // pretend there was a bug calculating size, ex it calculated incorrectly as to small
  class FooWriter implements WriteBuffer.Writer {
    @Override public int sizeInBytes(Object value) {
      return 2;
    }
    @Override public void write(Object value, WriteBuffer buffer) {
      buffer.writeByte('a');
      buffer.writeByte('b');
      buffer.writeByte('c'); // wrote larger than size!
    }
  }
  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 2/2 bytes: ab");
}