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
8 package org.opendaylight.netconf.server.util;
10 import static org.mockito.ArgumentMatchers.any;
11 import static org.mockito.Mockito.doReturn;
12 import static org.mockito.Mockito.mock;
13 import static org.mockito.Mockito.times;
14 import static org.mockito.Mockito.verify;
16 import io.netty.channel.Channel;
17 import io.netty.channel.ChannelFuture;
18 import io.netty.channel.ChannelHandlerContext;
19 import io.netty.util.concurrent.GenericFutureListener;
20 import org.junit.Before;
21 import org.junit.Test;
23 public class DeserializerExceptionHandlerTest {
24 private DeserializerExceptionHandler handler;
25 private ChannelFuture channelFuture;
26 private ChannelHandlerContext context;
27 private Channel channel;
30 public void setUp() throws Exception {
31 handler = new DeserializerExceptionHandler();
32 context = mock(ChannelHandlerContext.class);
33 channel = mock(Channel.class);
34 doReturn(channel).when(context).channel();
35 channelFuture = mock(ChannelFuture.class);
36 doReturn(channelFuture).when(channelFuture).addListener(any(GenericFutureListener.class));
37 doReturn(channelFuture).when(channel).writeAndFlush(any());
41 public void testExceptionCaught() throws Exception {
42 handler.exceptionCaught(context, new Exception());
43 verify(context, times(1)).channel();