### Question:
ClientSessionHandler extends AbstractSessionHandler { @Override public void channelActive(ChannelHandlerContext ctx) { getLogger().info("Connection established, starting Client FIX session."); FixSession pendingSession = createSession(sessionSettingsProvider); setSession(ctx, pendingSession); FixMessageBuilder logonRequest = createLogonRequest(pendingSession, sessionSettingsProvider); prepareMessageToSend(ctx, pendingSession, logonRequest); getLogger().info("Sending Logon: {}", logonRequest); ctx.writeAndFlush(logonRequest); } protected  ClientSessionHandler(FixSessionSettingsProvider settingsProvider,
                                   AuthenticationProvider authenticationProvider,
                                   MessageSequenceProvider messageSequenceProvider,
                                   FixApplication fixApplication); @Override void channelActive(ChannelHandlerContext ctx);  }### Answer:
@Test public void testChannelActiveNoAuthentication() throws Exception { when(authenticationProvider.getPasswordAuthentication()).thenReturn(null); handler.channelActive(ctx); verify(ctx).writeAndFlush(messageCaptor.capture()); FixMessageBuilderImpl messageBuilder = messageCaptor.getValue(); FixMessageHeader header = messageBuilder.getHeader(); verify(fixApplication).beforeSendMessage(same(ctx), same(messageBuilder)); assertEquals("LOGON expected", MessageTypes.LOGON, header.getMessageType()); assertEquals(outMsgSeqNum, header.getMsgSeqNum()); assertTrue(header.getSendingTime().toInstant().toEpochMilli() > 0); assertThat("HeartBtInt", messageBuilder.getInt(FieldType.HeartBtInt), is(heartbeartInterval)); assertThat("EncryptMethod", messageBuilder.getInt(FieldType.EncryptMethod), is(0)); assertThat("Username", messageBuilder.getString(FieldType.Username), nullValue()); assertThat("Password", messageBuilder.getString(FieldType.Password), nullValue()); }
@Test public void testChannelActiveWithAuthentication() throws Exception { handler.channelActive(ctx); verify(ctx).writeAndFlush(messageCaptor.capture()); FixMessageBuilderImpl messageBuilder = messageCaptor.getValue(); FixMessageHeader header = messageBuilder.getHeader(); verify(fixApplication).beforeSendMessage(same(ctx), same(messageBuilder)); assertEquals("LOGON expected", MessageTypes.LOGON, header.getMessageType()); assertEquals(outMsgSeqNum, header.getMsgSeqNum()); assertTrue(header.getSendingTime().toInstant().toEpochMilli() > 0); assertThat("HeartBtInt", messageBuilder.getInt(FieldType.HeartBtInt), is(heartbeartInterval)); assertThat("EncryptMethod", messageBuilder.getInt(FieldType.EncryptMethod), is(0)); assertThat("Username", messageBuilder.getString(FieldType.Username), is(userName)); assertThat("Password", messageBuilder.getString(FieldType.Password), is(password)); }