private static void assertWriteFails(ChannelHandler handler, int count) {
    final ByteBuf buffer = Unpooled.copiedBuffer("Test", CharsetUtil.US_ASCII);
    final EmbeddedChannel channel = new EmbeddedChannel(handler);
    ByteBuf[] buffers = new ByteBuf[count];
    for (int i = 0; i < buffers.length; i++) {
      buffers[i] = buffer.duplicate().retain();
    }
    try {
      Assert.assertFalse(channel.writeOutbound(buffers));
      Assert.fail();
    } catch (Exception e) {
      Assert.assertTrue(e instanceof TestException);
    }
    Assert.assertFalse(channel.finish());
    channel.closeFuture().syncUninterruptibly();

    buffer.release();
    Assert.assertNull(channel.readOutbound());
  }
  private static void assertWrite(ChannelHandler handler, int count) {
    final ByteBuf buffer = Unpooled.copiedBuffer("Test", CharsetUtil.US_ASCII);
    final EmbeddedChannel channel = new EmbeddedChannel(handler);
    channel.config().setWriteBufferLowWaterMark(1);
    channel.config().setWriteBufferHighWaterMark(3);

    ByteBuf[] buffers = new ByteBuf[count];
    for (int i = 0; i < buffers.length; i++) {
      buffers[i] = buffer.duplicate().retain();
    }
    Assert.assertTrue(channel.writeOutbound(buffers));
    Assert.assertTrue(channel.finish());
    channel.closeFuture().syncUninterruptibly();

    for (int i = 0; i < buffers.length; i++) {
      assertBuffer(channel, buffer);
    }
    buffer.release();
    Assert.assertNull(channel.readOutbound());
  }