Merge "Fix checkstyle warnings in opendaylight/netconf"
[controller.git] / opendaylight / netconf / netconf-impl / src / test / java / org / opendaylight / controller / netconf / impl / mapping / operations / DefaultCloseSessionTest.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.mapping.operations;
10
11 import org.junit.Test;
12 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
13 import org.opendaylight.controller.netconf.util.xml.XmlElement;
14 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
15 import org.w3c.dom.Document;
16 import org.w3c.dom.Element;
17
18 import static org.mockito.Mockito.doNothing;
19 import static org.mockito.Mockito.doThrow;
20 import static org.mockito.Mockito.mock;
21
22 public class DefaultCloseSessionTest {
23     @Test
24     public void testDefaultCloseSession() throws Exception {
25         AutoCloseable res = mock(AutoCloseable.class);
26         doNothing().when(res).close();
27         DefaultCloseSession session = new DefaultCloseSession("", res);
28         Document doc = XmlUtil.newDocument();
29         XmlElement elem = XmlElement.fromDomElement(XmlUtil.readXmlToElement("<elem/>"));
30         session.handleWithNoSubsequentOperations(doc, elem);
31     }
32
33     @Test(expected = NetconfDocumentedException.class)
34     public void testDefaultCloseSession2() throws Exception {
35         AutoCloseable res = mock(AutoCloseable.class);
36         doThrow(NetconfDocumentedException.class).when(res).close();
37         DefaultCloseSession session = new DefaultCloseSession("", res);
38         Document doc = XmlUtil.newDocument();
39         XmlElement elem = XmlElement.fromDomElement(XmlUtil.readXmlToElement("<elem/>"));
40         session.handleWithNoSubsequentOperations(doc, elem);
41     }
42 }