private void fail(final ChannelHandlerContext ctx, int length) {
        fail(ctx, String.valueOf(length));
    }
@Test
    public void testTooLongLine1AndEmitLastLine() throws Exception {
        EmbeddedChannel ch = new EmbeddedChannel(new LenientLineBasedFrameDecoder(16, false, false, true));

        try {
            ch.writeInbound(copiedBuffer("12345678901234567890\r\nfirst\nsecond", CharsetUtil.US_ASCII));
            fail();
        } catch (Exception e) {
            assertThat(e, is(instanceOf(TooLongFrameException.class)));
        }

        ByteBuf buf = ch.readInbound();
        ByteBuf expectedBuf = copiedBuffer("first\n", CharsetUtil.US_ASCII);
        assertThat(buf, is(expectedBuf));

        // Close channel
        assertTrue(ch.finish());

        ByteBuf buf2 = ch.readInbound();
        ByteBuf expectedBuf2 = copiedBuffer("second", CharsetUtil.US_ASCII);

        assertThat(buf2, is(expectedBuf2));
        assertThat(ch.finish(), is(false));

        buf.release();
        expectedBuf.release();
        buf2.release();
        expectedBuf2.release();
    }