Rename netconf-impl to netconf-server
[netconf.git] / protocol / netconf-server / src / test / java / org / opendaylight / netconf / server / util / DeserializerExceptionHandlerTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netconf.server.util;
9
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;
15
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;
22
23 public class DeserializerExceptionHandlerTest {
24     private DeserializerExceptionHandler handler;
25     private ChannelFuture channelFuture;
26     private ChannelHandlerContext context;
27     private Channel channel;
28
29     @Before
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());
38     }
39
40     @Test
41     public void testExceptionCaught() throws Exception {
42         handler.exceptionCaught(context, new Exception());
43         verify(context, times(1)).channel();
44     }
45 }