*/
package org.opendaylight.ovsdb.southbound;
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.CheckedFuture;
return node;
}
- private static String getLocalControllerHostIpAddress() {
+ @VisibleForTesting
+ static String getLocalControllerHostIpAddress() {
String ipaddress = null;
try {
Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces();
package org.opendaylight.ovsdb.southbound;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doNothing;
import org.powermock.api.support.membermodification.MemberModifier;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.reflect.Whitebox;
@RunWith(PowerMockRunner.class)
@PrepareForTest({SouthboundUtil.class, NetworkInterface.class})
//NetworkInterface.getNetworkInterfaces() returns null case
PowerMockito.mockStatic(NetworkInterface.class);
when(NetworkInterface.getNetworkInterfaces()).thenReturn(null);
- assertEquals(null, (String) Whitebox.invokeMethod(SouthboundUtil.class, "getLocalControllerHostIpAddress"));
+ assertNull(SouthboundUtil.getLocalControllerHostIpAddress());
Enumeration<NetworkInterface> ifaces = mock(Enumeration.class);
when(NetworkInterface.getNetworkInterfaces()).thenReturn(ifaces);
when(inetAddr.isLoopbackAddress()).thenReturn(false);
when(inetAddr.isSiteLocalAddress()).thenReturn(true);
when(inetAddr.getHostAddress()).thenReturn("HostAddress");
- assertEquals("HostAddress", Whitebox.invokeMethod(SouthboundUtil.class, "getLocalControllerHostIpAddress"));
+ assertEquals("HostAddress", SouthboundUtil.getLocalControllerHostIpAddress());
}
@Test