@Test
  public void testGetLocalHostExternalInet4Address() throws Exception {
    mockStatic(InetAddress.class, NetworkInterface.class);
    InetAddress inetAddressLocalHost = mock(InetAddress.class);
    when(inetAddressLocalHost.isLoopbackAddress()).thenReturn(true);
    when(InetAddress.getLocalHost()).thenReturn(inetAddressLocalHost);

    InetAddress linkLocalAddress = mock(InetAddress.class);
    when(linkLocalAddress.isLinkLocalAddress()).thenReturn(true);
    Inet4Address externalInet4Address = mock(Inet4Address.class);
    when(externalInet4Address.isLinkLocalAddress()).thenReturn(false);
    when(externalInet4Address.isLoopbackAddress()).thenReturn(false);
    byte[] externalInet4AddressBytes = new byte[]{0, 1, 2, 3};
    when(externalInet4Address.getAddress()).thenReturn(externalInet4AddressBytes);
    InetAddress otherExternalAddress = mock(InetAddress.class); // not Inet4Address
    when(otherExternalAddress.isLinkLocalAddress()).thenReturn(false);
    when(otherExternalAddress.isLoopbackAddress()).thenReturn(false);

    NetworkInterface networkInterfaceLinkLocal = mock(NetworkInterface.class);
    when(networkInterfaceLinkLocal.getInetAddresses()).thenReturn(
        Collections.enumeration(Collections.singletonList(linkLocalAddress)));
    NetworkInterface networkInterfaceExternal = mock(NetworkInterface.class);
    when(networkInterfaceExternal.getInetAddresses()).thenReturn(
        Collections.enumeration(Arrays.asList(otherExternalAddress, externalInet4Address)));
    when(NetworkInterface.getNetworkInterfaces()).thenReturn(
        Collections.enumeration(Arrays.asList(networkInterfaceLinkLocal, networkInterfaceExternal)));

    InetAddress finalInetAddress = mock(InetAddress.class);
    when(InetAddress.getByAddress(aryEq(externalInet4AddressBytes))).thenReturn(finalInetAddress);

    assertEquals(finalInetAddress, Util.getLocalHost());
  }
It's difficult to explicitly test having an actual version and using the fallback, due to the usage of methods of
 Class.
samza-core/src/test/java/org/apache/samza/util/TestUtil.java