ChannelAcceptor acceptor3 = EasyMock.createMock( ChannelAcceptor.class );
// Scenario 1:
// 1) Add acceptor 1, deny connection
acceptor1.newChannel( null, null, "A" );
EasyMock.expectLastCall().andThrow( new ChannelRejectedException() );
EasyMock.replay( acceptor1, acceptor2, acceptor3 );
main_acceptor.addDelegate( acceptor1 );
try {
main_acceptor.newChannel( null, null, "A" );
fail( "Shouldn't have worked" );
}
catch( ChannelRejectedException ex ) {
// Expected
}
EasyMock.verify( acceptor1, acceptor2, acceptor3 );
// Scenario 2:
// 1) Add acceptor 2 (to end)
// 2) Acceptor 1 will deny connection
// 2) Acceptor 2 will approve connection
EasyMock.reset( acceptor1, acceptor2, acceptor3 );
acceptor1.newChannel( null, null, "B" );
EasyMock.expectLastCall().andThrow( new ChannelRejectedException() );
acceptor2.newChannel( null, null, "B" );
EasyMock.replay( acceptor1, acceptor2, acceptor3 );
main_acceptor.addDelegate( acceptor2 );