Merge "Netconf-cli compilable and included in project"
[controller.git] / opendaylight / netconf / netconf-impl / src / test / java / org / opendaylight / controller / netconf / impl / 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
9 package org.opendaylight.controller.netconf.impl.util;
10
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;
17
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;
24
25 public class DeserializerExceptionHandlerTest {
26
27     private DeserializerExceptionHandler handler;
28     private ChannelFuture channelFuture;
29     private ChannelHandlerContext context;
30     private Channel channel;
31
32     @Before
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());
41     }
42
43     @Test
44     public void testExceptionCaught() throws Exception {
45         handler.exceptionCaught(context, new Exception());
46         verify(context, times(1)).channel();
47     }
48 }