@Test
public void testAggregate() {

    HttpObjectAggregator aggr = new HttpObjectAggregator(1024 * 1024);
    EmbeddedChannel embedder = new EmbeddedChannel(aggr);
    HttpRequest message = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost");
    message.headers().set(of("X-Test"), true);
    HttpContent chunk1 = new DefaultHttpContent(Unpooled.copiedBuffer("test", CharsetUtil.US_ASCII));
    HttpContent chunk2 = new DefaultHttpContent(Unpooled.copiedBuffer("test2", CharsetUtil.US_ASCII));
    HttpContent chunk3 = new DefaultLastHttpContent(Unpooled.EMPTY_BUFFER);
    assertFalse(embedder.writeInbound(message));
    assertFalse(embedder.writeInbound(chunk1));
    assertFalse(embedder.writeInbound(chunk2));
    // this should trigger a channelRead event so return true
    assertTrue(embedder.writeInbound(chunk3));
    assertTrue(embedder.finish());
    FullHttpRequest aggregatedMessage = embedder.readInbound();
    assertNotNull(aggregatedMessage);
    assertEquals(chunk1.content().readableBytes() + chunk2.content().readableBytes(),
            HttpUtil.getContentLength(aggregatedMessage));
    assertEquals(Boolean.TRUE.toString(), aggregatedMessage.headers().get(of("X-Test")));
    checkContentBuffer(aggregatedMessage);
    assertNull(embedder.readInbound());
}