!661 添加一个带默认值的 Ipv4Util.ipv4ToLong 方法

Merge pull request !661 from churen/v5-dev
This commit is contained in:
Looly
2022-06-20 04:13:47 +00:00
committed by Gitee
2 changed files with 24 additions and 0 deletions

View File

@@ -86,4 +86,17 @@ public class Ipv4UtilTest {
l = Ipv4Util.ipv4ToLong("255.255.255.255");
Assert.assertEquals(4294967295L, l);
}
@Test
public void ipv4ToLongWithDefaultTest() {
String strIP = "不正确的 IP 地址";
long defaultValue = 0L;
long ipOfLong = Ipv4Util.ipv4ToLong(strIP, defaultValue);
Assert.assertEquals(ipOfLong, defaultValue);
String strIP2 = "255.255.255.255";
long defaultValue2 = 0L;
long ipOfLong2 = Ipv4Util.ipv4ToLong(strIP2, defaultValue2);
Assert.assertEquals(ipOfLong2, 4294967295L);
}
}