Expose methods for testing 62/74162/2
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 17 Jul 2018 22:47:58 +0000 (00:47 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 18 Jul 2018 00:01:41 +0000 (02:01 +0200)
Using @VisibleForTesting to expose a method from private to package-private,
hence we do not need to use WhiteBox reflection and can do direct calls.

Change-Id: Ic6101b560595a74faaf7889dc496025f7eaf4a7f
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/SouthboundUtil.java
southbound/southbound-impl/src/test/java/org/opendaylight/ovsdb/southbound/SouthboundUtilTest.java

index 0516728546336302a5f11065c41d08460f832dbd..c3b306f856781eb599abdd05c24fff89f40f642c 100644 (file)
@@ -7,6 +7,7 @@
  */
 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;
@@ -95,7 +96,8 @@ public final class SouthboundUtil {
         return node;
     }
 
-    private static String getLocalControllerHostIpAddress() {
+    @VisibleForTesting
+    static String getLocalControllerHostIpAddress() {
         String ipaddress = null;
         try {
             Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces();
index f58229066d79629733b48522f6ac413ff0c10508..44a35ec89c34dc5437acf9d88f72b36e5757c03c 100644 (file)
@@ -8,6 +8,7 @@
 
 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;
@@ -44,7 +45,6 @@ import org.powermock.api.support.membermodification.MemberMatcher;
 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})
@@ -114,7 +114,7 @@ public class SouthboundUtilTest {
         //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);
@@ -130,7 +130,7 @@ public class SouthboundUtilTest {
         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