Integrate MRI projects for Neon
[netconf.git] / netconf / netconf-impl / src / test / java / org / opendaylight / netconf / impl / mapping / operations / DefaultCloseSessionTest.java
index 068ebf6eb4a3a28edb2f9f35254cdd633ec3eb0d..deddd88033b2cb765d6b9f88e285052782dc3a34 100644 (file)
@@ -8,8 +8,8 @@
 
 package org.opendaylight.netconf.impl.mapping.operations;
 
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyObject;
+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;
@@ -19,35 +19,29 @@ import static org.mockito.Mockito.verify;
 
 import io.netty.channel.Channel;
 import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelPromise;
 import io.netty.channel.EventLoop;
 import io.netty.util.concurrent.GenericFutureListener;
 import org.junit.Test;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-import org.opendaylight.controller.config.util.xml.DocumentedException;
-import org.opendaylight.controller.config.util.xml.XmlElement;
-import org.opendaylight.controller.config.util.xml.XmlUtil;
+import org.opendaylight.netconf.api.DocumentedException;
 import org.opendaylight.netconf.api.NetconfDocumentedException;
 import org.opendaylight.netconf.api.NetconfMessage;
 import org.opendaylight.netconf.api.NetconfTerminationReason;
 import org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader;
+import org.opendaylight.netconf.api.xml.XmlElement;
+import org.opendaylight.netconf.api.xml.XmlUtil;
 import org.opendaylight.netconf.impl.NetconfServerSession;
 import org.opendaylight.netconf.impl.NetconfServerSessionListener;
 import org.w3c.dom.Document;
 
 public class DefaultCloseSessionTest {
 
-    private void mockEventLoop(final Channel channel) {
+    private static void mockEventLoop(final Channel channel) {
         final EventLoop eventLoop = mock(EventLoop.class);
         doReturn(eventLoop).when(channel).eventLoop();
-        doAnswer(new Answer<Void>() {
-            @Override
-            public Void answer(InvocationOnMock invocation) throws Throwable {
-                final Object[] args = invocation.getArguments();
-                final Runnable runnable = (Runnable) args[0];
-                runnable.run();
-                return null;
-            }
+        doAnswer(invocation -> {
+            invocation.<Runnable>getArgument(0).run();
+            return null;
         }).when(eventLoop).execute(any(Runnable.class));
         doReturn(true).when(eventLoop).inEventLoop();
     }
@@ -66,15 +60,13 @@ public class DefaultCloseSessionTest {
         doReturn(channelFuture).when(channel).close();
         doReturn(channelFuture).when(channelFuture).addListener(any(GenericFutureListener.class));
 
-        final ChannelFuture sendFuture = mock(ChannelFuture.class);
-        doAnswer(new Answer<Object>() {
-            @Override
-            public Object answer(final InvocationOnMock invocation) throws Throwable {
-                ((GenericFutureListener) invocation.getArguments()[0]).operationComplete(sendFuture);
-                return null;
-            }
+        final ChannelPromise sendFuture = mock(ChannelPromise.class);
+        doAnswer(invocation -> {
+            invocation.<GenericFutureListener>getArgument(0).operationComplete(sendFuture);
+            return null;
         }).when(sendFuture).addListener(any(GenericFutureListener.class));
-        doReturn(sendFuture).when(channel).writeAndFlush(anyObject());
+        doReturn(sendFuture).when(channel).newPromise();
+        doReturn(sendFuture).when(channel).writeAndFlush(anyObject(), anyObject());
         doReturn(true).when(sendFuture).isSuccess();
         final NetconfServerSessionListener listener = mock(NetconfServerSessionListener.class);
         doNothing().when(listener).onSessionTerminated(any(NetconfServerSession.class),
@@ -98,8 +90,7 @@ public class DefaultCloseSessionTest {
         AutoCloseable res = mock(AutoCloseable.class);
         doThrow(NetconfDocumentedException.class).when(res).close();
         DefaultCloseSession session = new DefaultCloseSession("", res);
-        Document doc = XmlUtil.newDocument();
         XmlElement elem = XmlElement.fromDomElement(XmlUtil.readXmlToElement("<elem/>"));
-        session.handleWithNoSubsequentOperations(doc, elem);
+        session.handleWithNoSubsequentOperations(XmlUtil.newDocument(), elem);
     }
 }