Improve callhome-protocol unit tests 92/102292/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 5 Sep 2022 15:50:12 +0000 (17:50 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 5 Sep 2022 16:11:38 +0000 (18:11 +0200)
Do not mix Mockito references -- just use static imports. Also use
assertThrows() instead of Test(expected).

Change-Id: I3734828f3322665f330f9460042638adfbf7f3f5
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/callhome-protocol/src/test/java/org/opendaylight/netconf/callhome/protocol/AuthorizedKeysDecoderTest.java
netconf/callhome-protocol/src/test/java/org/opendaylight/netconf/callhome/protocol/CallHomeAuthorizationTest.java
netconf/callhome-protocol/src/test/java/org/opendaylight/netconf/callhome/protocol/CallHomeSessionContextTest.java
netconf/callhome-protocol/src/test/java/org/opendaylight/netconf/callhome/protocol/MinaSshNettyChannelTest.java
netconf/callhome-protocol/src/test/java/org/opendaylight/netconf/callhome/protocol/NetconfCallHomeServerTest.java

index a085b490194b05146b26d38a34fe8c89f22b21ae..1957d4dbcbf7f8f9f0414798b9533aa8b3d959ac 100644 (file)
  * 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.callhome.protocol;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
 
-import java.security.GeneralSecurityException;
-import java.security.PublicKey;
-import org.junit.Before;
 import org.junit.Test;
 
 public class AuthorizedKeysDecoderTest {
+    private final AuthorizedKeysDecoder instance = new AuthorizedKeysDecoder();
 
-    private AuthorizedKeysDecoder instance;
-
-    @Before
-    public void setup() {
-        instance = new AuthorizedKeysDecoder();
-    }
-
-    @SuppressWarnings("checkstyle:lineLength")
     @Test
-    public void authorizedKeysDecoderValidRSAKey() throws GeneralSecurityException {
+    public void authorizedKeysDecoderValidRSAKey() throws Exception {
         // given
-        String rsaStr = "AAAAB3NzaC1yc2EAAAADAQABAAABAQCvLigTfPZMqOQwHp051Co4lwwPwO21NFIXWgjQmCPEgRTqQpei7qQaxlLGkrIPjZtJQRgCuC+Sg8HFw1YpUaMybN0nFInInQLp/qe0yc9ByDZM2G86NX6W5W3+j87I8Fh1dnMov1iJ0DFVn8RLwdEGjreiZCRyJOMuHghh6y4EG7W8BwmZrse17zhSpc2wFOVhxeZnYAQFEw6g48LutFRDpoTjGgz1nz/L4zcaUxxigs8wdY+qTTOHxSTxlLqwSZPFLyYrV2KJ9mKahMuYUy6o2b8snsjvnSjyK0kY+U0C6c8fmPDFUc0RqJqfdnsIUyh11U8d3NZdaFWg0UW0SNK3";
+        final var rsaStr = "AAAAB3NzaC1yc2EAAAADAQABAAABAQCvLigTfPZMqOQwHp051Co4lwwPwO21NFIXWgjQmCPEgRTqQpe"
+                         + "i7qQaxlLGkrIPjZtJQRgCuC+Sg8HFw1YpUaMybN0nFInInQLp/qe0yc9ByDZM2G86NX6W5W3+j87I8F"
+                         + "h1dnMov1iJ0DFVn8RLwdEGjreiZCRyJOMuHghh6y4EG7W8BwmZrse17zhSpc2wFOVhxeZnYAQFEw6g4"
+                         + "8LutFRDpoTjGgz1nz/L4zcaUxxigs8wdY+qTTOHxSTxlLqwSZPFLyYrV2KJ9mKahMuYUy6o2b8snsjv"
+                         + "nSjyK0kY+U0C6c8fmPDFUc0RqJqfdnsIUyh11U8d3NZdaFWg0UW0SNK3";
         // when
-        PublicKey serverKey = instance.decodePublicKey(rsaStr);
+        final var serverKey = instance.decodePublicKey(rsaStr);
         // then
-        assertEquals(serverKey.getAlgorithm(), "RSA");
+        assertEquals("RSA", serverKey.getAlgorithm());
     }
 
-    @SuppressWarnings("checkstyle:lineLength")
-    @Test(expected = Exception.class)
-    public void authorizedKeysDecoderInvalidRSAKey() throws GeneralSecurityException {
+    @Test
+    public void authorizedKeysDecoderInvalidRSAKey() {
         // given
-        String rsaStr = "AAAB3NzaC1yc2EAAAADAQABAAABAQCvLigTfPZMqOQwHp051Co4lwwPwO21NFIXWgjQmCPEgRTqQpei7qQaxlLGkrIPjZtJQRgCuC+Sg8HFw1YpUaMybN0nFInInQLp/qe0yc9ByDZM2G86NX6W5W3+j87I8Fh1dnMov1iJ0DFVn8RLwdEGjreiZCRyJOMuHghh6y4EG7W8BwmZrse17zhSpc2wFOVhxeZnYAQFEw6g48LutFRDpoTjGgz1nz/L4zcaUxxigs8wdY+qTTOHxSTxlLqwSZPFLyYrV2KJ9mKahMuYUy6o2b8snsjvnSjyK0kY+U0C6c8fmPDFUc0RqJqfdnsIUyh11U8d3NZdaFWg0UW0SNK3";
+        final var rsaStr = "AAAB3NzaC1yc2EAAAADAQABAAABAQCvLigTfPZMqOQwHp051Co4lwwPwO21NFIXWgjQmCPEgRTqQpei"
+                         + "7qQaxlLGkrIPjZtJQRgCuC+Sg8HFw1YpUaMybN0nFInInQLp/qe0yc9ByDZM2G86NX6W5W3+j87I8Fh"
+                         + "1dnMov1iJ0DFVn8RLwdEGjreiZCRyJOMuHghh6y4EG7W8BwmZrse17zhSpc2wFOVhxeZnYAQFEw6g48"
+                         + "LutFRDpoTjGgz1nz/L4zcaUxxigs8wdY+qTTOHxSTxlLqwSZPFLyYrV2KJ9mKahMuYUy6o2b8snsjvn"
+                         + "SjyK0kY+U0C6c8fmPDFUc0RqJqfdnsIUyh11U8d3NZdaFWg0UW0SNK3";
         // when
-        instance.decodePublicKey(rsaStr);
+        final var ex = assertThrows(StringIndexOutOfBoundsException.class, () -> instance.decodePublicKey(rsaStr));
+        assertEquals("offset 4, count 476, length 278", ex.getMessage());
     }
 
-    @SuppressWarnings("checkstyle:lineLength")
     @Test
-    public void authorizedKeysDecoderValidDSAKey() throws GeneralSecurityException {
+    public void authorizedKeysDecoderValidDSAKey() throws Exception {
         // given
-        String dsaStr = "AAAAB3NzaC1kc3MAAACBANkM1e45lxlyV24QyWBAoESlHzhYYJUfk/yUd0+Dv28okyO71DmnJesYyUzsKDpnFLlnFhxTTUGSg90fdrdubLFkRTGnHhweegMCf6kU1xyE3U6bpyMdiOXH7fOS6Q2B+qtaQRB4R5TEhdoJX648Ng+YZvLwdbZh3r/et4P46b3DAAAAFQDcu6qp67XRpzMoOS2fIL+VOxvmDwAAAIAeT3d/hbvzPoL8wV52gPtWJMU2EGoX/LJwc86Vn52NlxXB1EQSzZI50PgCKEckS80lj4GXO1ZyuBhdsBEz4rDtAIdZGW5z7WxTfcz0G2dOWmNOBqvu7j9ngfPrgtDVHYV2VL/4VpbmoPgkQLfbA9NWb6US2RnTO46rGbGurigDMQAAAIEAiI3REuOJAmgDow6HxbN0FM+RCe1JYDwJIsCRRK4JA9oYV4Pg897xqypOeXogutVu9usfcOJI6uk5OwwLqIUSaU+flgmL0LOXv4lH4+URqs7Or8+ABFTcVGGCxg0I3gwhlY2Vjc9nyHY15wqBYdUxLbe8HC6EQp9uwlLlb8LQ6a0=";
+        final var dsaStr = "AAAAB3NzaC1kc3MAAACBANkM1e45lxlyV24QyWBAoESlHzhYYJUfk/yUd0+Dv28okyO71DmnJesYyUz"
+                         + "sKDpnFLlnFhxTTUGSg90fdrdubLFkRTGnHhweegMCf6kU1xyE3U6bpyMdiOXH7fOS6Q2B+qtaQRB4R5"
+                         + "TEhdoJX648Ng+YZvLwdbZh3r/et4P46b3DAAAAFQDcu6qp67XRpzMoOS2fIL+VOxvmDwAAAIAeT3d/h"
+                         + "bvzPoL8wV52gPtWJMU2EGoX/LJwc86Vn52NlxXB1EQSzZI50PgCKEckS80lj4GXO1ZyuBhdsBEz4rDt"
+                         + "AIdZGW5z7WxTfcz0G2dOWmNOBqvu7j9ngfPrgtDVHYV2VL/4VpbmoPgkQLfbA9NWb6US2RnTO46rGbG"
+                         + "urigDMQAAAIEAiI3REuOJAmgDow6HxbN0FM+RCe1JYDwJIsCRRK4JA9oYV4Pg897xqypOeXogutVu9u"
+                         + "sfcOJI6uk5OwwLqIUSaU+flgmL0LOXv4lH4+URqs7Or8+ABFTcVGGCxg0I3gwhlY2Vjc9nyHY15wqBY"
+                         + "dUxLbe8HC6EQp9uwlLlb8LQ6a0=";
         // when
-        PublicKey serverKey = instance.decodePublicKey(dsaStr);
+        final var serverKey = instance.decodePublicKey(dsaStr);
         // then
-        assertEquals(serverKey.getAlgorithm(), "DSA");
+        assertEquals("DSA", serverKey.getAlgorithm());
     }
 
-    @SuppressWarnings("checkstyle:lineLength")
-    @Test(expected = IllegalArgumentException.class)
-    public void authorizedKeysDecoderInvalidDSAKey() throws GeneralSecurityException {
+    @Test
+    public void authorizedKeysDecoderInvalidDSAKey() {
         // given
-        String dsaStr = "AAAAB3Nzakc3MAAACBANkM1e45lxlyV24QyWBAoESlHzhYYJUfk/yUd0+Dv28okyO71DmnJesYyUzsKDpnFLlnFhxTTUGSg90fdrdubLFkRTGnHhweegMCf6kU1xyE3U6bpyMdiOXH7fOS6Q2B+qtaQRB4R5TEhdoJX648Ng+YZvLwdbZh3r/et4P46b3DAAAAFQDcu6qp67XRpzMoOS2fIL+VOxvmDwAAAIAeT3d/hbvzPoL8wV52gPtWJMU2EGoX/LJwc86Vn52NlxXB1EQSzZI50PgCKEckS80lj4GXO1ZyuBhdsBEz4rDtAIdZGW5z7WxTfcz0G2dOWmNOBqvu7j9ngfPrgtDVHYV2VL/4VpbmoPgkQLfbA9NWb6US2RnTO46rGbGurigDMQAAAIEAiI3REuOJAmgDow6HxbN0FM+RCe1JYDwJIsCRRK4JA9oYV4Pg897xqypOeXogutVu9usfcOJI6uk5OwwLqIUSaU+flgmL0LOXv4lH4+URqs7Or8+ABFTcVGGCxg0I3gwhlY2Vjc9nyHY15wqBYdUxLbe8HC6EQp9uwlLlb8LQ6a0=";
+        final var dsaStr = "AAAAB3Nzakc3MAAACBANkM1e45lxlyV24QyWBAoESlHzhYYJUfk/yUd0+Dv28okyO71DmnJesYyUzsK"
+                         + "DpnFLlnFhxTTUGSg90fdrdubLFkRTGnHhweegMCf6kU1xyE3U6bpyMdiOXH7fOS6Q2B+qtaQRB4R5TE"
+                         + "hdoJX648Ng+YZvLwdbZh3r/et4P46b3DAAAAFQDcu6qp67XRpzMoOS2fIL+VOxvmDwAAAIAeT3d/hbv"
+                         + "zPoL8wV52gPtWJMU2EGoX/LJwc86Vn52NlxXB1EQSzZI50PgCKEckS80lj4GXO1ZyuBhdsBEz4rDtAI"
+                         + "dZGW5z7WxTfcz0G2dOWmNOBqvu7j9ngfPrgtDVHYV2VL/4VpbmoPgkQLfbA9NWb6US2RnTO46rGbGur"
+                         + "igDMQAAAIEAiI3REuOJAmgDow6HxbN0FM+RCe1JYDwJIsCRRK4JA9oYV4Pg897xqypOeXogutVu9usf"
+                         + "cOJI6uk5OwwLqIUSaU+flgmL0LOXv4lH4+URqs7Or8+ABFTcVGGCxg0I3gwhlY2Vjc9nyHY15wqBYdU"
+                         + "xLbe8HC6EQp9uwlLlb8LQ6a0=";
         // when
-        instance.decodePublicKey(dsaStr);
+        final var ex = assertThrows(IllegalArgumentException.class, () -> instance.decodePublicKey(dsaStr));
+        assertEquals("Last unit does not have enough valid bits", ex.getMessage());
     }
 
-    @SuppressWarnings("checkstyle:lineLength")
     @Test
-    public void authorizedKeysDecoderValidEcDSAKey() throws GeneralSecurityException {
+    public void authorizedKeysDecoderValidEcDSAKey() throws Exception {
         // given
-        String ecdsaStr = "AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBAP4dTrlwZmz8bZ1f901qWuFk7YelrL2WJG0jrCEAPo9UNM1wywpqjbaYUfoq+cevhLZaukDQ4N2Evux+YQ2zz0=";
+        final var ecdsaStr = "AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBAP4dTrlwZmz8bZ1f901qWuFk7Y"
+                           + "elrL2WJG0jrCEAPo9UNM1wywpqjbaYUfoq+cevhLZaukDQ4N2Evux+YQ2zz0=";
         // when
-        PublicKey serverKey = instance.decodePublicKey(ecdsaStr);
+        final var serverKey = instance.decodePublicKey(ecdsaStr);
         // then
-        assertEquals(serverKey.getAlgorithm(), "EC");
+        assertEquals("EC", serverKey.getAlgorithm());
     }
 
-    @SuppressWarnings("checkstyle:lineLength")
-    @Test(expected = IllegalArgumentException.class)
-    public void authorizedKeysDecoderInvalidEcDSAKey() throws GeneralSecurityException {
+    @Test
+    public void authorizedKeysDecoderInvalidEcDSAKey() {
         // given
-        String ecdsaStr = "AAAAE2VjZHNhLXNoItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBAP4dTrlwZmz8bZ1f901qWuFk7YelrL2WJG0jrCEAPo9UNM1wywpqjbaYUfoq+cevhLZaukDQ4N2Evux+YQ2zz0=";
+        final var ecdsaStr = "AAAAE2VjZHNhLXNoItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBAP4dTrlwZmz8bZ1f901qWuFk7Yel"
+                           + "rL2WJG0jrCEAPo9UNM1wywpqjbaYUfoq+cevhLZaukDQ4N2Evux+YQ2zz0=";
         // when
-        instance.decodePublicKey(ecdsaStr);
+        final var ex = assertThrows(IllegalArgumentException.class, () -> instance.decodePublicKey(ecdsaStr));
+        assertEquals("Last unit does not have enough valid bits", ex.getMessage());
     }
 
-    @Test(expected = IllegalArgumentException.class)
-    public void authorizedKeysDecoderInvalidKeyType() throws GeneralSecurityException {
+    @Test
+    public void authorizedKeysDecoderInvalidKeyType() {
         // given
-        String ed25519Str = "AAAAC3NzaC1lZDI1NTE5AAAAICIvyX9C+u3KZmJ8x4DuqJg1iAKOPObCgkX9plrvu29R";
+        final var ed25519Str = "AAAAC3NzaC1lZDI1NTE5AAAAICIvyX9C+u3KZmJ8x4DuqJg1iAKOPObCgkX9plrvu29R";
         // when
-        instance.decodePublicKey(ed25519Str);
+        final var ex = assertThrows(IllegalArgumentException.class, () -> instance.decodePublicKey(ed25519Str));
+        assertEquals("Unknown decode key type ssh-ed25519 in " + ed25519Str, ex.getMessage());
     }
 
-    @Test(expected = IllegalArgumentException.class)
-    public void decodingOfBlankInputIsCaughtAsAnError() throws GeneralSecurityException {
+    @Test
+    public void decodingOfBlankInputIsCaughtAsAnError() {
         // when
-        instance.decodePublicKey("");
+        final var ex = assertThrows(IllegalArgumentException.class, () -> instance.decodePublicKey(""));
+        assertEquals("No Base64 part to decode in ", ex.getMessage());
     }
 }
index c354140544b97be45d7172029e64f2eb37248fb7..77ff086d1b5c98f18451d535e16bdadf0bebaecf 100644 (file)
@@ -7,7 +7,9 @@
  */
 package org.opendaylight.netconf.callhome.protocol;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyString;
@@ -32,12 +34,13 @@ public class CallHomeAuthorizationTest {
         assertFalse(auth.isServerAllowed());
     }
 
-    @Test(expected = IllegalStateException.class)
+    @Test
     public void anAuthorizationOfRejectedCannotBeAppliedToASession() {
         // given
         CallHomeAuthorization auth = CallHomeAuthorization.rejected();
         // when
-        auth.applyTo(mock(ClientSession.class));
+        final var ex = assertThrows(IllegalStateException.class, () -> auth.applyTo(mock(ClientSession.class)));
+        assertEquals("Server is not allowed.", ex.getMessage());
     }
 
     @Test
index 0691c1cb77024f704a61e0d506e291c717e86e01..49f7f7dce34b03bf54c02a9172cad120b0c6e034 100644 (file)
@@ -27,7 +27,6 @@ import java.net.InetSocketAddress;
 import java.security.PublicKey;
 import org.junit.Before;
 import org.junit.Test;
-import org.mockito.Mockito;
 import org.opendaylight.netconf.client.NetconfClientSessionListener;
 import org.opendaylight.netconf.client.NetconfClientSessionNegotiatorFactory;
 import org.opendaylight.netconf.shaded.sshd.client.channel.ChannelSubsystem;
@@ -71,30 +70,30 @@ public class CallHomeSessionContextTest {
 
         realFactory = new CallHomeSessionContext.Factory(mockNettyGroup, mockNegotiatior, subListener);
 
-        KeyExchange kexMock = Mockito.mock(KeyExchange.class);
-        Mockito.doReturn(kexMock).when(mockSession).getKex();
+        KeyExchange kexMock = mock(KeyExchange.class);
+        doReturn(kexMock).when(mockSession).getKex();
 
-        PublicKey keyMock = Mockito.mock(PublicKey.class);
-        Mockito.doReturn(keyMock).when(mockSession).getServerKey();
+        PublicKey keyMock = mock(PublicKey.class);
+        doReturn(keyMock).when(mockSession).getServerKey();
         IoReadFuture mockFuture = mock(IoReadFuture.class);
         IoInputStream mockIn = mock(IoInputStream.class);
-        Mockito.doReturn(mockFuture).when(mockIn).read(any(Buffer.class));
+        doReturn(mockFuture).when(mockIn).read(any(Buffer.class));
         IoOutputStream mockOut = mock(IoOutputStream.class);
 
-        Mockito.doReturn(mockIn).when(mockChannel).getAsyncOut();
-        Mockito.doReturn(mockOut).when(mockChannel).getAsyncIn();
+        doReturn(mockIn).when(mockChannel).getAsyncOut();
+        doReturn(mockOut).when(mockChannel).getAsyncIn();
 
-        Mockito.doReturn(true).when(mockAuth).isServerAllowed();
+        doReturn(true).when(mockAuth).isServerAllowed();
 
         IoSession ioSession = mock(IoSession.class);
-        Mockito.doReturn(ioSession).when(mockSession).getIoSession();
-        Mockito.doReturn(address).when(ioSession).getRemoteAddress();
-        Mockito.doReturn(null).when(mockSession).setAttribute(any(AttributeKey.class), any());
-        Mockito.doReturn(null).when(mockSession).getAttribute(any(AttributeKey.class));
-        Mockito.doReturn("testSession").when(mockSession).toString();
+        doReturn(ioSession).when(mockSession).getIoSession();
+        doReturn(address).when(ioSession).getRemoteAddress();
+        doReturn(null).when(mockSession).setAttribute(any(AttributeKey.class), any());
+        doReturn(null).when(mockSession).getAttribute(any(AttributeKey.class));
+        doReturn("testSession").when(mockSession).toString();
 
         doNothing().when(mockAuth).applyTo(mockSession);
-        Mockito.doReturn("test").when(mockAuth).getSessionName();
+        doReturn("test").when(mockAuth).getSessionName();
     }
 
     @Test
@@ -116,7 +115,7 @@ public class CallHomeSessionContextTest {
     public void anAuthorizeActionShouldApplyToTheBoundSession() throws IOException {
         instance = realFactory.createIfNotExists(mockSession, mockAuth);
         // when
-        Mockito.doReturn(null).when(mockSession).auth();
+        doReturn(null).when(mockSession).auth();
         instance.authorize();
         // then
         verify(mockAuth, times(1)).applyTo(mockSession);
@@ -127,10 +126,10 @@ public class CallHomeSessionContextTest {
         // given
         OpenFuture mockFuture = mock(OpenFuture.class);
         ChannelSubsystem mockChannelSubsystem = mock(ChannelSubsystem.class);
-        Mockito.doReturn(mockFuture).when(mockChannelSubsystem).open();
-        Mockito.doReturn(mockChannelSubsystem).when(mockSession).createSubsystemChannel(anyString());
+        doReturn(mockFuture).when(mockChannelSubsystem).open();
+        doReturn(mockChannelSubsystem).when(mockSession).createSubsystemChannel(anyString());
 
-        Mockito.doReturn(null).when(mockFuture).addListener(any(SshFutureListener.class));
+        doReturn(null).when(mockFuture).addListener(any(SshFutureListener.class));
         doNothing().when(mockChannelSubsystem).setStreaming(any(StreamingChannel.Streaming.class));
         instance = realFactory.createIfNotExists(mockSession, mockAuth);
         // when
@@ -150,18 +149,18 @@ public class CallHomeSessionContextTest {
                 any(CallHomeChannelActivator.class));
 
         ChannelFuture mockChanFuture = mock(ChannelFuture.class);
-        Mockito.doReturn(mockChanFuture).when(mockNettyGroup).register(any(Channel.class));
+        doReturn(mockChanFuture).when(mockNettyGroup).register(any(Channel.class));
 
-        Mockito.doReturn(mockNettyGroup).when(mockFactory).getNettyGroup();
-        Mockito.doReturn(mockChannelInitializer).when(mockFactory)
+        doReturn(mockNettyGroup).when(mockFactory).getNettyGroup();
+        doReturn(mockChannelInitializer).when(mockFactory)
                 .getChannelInitializer(any(NetconfClientSessionListener.class));
-        Mockito.doReturn(mockListener).when(mockFactory).getChannelOpenListener();
+        doReturn(mockListener).when(mockFactory).getChannelOpenListener();
 
         ChannelPipeline mockPipeline = mock(ChannelPipeline.class);
-        Mockito.doReturn(mockPipeline).when(mockMinaChannel).pipeline();
+        doReturn(mockPipeline).when(mockMinaChannel).pipeline();
 
         OpenFuture mockFuture = mock(OpenFuture.class);
-        Mockito.doReturn(true).when(mockFuture).isOpened();
+        doReturn(true).when(mockFuture).isOpened();
 
         instance = new TestableContext(mockSession, mockAuth, mockFactory, mockMinaChannel);
         SshFutureListener<OpenFuture> listener = instance.newSshFutureListener(mockChannel);
@@ -177,8 +176,8 @@ public class CallHomeSessionContextTest {
         // given
         instance = realFactory.createIfNotExists(mockSession, mockAuth);
         OpenFuture mockFuture = mock(OpenFuture.class);
-        Mockito.doReturn(false).when(mockFuture).isOpened();
-        Mockito.doReturn(new RuntimeException("test")).when(mockFuture).getException();
+        doReturn(false).when(mockFuture).isOpened();
+        doReturn(new RuntimeException("test")).when(mockFuture).getException();
 
         doReturn(null).when(mockSession).close(anyBoolean());
 
index a7451eb54430404fe91c197e9b905288380216ec..58b1400d45c267d4c4948c7f18e4f453ec0dba20 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.netconf.callhome.protocol;
 
 import static org.junit.Assert.assertTrue;
 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;
@@ -23,7 +24,6 @@ import io.netty.channel.ChannelPromise;
 import java.io.IOException;
 import org.junit.Before;
 import org.junit.Test;
-import org.mockito.Mockito;
 import org.opendaylight.netconf.shaded.sshd.client.channel.ClientChannel;
 import org.opendaylight.netconf.shaded.sshd.client.session.ClientSession;
 import org.opendaylight.netconf.shaded.sshd.common.io.IoInputStream;
@@ -42,22 +42,22 @@ public class MinaSshNettyChannelTest {
     public void setup() throws IOException {
         IoReadFuture mockFuture = mock(IoReadFuture.class);
         IoInputStream mockIn = mock(IoInputStream.class);
-        Mockito.doReturn(mockFuture).when(mockIn).read(any(Buffer.class));
+        doReturn(mockFuture).when(mockIn).read(any(Buffer.class));
         mockContext = mock(CallHomeSessionContext.class);
         mockSession = mock(ClientSession.class);
         mockChannel = mock(ClientChannel.class);
-        Mockito.doReturn(mockIn).when(mockChannel).getAsyncOut();
+        doReturn(mockIn).when(mockChannel).getAsyncOut();
 
         IoOutputStream mockOut = mock(IoOutputStream.class);
-        Mockito.doReturn(mockOut).when(mockChannel).getAsyncIn();
+        doReturn(mockOut).when(mockChannel).getAsyncIn();
 
         IoWriteFuture mockWrFuture = mock(IoWriteFuture.class);
-        Mockito.doReturn(false).when(mockOut).isClosed();
-        Mockito.doReturn(false).when(mockOut).isClosing();
-        Mockito.doReturn(mockWrFuture).when(mockOut).writeBuffer(any(Buffer.class));
-        Mockito.doReturn(null).when(mockWrFuture).addListener(any());
+        doReturn(false).when(mockOut).isClosed();
+        doReturn(false).when(mockOut).isClosing();
+        doReturn(mockWrFuture).when(mockOut).writeBuffer(any(Buffer.class));
+        doReturn(null).when(mockWrFuture).addListener(any());
 
-        Mockito.doReturn(mockFuture).when(mockFuture).addListener(Mockito.any());
+        doReturn(mockFuture).when(mockFuture).addListener(any());
 
         instance = new MinaSshNettyChannel(mockContext, mockSession, mockChannel);
     }
@@ -75,7 +75,7 @@ public class MinaSshNettyChannelTest {
     public void ourChannelHandlerShouldForwardWrites() throws Exception {
         ChannelHandler mockHandler = mock(ChannelHandler.class);
         ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
-        Mockito.doReturn(mockHandler).when(ctx).handler();
+        doReturn(mockHandler).when(ctx).handler();
         ChannelPromise promise = mock(ChannelPromise.class);
 
         // we would really like to just verify that the async handler write() was
@@ -84,8 +84,8 @@ public class MinaSshNettyChannelTest {
         // on the write promise that we use as a cheap way to tell that write()
         // got called. ick.
 
-        Mockito.doReturn(null).when(mockChannel).getAsyncIn();
-        Mockito.doReturn(null).when(promise).setFailure(any(Throwable.class));
+        doReturn(null).when(mockChannel).getAsyncIn();
+        doReturn(null).when(promise).setFailure(any(Throwable.class));
 
         // Need to reconstruct instance to pick up null async in above
         instance = new MinaSshNettyChannel(mockContext, mockSession, mockChannel);
index 136d5055aa81f20280120a0e0f10e121e21273dc..bb6e07a71a346e5f712f4f3556b76b94942596ec 100644 (file)
@@ -30,7 +30,6 @@ import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
-import org.mockito.Mockito;
 import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.netconf.shaded.sshd.client.SshClient;
 import org.opendaylight.netconf.shaded.sshd.client.future.AuthFuture;
@@ -132,14 +131,14 @@ public class NetconfCallHomeServerTest {
     public void verificationOfTheServerKeyShouldBeSuccessfulForServerIsAllowed() {
         // given
         ClientSessionImpl mockClientSession = mock(ClientSessionImpl.class);
-        Mockito.doReturn("test").when(mockClientSession).toString();
+        doReturn("test").when(mockClientSession).toString();
         SocketAddress mockSocketAddr = mock(SocketAddress.class);
         PublicKey mockPublicKey = mock(PublicKey.class);
 
-        Mockito.doReturn(true).when(mockAuth).isServerAllowed();
-        Mockito.doReturn("some-session-name").when(mockAuth).getSessionName();
-        Mockito.doReturn(mockAuth).when(mockCallHomeAuthProv).provideAuth(mockSocketAddr, mockPublicKey);
-        Mockito.doReturn(null).when(mockFactory).createIfNotExists(mockClientSession, mockAuth);
+        doReturn(true).when(mockAuth).isServerAllowed();
+        doReturn("some-session-name").when(mockAuth).getSessionName();
+        doReturn(mockAuth).when(mockCallHomeAuthProv).provideAuth(mockSocketAddr, mockPublicKey);
+        doReturn(null).when(mockFactory).createIfNotExists(mockClientSession, mockAuth);
 
         // expect
         assertFalse(instance.verifyServerKey(mockClientSession, mockSocketAddr, mockPublicKey));
@@ -153,9 +152,9 @@ public class NetconfCallHomeServerTest {
         SocketAddress mockSocketAddr = mock(SocketAddress.class);
         PublicKey mockPublicKey = mock(PublicKey.class);
 
-        Mockito.doReturn(false).when(mockAuth).isServerAllowed();
-        Mockito.doReturn(mockAuth).when(mockCallHomeAuthProv).provideAuth(mockSocketAddr, mockPublicKey);
-        Mockito.doReturn("").when(mockClientSession).toString();
+        doReturn(false).when(mockAuth).isServerAllowed();
+        doReturn(mockAuth).when(mockCallHomeAuthProv).provideAuth(mockSocketAddr, mockPublicKey);
+        doReturn("").when(mockClientSession).toString();
 
         // expect
         assertFalse(instance.verifyServerKey(mockClientSession, mockSocketAddr, mockPublicKey));
@@ -167,8 +166,8 @@ public class NetconfCallHomeServerTest {
         IoAcceptor mockAcceptor = mock(IoAcceptor.class);
         IoServiceFactory mockMinaFactory = mock(IoServiceFactory.class);
 
-        Mockito.doReturn(mockAcceptor).when(mockMinaFactory).createAcceptor(any(IoHandler.class));
-        Mockito.doNothing().when(mockAcceptor).bind(any(SocketAddress.class));
+        doReturn(mockAcceptor).when(mockMinaFactory).createAcceptor(any(IoHandler.class));
+        doNothing().when(mockAcceptor).bind(any(SocketAddress.class));
         instance = new NetconfCallHomeServer(
                 mockSshClient, mockCallHomeAuthProv, mockFactory, MOCK_ADDRESS, mockStatusRecorder, mockMinaFactory);
         // when