Rather than mocking a static method setup the class properly.
Change-Id: Idfd4c0c655c708f5c0e8c83287051b77a4544774
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
<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>
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;
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",
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;
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
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());
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;
}
<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>
}
+ @Override
public void close() throws Exception {
mountInstance.close();
if (topologyDatastoreAdapter != null) {
}
}
- public static final class MountInstance implements AutoCloseable {
+ public static class MountInstance implements AutoCloseable {
private final DOMMountPointService mountService;
private final RemoteDeviceId id;
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);
}
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);
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;
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
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));
<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>