* 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.client;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyObject;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import java.util.Set;
import org.junit.Before;
import org.junit.Test;
-import org.mockito.internal.util.collections.Sets;
-import org.opendaylight.netconf.api.NetconfDocumentedException;
import org.opendaylight.netconf.api.NetconfMessage;
import org.opendaylight.netconf.api.messages.NetconfHelloMessage;
public class SimpleNetconfClientSessionListenerTest {
-
private Channel channel;
private ChannelPromise channelFuture;
- Set<String> caps;
private NetconfHelloMessage helloMessage;
private NetconfMessage message;
private NetconfClientSessionListener sessionListener;
private NetconfClientSession clientSession;
@Before
- public void setUp() throws NetconfDocumentedException {
+ public void setUp() {
channel = mock(Channel.class);
channelFuture = mock(ChannelPromise.class);
mockEventLoop();
doReturn(channelFuture).when(channel).newPromise();
- doReturn(channelFuture).when(channel).writeAndFlush(anyObject());
- doReturn(channelFuture).when(channel).writeAndFlush(anyObject(), any(ChannelPromise.class));
+ doReturn(channelFuture).when(channel).writeAndFlush(any());
+ doReturn(channelFuture).when(channel).writeAndFlush(any(), any(ChannelPromise.class));
doReturn(channelFuture).when(channelFuture).addListener(any(GenericFutureListener.class));
- caps = Sets.newSet("a", "b");
+ final var caps = Set.of("a", "b");
helloMessage = NetconfHelloMessage.createServerHello(caps, 10);
message = new NetconfMessage(helloMessage.getDocument());
sessionListener = mock(NetconfClientSessionListener.class);
}
@Test
- public void testSessionDown() throws Exception {
+ public void testSessionDown() {
SimpleNetconfClientSessionListener simpleListener = new SimpleNetconfClientSessionListener();
final Future<NetconfMessage> promise = simpleListener.sendRequest(message);
simpleListener.onSessionUp(clientSession);
- verify(channel, times(1)).writeAndFlush(anyObject(), anyObject());
+ verify(channel, times(1)).writeAndFlush(any(), any());
simpleListener.onSessionDown(clientSession, new Exception());
assertFalse(promise.isSuccess());
SimpleNetconfClientSessionListener simpleListener = new SimpleNetconfClientSessionListener();
final Future<NetconfMessage> promise = simpleListener.sendRequest(message);
simpleListener.onSessionUp(clientSession);
- verify(channel, times(1)).writeAndFlush(anyObject(), anyObject());
+ verify(channel, times(1)).writeAndFlush(any(), any());
simpleListener.sendRequest(message);
assertFalse(promise.isSuccess());
SimpleNetconfClientSessionListener simpleListener = new SimpleNetconfClientSessionListener();
final Future<NetconfMessage> promise = simpleListener.sendRequest(message);
simpleListener.onSessionUp(clientSession);
- verify(channel, times(1)).writeAndFlush(anyObject(), anyObject());
+ verify(channel, times(1)).writeAndFlush(any(), any());
simpleListener.onMessage(clientSession, message);
assertTrue(promise.isSuccess());