@Test
 public void closeWithExceptionWhenWritingAndClosing() throws IOException {
   MockSink mockSink = new MockSink();
   mockSink.scheduleThrow(0, new IOException("first"));
   mockSink.scheduleThrow(1, new IOException("second"));
   BufferedSink bufferedSink = new RealBufferedSink(mockSink);
   bufferedSink.writeByte('a');
   try {
     bufferedSink.close();
     fail();
   } catch (IOException expected) {
     assertEquals("first", expected.getMessage());
   }
   mockSink.assertLog("write([text=a], 1)", "close()");
 }
 @Test
 public void closeWithExceptionWhenClosing() throws IOException {
   MockSink mockSink = new MockSink();
   mockSink.scheduleThrow(1, new IOException());
   BufferedSink bufferedSink = new RealBufferedSink(mockSink);
   bufferedSink.writeByte('a');
   try {
     bufferedSink.close();
     fail();
   } catch (IOException expected) {
   }
   mockSink.assertLog("write([text=a], 1)", "close()");
 }