提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.framework.ip.core.utils; |
H |
2 |
|
|
3 |
import com.iailab.framework.ip.core.Area; |
|
4 |
import org.junit.jupiter.api.Test; |
|
5 |
import org.lionsoul.ip2region.xdb.Searcher; |
|
6 |
|
|
7 |
|
|
8 |
import static org.junit.jupiter.api.Assertions.assertEquals; |
|
9 |
|
|
10 |
/** |
|
11 |
* {@link IPUtils} 的单元测试 |
|
12 |
* |
|
13 |
* @author wanglhup |
|
14 |
*/ |
|
15 |
public class IPUtilsTest { |
|
16 |
|
|
17 |
@Test |
|
18 |
public void testGetAreaId_string() { |
|
19 |
// 120.202.4.0|120.202.4.255|420600 |
|
20 |
Integer areaId = IPUtils.getAreaId("120.202.4.50"); |
|
21 |
assertEquals(420600, areaId); |
|
22 |
} |
|
23 |
|
|
24 |
@Test |
|
25 |
public void testGetAreaId_long() throws Exception { |
|
26 |
// 120.203.123.0|120.203.133.255|360900 |
|
27 |
long ip = Searcher.checkIP("120.203.123.250"); |
|
28 |
Integer areaId = IPUtils.getAreaId(ip); |
|
29 |
assertEquals(360900, areaId); |
|
30 |
} |
|
31 |
|
|
32 |
@Test |
|
33 |
public void testGetArea_string() { |
|
34 |
// 120.202.4.0|120.202.4.255|420600 |
|
35 |
Area area = IPUtils.getArea("120.202.4.50"); |
|
36 |
assertEquals("襄阳市", area.getName()); |
|
37 |
} |
|
38 |
|
|
39 |
@Test |
|
40 |
public void testGetArea_long() throws Exception { |
|
41 |
// 120.203.123.0|120.203.133.255|360900 |
|
42 |
long ip = Searcher.checkIP("120.203.123.252"); |
|
43 |
Area area = IPUtils.getArea(ip); |
|
44 |
assertEquals("宜春市", area.getName()); |
|
45 |
} |
|
46 |
|
|
47 |
} |