Remove DocumentedException.ErrorSeverity
[netconf.git] / netconf / netconf-impl / src / test / java / org / opendaylight / netconf / impl / mapping / operations / DefaultCloseSessionTest.java
index deddd88033b2cb765d6b9f88e285052782dc3a34..44ecfc76e3b7c2674c0ab9d11c4ccaa54649bd9f 100644 (file)
@@ -5,11 +5,12 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netconf.impl.mapping.operations;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertThrows;
 import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyObject;
 import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
@@ -40,7 +41,7 @@ public class DefaultCloseSessionTest {
         final EventLoop eventLoop = mock(EventLoop.class);
         doReturn(eventLoop).when(channel).eventLoop();
         doAnswer(invocation -> {
-            invocation.<Runnable>getArgument(0).run();
+            invocation.getArgument(0, Runnable.class).run();
             return null;
         }).when(eventLoop).execute(any(Runnable.class));
         doReturn(true).when(eventLoop).inEventLoop();
@@ -66,7 +67,7 @@ public class DefaultCloseSessionTest {
             return null;
         }).when(sendFuture).addListener(any(GenericFutureListener.class));
         doReturn(sendFuture).when(channel).newPromise();
-        doReturn(sendFuture).when(channel).writeAndFlush(anyObject(), anyObject());
+        doReturn(sendFuture).when(channel).writeAndFlush(any(), any());
         doReturn(true).when(sendFuture).isSuccess();
         final NetconfServerSessionListener listener = mock(NetconfServerSessionListener.class);
         doNothing().when(listener).onSessionTerminated(any(NetconfServerSession.class),
@@ -85,12 +86,17 @@ public class DefaultCloseSessionTest {
         verify(listener).onSessionTerminated(any(NetconfServerSession.class), any(NetconfTerminationReason.class));
     }
 
-    @Test(expected = DocumentedException.class)
+    @Test
     public void testDefaultCloseSession2() throws Exception {
-        AutoCloseable res = mock(AutoCloseable.class);
-        doThrow(NetconfDocumentedException.class).when(res).close();
-        DefaultCloseSession session = new DefaultCloseSession("", res);
+        final NetconfDocumentedException expectedCause = new NetconfDocumentedException("testMessage");
+        final AutoCloseable res = mock(AutoCloseable.class);
+        doThrow(expectedCause).when(res).close();
+        final DefaultCloseSession session = new DefaultCloseSession("testSession", res);
         XmlElement elem = XmlElement.fromDomElement(XmlUtil.readXmlToElement("<elem/>"));
-        session.handleWithNoSubsequentOperations(XmlUtil.newDocument(), elem);
+
+        final DocumentedException ex = assertThrows(DocumentedException.class,
+            () -> session.handleWithNoSubsequentOperations(XmlUtil.newDocument(), elem));
+        assertEquals("Unable to properly close session testSession", ex.getMessage());
+        assertSame(expectedCause, ex.getCause());
     }
 }