2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.netconf.impl.util;
11 import static org.mockito.Mockito.any;
12 import static org.mockito.Mockito.anyObject;
13 import static org.mockito.Mockito.doReturn;
14 import static org.mockito.Mockito.mock;
15 import static org.mockito.Mockito.times;
16 import static org.mockito.Mockito.verify;
18 import io.netty.channel.Channel;
19 import io.netty.channel.ChannelFuture;
20 import io.netty.channel.ChannelHandlerContext;
21 import io.netty.util.concurrent.GenericFutureListener;
22 import org.junit.Before;
23 import org.junit.Test;
25 public class DeserializerExceptionHandlerTest {
27 private DeserializerExceptionHandler handler;
28 private ChannelFuture channelFuture;
29 private ChannelHandlerContext context;
30 private Channel channel;
33 public void setUp() throws Exception {
34 handler = new DeserializerExceptionHandler();
35 context = mock(ChannelHandlerContext.class);
36 channel = mock(Channel.class);
37 doReturn(channel).when(context).channel();
38 channelFuture = mock(ChannelFuture.class);
39 doReturn(channelFuture).when(channelFuture).addListener(any(GenericFutureListener.class));
40 doReturn(channelFuture).when(channel).writeAndFlush(anyObject());
44 public void testExceptionCaught() throws Exception {
45 handler.exceptionCaught(context, new Exception());
46 verify(context, times(1)).channel();