i want to test this method using mockito and unit testing
`public class CurrentIP {
public static String getIPAddress() {
try {
List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
for (NetworkInterface intf : interfaces) {
List<InetAddress> addrs = Collections.list(intf.getInetAddresses());
for (InetAddress addr : addrs) {
if (!addr.isLoopbackAddress()) {
String sAddr = addr.getHostAddress();
boolean isIPv4 = sAddr.indexOf(':') < 0;
if (isIPv4)
return sAddr;
}
}
}
} catch (Exception ignored) {
} // for now eat exceptions
return "";
}
}`
Aucun commentaire:
Enregistrer un commentaire