public static Writer writerForAppendable(Appendable appendable) {
    return appendable instanceof Writer ? (Writer) appendable : new AppendableWriter(appendable);
  }
@Test
  public void testWriterForAppendable() throws IOException {
    StringBuilder stringBuilder = new StringBuilder();
    Writer writer = Streams.writerForAppendable(stringBuilder);

    writer.append('a');
    writer.append('\u1234');
    writer.append("test");
    writer.append(null); // test custom null handling mandated by `append`
    writer.append("abcdef", 2, 4);
    writer.append(null, 1, 3); // test custom null handling mandated by `append`
    writer.append(',');

    writer.write('a');
    writer.write('\u1234');
    // Should only consider the 16 low-order bits
    writer.write(0x4321_1234);
    writer.append(',');

    writer.write("chars".toCharArray());
    assertThrows(NullPointerException.class, () -> writer.write((char[]) null));

    writer.write("chars".toCharArray(), 1, 2);
    assertThrows(NullPointerException.class, () -> writer.write((char[]) null, 1, 2));
    writer.append(',');

    writer.write("string");
    assertThrows(NullPointerException.class, () -> writer.write((String) null));

    writer.write("string", 1, 2);
    assertThrows(NullPointerException.class, () -> writer.write((String) null, 1, 2));

    String actualOutput = stringBuilder.toString();
    assertThat(actualOutput).isEqualTo("a\u1234testnullcdul,a\u1234\u1234,charsha,stringtr");

    writer.flush();
    writer.close();

    // flush() and close() calls should have had no effect
    assertThat(stringBuilder.toString()).isEqualTo(actualOutput);
  }