package org.opendaylight.netconf.callhome.mount;
import static org.junit.Assert.assertNotNull;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import io.netty.util.concurrent.Promise;
+import com.google.common.net.InetAddresses;
import java.net.Inet4Address;
-import java.net.InetAddress;
import java.net.InetSocketAddress;
-import java.net.UnknownHostException;
import org.junit.Before;
import org.junit.Test;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
import org.opendaylight.netconf.api.NetconfMessage;
import org.opendaylight.netconf.api.NetconfTerminationReason;
import org.opendaylight.netconf.callhome.protocol.CallHomeChannelActivator;
import org.opendaylight.netconf.client.NetconfClientSession;
import org.opendaylight.netconf.client.NetconfClientSessionListener;
-
public class CallHomeMountSessionContextTest {
private Inet4Address someAddressIpv4;
private InetSocketAddress someSocketAddress;
private CallHomeProtocolSessionContext mockProtocol;
@Before
- public void setup() throws UnknownHostException {
- someAddressIpv4 = (Inet4Address) InetAddress.getByName("1.2.3.4");
+ public void setup() {
+ someAddressIpv4 = (Inet4Address) InetAddresses.forString("1.2.3.4");
someSocketAddress = new InetSocketAddress(someAddressIpv4, 123);
mockProtocol = mock(CallHomeProtocolSessionContext.class);
public void activationOfListenerSupportsSessionUp() {
// given
when(mockActivator.activate(any(NetconfClientSessionListener.class)))
- .thenAnswer(invocationOnMock -> {
- NetconfClientSession mockSession = mock(NetconfClientSession.class);
+ .thenAnswer(invocationOnMock -> {
+ NetconfClientSession mockSession = mock(NetconfClientSession.class);
- Object arg = invocationOnMock.getArguments()[0];
- ((NetconfClientSessionListener) arg).onSessionUp(mockSession);
- return null;
- });
+ Object arg = invocationOnMock.getArguments()[0];
+ ((NetconfClientSessionListener) arg).onSessionUp(mockSession);
+ return null;
+ });
NetconfClientSessionListener mockListener = mock(NetconfClientSessionListener.class);
// when
// given
when(mockActivator.activate(any(NetconfClientSessionListener.class)))
.thenAnswer(invocationOnMock -> {
- NetconfClientSession mockSession = mock(NetconfClientSession.class);
- NetconfTerminationReason mockReason = mock(NetconfTerminationReason.class);
+ NetconfClientSession mockSession = mock(NetconfClientSession.class);
+ NetconfTerminationReason mockReason = mock(NetconfTerminationReason.class);
- Object arg = invocationOnMock.getArguments()[0];
- ((NetconfClientSessionListener) arg).onSessionTerminated(mockSession, mockReason);
- return null;
- });
+ Object arg = invocationOnMock.getArguments()[0];
+ ((NetconfClientSessionListener) arg).onSessionTerminated(mockSession, mockReason);
+ return null;
+ });
NetconfClientSessionListener mockListener = mock(NetconfClientSessionListener.class);
// when
// given
when(mockActivator.activate(any(NetconfClientSessionListener.class)))
.thenAnswer(invocationOnMock -> {
- NetconfClientSession mockSession = mock(NetconfClientSession.class);
- Exception mockException = mock(Exception.class);
+ NetconfClientSession mockSession = mock(NetconfClientSession.class);
+ Exception mockException = mock(Exception.class);
- Object arg = invocationOnMock.getArguments()[0];
- ((NetconfClientSessionListener) arg).onSessionDown(mockSession, mockException);
- return null;
- });
+ Object arg = invocationOnMock.getArguments()[0];
+ ((NetconfClientSessionListener) arg).onSessionDown(mockSession, mockException);
+ return null;
+ });
// given
NetconfClientSessionListener mockListener = mock(NetconfClientSessionListener.class);
// when
mockActivator.activate(mockListener);
// then
- verify(mockListener, times(1)).onSessionDown(any(NetconfClientSession.class), any(Exception.class));
+ verify(mockListener, times(1)).onSessionDown(any(NetconfClientSession.class),
+ any(Exception.class));
}
@Test
// given
when(mockActivator.activate(any(NetconfClientSessionListener.class)))
.thenAnswer(invocationOnMock -> {
- NetconfClientSession mockSession = mock(NetconfClientSession.class);
- NetconfMessage mockMsg = mock(NetconfMessage.class);
+ NetconfClientSession mockSession = mock(NetconfClientSession.class);
+ NetconfMessage mockMsg = mock(NetconfMessage.class);
- Object arg = invocationOnMock.getArguments()[0];
- ((NetconfClientSessionListener) arg).onMessage(mockSession, mockMsg);
- return null;
- });
+ Object arg = invocationOnMock.getArguments()[0];
+ ((NetconfClientSessionListener) arg).onMessage(mockSession, mockMsg);
+ return null;
+ });
// given
NetconfClientSessionListener mockListener = mock(NetconfClientSessionListener.class);
// when
mockActivator.activate(mockListener);
// then
- verify(mockListener, times(1)).onMessage(any(NetconfClientSession.class), any(NetconfMessage.class));
+ verify(mockListener, times(1)).onMessage(any(NetconfClientSession.class),
+ any(NetconfMessage.class));
}
}