ProtocolCodecFilter extends AbstractIoFilter { @Override public void sessionOpened(IoSession session) { ENCODING_STATE encodingState = encoder.createEncoderState(); session.setAttribute(ENCODER, encodingState); DECODING_STATE decodingState = decoder.createDecoderState(); session.setAttribute(DECODER, decodingState); super.sessionOpened(session); } ProtocolCodecFilter(ProtocolEncoder<MESSAGE, ENCODED, ENCODING_STATE> encoder,
            ProtocolDecoder<ENCODED, MESSAGE, DECODING_STATE> decoder); @SuppressWarnings("unchecked") @Override void messageReceived(IoSession session, Object in, ReadFilterChainController controller); @SuppressWarnings("unchecked") @Override void messageWriting(IoSession session, WriteRequest message, WriteFilterChainController controller); @Override void sessionOpened(IoSession session); @Override void sessionClosed(IoSession session);  }
@Test public void create_states() { Object decodingState = new Object(); Object encodingState = new Object(); IoSession session = mock(IoSession.class); when(decoder.createDecoderState()).thenReturn(decodingState); when(encoder.createEncoderState()).thenReturn(encodingState); filter.sessionOpened(session); verify(decoder).createDecoderState(); verify(session).setAttribute(new AttributeKey<Object>(Object.class, "internal_decoder"), decodingState); verify(encoder).createEncoderState(); verify(session).setAttribute(new AttributeKey<Object>(Object.class, "internal_encoder"), encodingState); verifyNoMoreInteractions(encoder, decoder, session); }