@Test
public void loop_decode_twice() {

    // prepare
    IoSession session = mock(IoSession.class);
    ByteBuffer buff = ByteBuffer.wrap("test".getBytes());
    Object decodingState = new Object();
    when(session.getAttribute(new AttributeKey<Object>(Object.class, "internal_decoder")))
            .thenReturn(decodingState);
    Object decoded = new Object();
    when(decoder.decode(buff, decodingState)).thenReturn(decoded).thenReturn(decoded).thenReturn(null);
    ReadFilterChainController ctrl = mock(ReadFilterChainController.class);
    // run
    filter.messageReceived(session, buff, ctrl);
    // verify
    verify(decoder, times(3)).decode(buff, decodingState);
    verify(ctrl, times(2)).callReadNextFilter(decoded);
    verify(session).getAttribute(new AttributeKey<Object>(Object.class, "internal_decoder"));
    verifyNoMoreInteractions(encoder, decoder, session, ctrl);
}