Remove use of powermock 84/74184/2
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 18 Jul 2018 11:11:39 +0000 (13:11 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 18 Jul 2018 11:34:54 +0000 (13:34 +0200)
Rather than mocking a static method setup the class properly.

Change-Id: Idfd4c0c655c708f5c0e8c83287051b77a4544774
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/netconf-console/pom.xml
netconf/netconf-console/src/main/java/org/opendaylight/netconf/console/commands/NetconfConnectDeviceCommand.java
netconf/netconf-console/src/test/java/org/opendaylight/netconf/console/commands/NetconfCommandsImplCallsTest.java
netconf/sal-netconf-connector/pom.xml
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalProvider.java
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceTopologyAdapter.java
netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalFacadeTest.java
netconf/yanglib/pom.xml

index 6e9943246b3a165c84eb334a8deacea6b3734f7b..bd430b18e7c3284e5bb2323416ecb5fe44b99364 100644 (file)
@@ -39,20 +39,6 @@ and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL
           <artifactId>mockito-core</artifactId>
           <scope>test</scope>
       </dependency>
-      <dependency>
-          <groupId>org.powermock</groupId>
-          <artifactId>powermock-module-junit4</artifactId>
-          <scope>test</scope>
-      </dependency>
-      <dependency>
-          <groupId>org.powermock</groupId>
-          <artifactId>powermock-api-mockito</artifactId>
-          <scope>test</scope>
-      </dependency>
-      <dependency>
-          <groupId>org.powermock</groupId>
-          <artifactId>powermock-core</artifactId>
-      </dependency>
       <dependency>
           <groupId>org.opendaylight.yangtools</groupId>
           <artifactId>yang-test-util</artifactId>
index 88186de9cc62cb0961a3c5b3fee4ed5d97931605..cedb5db57652cea52398c41ce62acef831caed53 100644 (file)
@@ -8,6 +8,8 @@
 
 package org.opendaylight.netconf.console.commands;
 
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Strings;
 import java.util.Arrays;
@@ -44,6 +46,16 @@ public class NetconfConnectDeviceCommand implements Action {
         this.devicePort = devicePort;
     }
 
+    @VisibleForTesting
+    NetconfConnectDeviceCommand(final NetconfCommands service, final String deviceIp, final String devicePort,
+            final String username, final String password) {
+        this.service = requireNonNull(service);
+        this.deviceIp = requireNonNull(deviceIp);
+        this.devicePort = requireNonNull(devicePort);
+        this.username = requireNonNull(username);
+        this.password = requireNonNull(password);
+    }
+
     @Option(name = "-i",
             aliases = { "--ipaddress" },
             description = "IP address of the netconf device",
index f0e0af565d4935c45c077279e25396bfe33d2fab..2ceb0668080de191c7555eb26341f4698dcb16c5 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.netconf.console.commands;
 
 import static junit.framework.TestCase.assertEquals;
 import static junit.framework.TestCase.assertTrue;
-import static org.mockito.BDDMockito.given;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyString;
 import static org.mockito.Mockito.doNothing;
@@ -19,24 +18,17 @@ import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.MockitoAnnotations.initMocks;
 
-import com.google.common.base.Strings;
-import com.google.common.collect.Lists;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import org.junit.Before;
 import org.junit.Test;
-import org.junit.runner.RunWith;
 import org.mockito.ArgumentCaptor;
 import org.mockito.Mock;
 import org.opendaylight.netconf.console.api.NetconfCommands;
 import org.opendaylight.netconf.console.utils.NetconfConsoleConstants;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
 
-@RunWith(PowerMockRunner.class)
-@PrepareForTest(Strings.class)
 public class NetconfCommandsImplCallsTest {
 
     @Mock
@@ -54,10 +46,9 @@ public class NetconfCommandsImplCallsTest {
         netconfConnectDeviceCommand.execute();
         verify(netconfCommands, times(0)).connectDevice(any(), any());
 
-        netconfConnectDeviceCommand = new NetconfConnectDeviceCommand(netconfCommands, "192.168.1.1", "7777");
+        netconfConnectDeviceCommand = new NetconfConnectDeviceCommand(netconfCommands, "192.168.1.1", "7777", "user",
+            "pass");
 
-        PowerMockito.mockStatic(Strings.class);
-        given(Strings.isNullOrEmpty(any())).willReturn(false);
         netconfConnectDeviceCommand.execute();
         doNothing().when(netconfCommands).connectDevice(any(), any());
         verify(netconfCommands, times(1)).connectDevice(any(), any());
@@ -141,10 +132,10 @@ public class NetconfCommandsImplCallsTest {
     private static HashMap<String, Map<String, List<String>>> getDeviceHashMap() {
         final HashMap<String, Map<String, List<String>>> devices = new HashMap<>();
         final HashMap<String, List<String>> deviceMap = new HashMap<>();
-        deviceMap.put(NetconfConsoleConstants.NETCONF_IP, Lists.newArrayList("192.168.1.1"));
-        deviceMap.put(NetconfConsoleConstants.NETCONF_PORT, Lists.newArrayList("7777"));
-        deviceMap.put(NetconfConsoleConstants.STATUS, Lists.newArrayList("connecting"));
-        deviceMap.put(NetconfConsoleConstants.AVAILABLE_CAPABILITIES, Lists.newArrayList("cap1", "cap2", "cap3"));
+        deviceMap.put(NetconfConsoleConstants.NETCONF_IP, Arrays.asList("192.168.1.1"));
+        deviceMap.put(NetconfConsoleConstants.NETCONF_PORT, Arrays.asList("7777"));
+        deviceMap.put(NetconfConsoleConstants.STATUS, Arrays.asList("connecting"));
+        deviceMap.put(NetconfConsoleConstants.AVAILABLE_CAPABILITIES, Arrays.asList("cap1", "cap2", "cap3"));
         devices.put("device", deviceMap);
         return devices;
     }
index 2b306d858e4110e94d46da97586e7a337b6345f0..07c027e36da503ebcf95e1cbfbbdc7376fd1f5dc 100644 (file)
       <groupId>com.google.code.gson</groupId>
       <artifactId>gson</artifactId>
     </dependency>
-    <dependency>
-      <groupId>org.powermock</groupId>
-      <artifactId>powermock-module-junit4</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.powermock</groupId>
-      <artifactId>powermock-api-mockito</artifactId>
-      <scope>test</scope>
-    </dependency>
     <dependency>
       <groupId>org.awaitility</groupId>
       <artifactId>awaitility</artifactId>
index e4d16e9394f4c92d22d7bf7b6dd2bc1e8faed0ca..f4b44d9bc453b6742d2a41446e0be3350ea8bb23 100644 (file)
@@ -90,6 +90,7 @@ public class NetconfDeviceSalProvider implements AutoCloseable {
 
     }
 
+    @Override
     public void close() throws Exception {
         mountInstance.close();
         if (topologyDatastoreAdapter != null) {
@@ -101,7 +102,7 @@ public class NetconfDeviceSalProvider implements AutoCloseable {
         }
     }
 
-    public static final class MountInstance implements AutoCloseable {
+    public static class MountInstance implements AutoCloseable {
 
         private final DOMMountPointService mountService;
         private final RemoteDeviceId id;
@@ -109,7 +110,7 @@ public class NetconfDeviceSalProvider implements AutoCloseable {
 
         private ObjectRegistration<DOMMountPoint> topologyRegistration;
 
-        public MountInstance(final DOMMountPointService mountService, final RemoteDeviceId id) {
+        MountInstance(final DOMMountPointService mountService, final RemoteDeviceId id) {
             this.mountService = Preconditions.checkNotNull(mountService);
             this.id = Preconditions.checkNotNull(id);
         }
index c9b22510270f514ed87720aca8e81735fa9c7343..5bc790363466de47a6b707715bb25efb5d79fb45 100644 (file)
@@ -50,7 +50,7 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public final class NetconfDeviceTopologyAdapter implements AutoCloseable {
+public class NetconfDeviceTopologyAdapter implements AutoCloseable {
 
     private static final Logger LOG = LoggerFactory.getLogger(NetconfDeviceTopologyAdapter.class);
 
index 89f0ee26422afa6913ee219028d33618896d6404..05678f14ffa9ff3c3533b72998a6eaf0f7c54aea 100644 (file)
@@ -22,7 +22,6 @@ import java.util.Arrays;
 import java.util.List;
 import org.junit.Before;
 import org.junit.Test;
-import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
 import org.opendaylight.controller.md.sal.dom.api.DOMNotification;
@@ -32,18 +31,14 @@ import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPrefe
 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
 
-@RunWith(PowerMockRunner.class)
-@PrepareForTest({NetconfDeviceTopologyAdapter.class, NetconfDeviceSalProvider.MountInstance.class,
-        NetconfSessionPreferences.class})
 public class NetconfDeviceSalFacadeTest {
 
     private NetconfDeviceSalFacade deviceFacade;
 
+    @Mock
     private NetconfDeviceTopologyAdapter netconfDeviceTopologyAdapter;
+    @Mock
     private NetconfDeviceSalProvider.MountInstance mountInstance;
 
     @Mock
@@ -57,9 +52,6 @@ public class NetconfDeviceSalFacadeTest {
 
         deviceFacade = new NetconfDeviceSalFacade(remoteDeviceId, salProvider);
 
-        netconfDeviceTopologyAdapter = PowerMockito.mock(NetconfDeviceTopologyAdapter.class);
-        mountInstance = PowerMockito.mock(NetconfDeviceSalProvider.MountInstance.class);
-
         doReturn(netconfDeviceTopologyAdapter).when(salProvider).getTopologyDatastoreAdapter();
         doNothing().when(netconfDeviceTopologyAdapter)
                 .updateDeviceData(any(Boolean.class), any(NetconfDeviceCapabilities.class));
index 2751298d071d71a46c8eeabbca506c48d925590c..82a1b5c4748b9340c876ef16c9918d4183a7bbcb 100644 (file)
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
         </dependency>
-        <dependency>
-            <groupId>org.powermock</groupId>
-            <artifactId>powermock-module-junit4</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.powermock</groupId>
-            <artifactId>powermock-api-mockito</artifactId>
-            <scope>test</scope>
-        </dependency>
         <dependency>
             <groupId>commons-io</groupId>
             <artifactId>commons-io</artifactId>