@Test
 public void logsPartialLineOnClose() throws IOException {
   context.checking(
       new Expectations() {
         {
           one(action).execute("line 1");
         }
       });
   outputStream.write("line 1".getBytes());
   outputStream.close();
 }
 @Test
 public void logsLineWhichIsLongerThanInitialBufferLength() throws IOException {
   context.checking(
       new Expectations() {
         {
           one(action).execute("a line longer than 8 bytes long");
           one(action).execute("line 2");
         }
       });
   outputStream.write(String.format("a line longer than 8 bytes long%n").getBytes());
   outputStream.write("line 2".getBytes());
   outputStream.close();
 }
  @Test
  public void logsEmptyLines() throws IOException {
    context.checking(
        new Expectations() {
          {
            one(action).execute("");
            one(action).execute("");
          }
        });

    outputStream.write(String.format("%n%n").getBytes());
  }
  @Test
  public void logsEachLineAsASeparateLogMessage() throws IOException {
    context.checking(
        new Expectations() {
          {
            one(action).execute("line 1");
            one(action).execute("line 2");
          }
        });

    outputStream.write(String.format("line 1%nline 2%n").getBytes());
  }
  @Test
  public void handlesMultiCharacterLineSeparator() throws IOException {
    context.checking(
        new Expectations() {
          {
            one(action).execute("line 1");
            one(action).execute("line 2");
          }
        });

    System.setProperty("line.separator", "----");
    outputStream = new TestOutputStream(8);

    outputStream.write(String.format("line 1----line 2----").getBytes());
  }
 @Test(expected = IOException.class)
 public void cannotWriteAfterClose() throws IOException {
   outputStream.close();
   outputStream.write("ignore me".getBytes());
 }