* @return The mocked ChannelHandlerContext
*/
@SuppressWarnings("unchecked")
private ChannelHandlerContext mockChannelHandlerContext(
final AlternativeCompositeByteBuf buf, final AtomicReference<Message> m2) {
ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
ByteBufAllocator alloc = mock(ByteBufAllocator.class);
when(ctx.alloc()).thenReturn(alloc);
when(alloc.ioBuffer()).thenReturn(buf);
DatagramChannel dc = mock(DatagramChannel.class);
when(ctx.channel()).thenReturn(dc);
when(ctx.writeAndFlush(any(), any(ChannelPromise.class))).thenReturn(
null);
Attribute<InetSocketAddress> attr = mock(Attribute.class);
when(ctx.attr(any(AttributeKey.class))).thenReturn(attr);
when(ctx.fireChannelRead(any())).then(new Answer<Void>() {
@Override
public Void answer(final InvocationOnMock invocation)
throws Throwable {
Object[] args = invocation.getArguments();
m2.set((Message) args[0]);
return null;
}
});
when(ctx.fireExceptionCaught(any(Throwable.class))).then(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
for(Object obj:args) {