package org.opendaylight.netconf.nettyutil;
import static org.junit.Assert.assertEquals;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyString;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelPipeline;
+import io.netty.channel.ChannelPromise;
import io.netty.channel.EventLoop;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.MessageToByteEncoder;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
import org.opendaylight.netconf.api.NetconfMessage;
import org.opendaylight.netconf.api.NetconfSessionListener;
import org.opendaylight.netconf.api.NetconfTerminationReason;
import org.opendaylight.netconf.api.messages.NetconfHelloMessage;
-import org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader;
import org.opendaylight.netconf.nettyutil.handler.exi.EXIParameters;
import org.opendaylight.netconf.nettyutil.handler.exi.NetconfStartExiMessage;
@Mock
private EventLoop eventLoop;
@Mock
- private ChannelFuture writeFuture;
+ private ChannelPromise writeFuture;
private NetconfHelloMessage clientHello;
doReturn(writeFuture).when(writeFuture).addListener(any(GenericFutureListener.class));
+ doReturn(writeFuture).when(channel).newPromise();
doReturn(writeFuture).when(channel).writeAndFlush(any(NetconfMessage.class));
+ doReturn(writeFuture).when(channel).writeAndFlush(any(NetconfMessage.class), any(ChannelPromise.class));
doReturn(pipeline).when(channel).pipeline();
doReturn("mockChannel").when(channel).toString();
doReturn(mock(ChannelFuture.class)).when(channel).close();
doReturn(null).when(pipeline).replace(anyString(), anyString(), any(ChannelHandler.class));
doReturn(eventLoop).when(channel).eventLoop();
- doAnswer(new Answer<Void>() {
- @Override
- public Void answer(final 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));
- clientHello = NetconfHelloMessage.createClientHello(Collections.<String>emptySet(),
- Optional.<NetconfHelloMessageAdditionalHeader>absent());
+ clientHello = NetconfHelloMessage.createClientHello(Collections.emptySet(), Optional.absent());
}
@Test
@Test
public void testSendMessage() throws Exception {
final TestingNetconfSession testingNetconfSession = new TestingNetconfSession(listener, channel, 1L);
- final NetconfHelloMessage hello = NetconfHelloMessage.createClientHello(Collections.<String>emptySet(),
- Optional.<NetconfHelloMessageAdditionalHeader>absent());
+ final NetconfHelloMessage hello = NetconfHelloMessage.createClientHello(Collections.emptySet(),
+ Optional.absent());
testingNetconfSession.sendMessage(hello);
- verify(channel).writeAndFlush(hello);
+ verify(channel).writeAndFlush(hello, writeFuture);
}
}