### Question:
LineBasedFrameDecoder extends ByteToMessageDecoder { private void fail(final ChannelHandlerContext ctx, int length) { fail(ctx, String.valueOf(length)); } LineBasedFrameDecoder(final int maxLength);  LineBasedFrameDecoder(final int maxLength, final boolean stripDelimiter, final boolean failFast);   }### Answer:
@Test public void testNotFailFast() throws Exception { EmbeddedChannel ch = new EmbeddedChannel(new LineBasedFrameDecoder(2, false, false)); assertFalse(ch.writeInbound(wrappedBuffer(new byte[] { 0, 1, 2 }))); assertFalse(ch.writeInbound(wrappedBuffer(new byte[]{ 3, 4 }))); try { ch.writeInbound(wrappedBuffer(new byte[] { '\n' })); fail(); } catch (TooLongFrameException expected) { } assertFalse(ch.writeInbound(wrappedBuffer(new byte[] { '5' }))); assertTrue(ch.writeInbound(wrappedBuffer(new byte[] { '\n' }))); ByteBuf expected = wrappedBuffer(new byte[] { '5', '\n' }); ByteBuf buffer = ch.readInbound(); assertEquals(expected, buffer); expected.release(); buffer.release(); assertFalse(ch.finish()); }
@Test public void testTooLongLine1() throws Exception { EmbeddedChannel ch = new EmbeddedChannel(new LineBasedFrameDecoder(16, false, false)); try { ch.writeInbound(copiedBuffer("12345678901234567890\r\nfirst\nsecond", CharsetUtil.US_ASCII)); fail(); } catch (Exception e) { assertThat(e, is(instanceOf(TooLongFrameException.class))); } assertThat(releaseLater((ByteBuf) ch.readInbound()), is(releaseLater(copiedBuffer("first\n", CharsetUtil.US_ASCII)))); assertThat(ch.finish(), is(false)); }
@Test public void testTooLongLine2() throws Exception { EmbeddedChannel ch = new EmbeddedChannel(new LineBasedFrameDecoder(16, false, false)); assertFalse(ch.writeInbound(copiedBuffer("12345678901234567", CharsetUtil.US_ASCII))); try { ch.writeInbound(copiedBuffer("890\r\nfirst\r\n", CharsetUtil.US_ASCII)); fail(); } catch (Exception e) { assertThat(e, is(instanceOf(TooLongFrameException.class))); } assertThat(releaseLater((ByteBuf) ch.readInbound()), is(releaseLater(copiedBuffer("first\r\n", CharsetUtil.US_ASCII)))); assertThat(ch.finish(), is(false)); }
@Test public void testTooLongLineWithFailFast() throws Exception { EmbeddedChannel ch = new EmbeddedChannel(new LineBasedFrameDecoder(16, false, true)); try { ch.writeInbound(copiedBuffer("12345678901234567", CharsetUtil.US_ASCII)); fail(); } catch (Exception e) { assertThat(e, is(instanceOf(TooLongFrameException.class))); } assertThat(ch.writeInbound(copiedBuffer("890", CharsetUtil.US_ASCII)), is(false)); assertThat(ch.writeInbound(copiedBuffer("123\r\nfirst\r\n", CharsetUtil.US_ASCII)), is(true)); assertThat(releaseLater((ByteBuf) ch.readInbound()), is(releaseLater(copiedBuffer("first\r\n", CharsetUtil.US_ASCII)))); assertThat(ch.finish(), is(false)); }