mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix test
This commit is contained in:
parent
317d8ee527
commit
b884cdaedd
@ -16,30 +16,10 @@ import javax.naming.directory.Attributes;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.net.Authenticator;
|
import java.net.*;
|
||||||
import java.net.DatagramSocket;
|
|
||||||
import java.net.HttpCookie;
|
|
||||||
import java.net.IDN;
|
|
||||||
import java.net.Inet4Address;
|
|
||||||
import java.net.Inet6Address;
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
import java.net.NetworkInterface;
|
|
||||||
import java.net.ServerSocket;
|
|
||||||
import java.net.Socket;
|
|
||||||
import java.net.SocketException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.SocketChannel;
|
import java.nio.channels.SocketChannel;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.util.LinkedHashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.TreeSet;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 网络相关工具
|
* 网络相关工具
|
||||||
@ -632,7 +612,8 @@ public class NetUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取主机名称,一次获取会缓存名称
|
* 获取主机名称,一次获取会缓存名称<br>
|
||||||
|
* 注意此方法会触发反向DNS解析,导致阻塞,阻塞时间取决于网络!
|
||||||
*
|
*
|
||||||
* @return 主机名称
|
* @return 主机名称
|
||||||
* @since 5.4.4
|
* @since 5.4.4
|
||||||
@ -643,6 +624,7 @@ public class NetUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final InetAddress localhost = getLocalhost();
|
final InetAddress localhost = getLocalhost();
|
||||||
|
|
||||||
if (null != localhost) {
|
if (null != localhost) {
|
||||||
String name = localhost.getHostName();
|
String name = localhost.getHostName();
|
||||||
if (StrUtil.isEmpty(name)) {
|
if (StrUtil.isEmpty(name)) {
|
||||||
|
@ -23,37 +23,37 @@ public class NetUtilTest {
|
|||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Ignore
|
||||||
public void getLocalhostStrTest() {
|
public void getLocalhostStrTest() {
|
||||||
String localhost = NetUtil.getLocalhostStr();
|
final String localhost = NetUtil.getLocalhostStr();
|
||||||
Assert.assertNotNull(localhost);
|
Assert.assertNotNull(localhost);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Ignore
|
||||||
public void getLocalhostTest() {
|
public void getLocalhostTest() {
|
||||||
InetAddress localhost = NetUtil.getLocalhost();
|
final InetAddress localhost = NetUtil.getLocalhost();
|
||||||
Assert.assertNotNull(localhost);
|
Assert.assertNotNull(localhost);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Ignore
|
||||||
public void getLocalMacAddressTest() {
|
public void getLocalMacAddressTest() {
|
||||||
String macAddress = NetUtil.getLocalMacAddress();
|
final String macAddress = NetUtil.getLocalMacAddress();
|
||||||
Assert.assertNotNull(macAddress);
|
Assert.assertNotNull(macAddress);
|
||||||
|
|
||||||
// 验证MAC地址正确
|
// 验证MAC地址正确
|
||||||
boolean match = ReUtil.isMatch(PatternPool.MAC_ADDRESS, macAddress);
|
final boolean match = ReUtil.isMatch(PatternPool.MAC_ADDRESS, macAddress);
|
||||||
Assert.assertTrue(match);
|
Assert.assertTrue(match);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void longToIpTest() {
|
public void longToIpTest() {
|
||||||
String ipv4 = NetUtil.longToIpv4(2130706433L);
|
final String ipv4 = NetUtil.longToIpv4(2130706433L);
|
||||||
Assert.assertEquals("127.0.0.1", ipv4);
|
Assert.assertEquals("127.0.0.1", ipv4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ipToLongTest() {
|
public void ipToLongTest() {
|
||||||
long ipLong = NetUtil.ipv4ToLong("127.0.0.1");
|
final long ipLong = NetUtil.ipv4ToLong("127.0.0.1");
|
||||||
Assert.assertEquals(2130706433L, ipLong);
|
Assert.assertEquals(2130706433L, ipLong);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ public class NetUtilTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseCookiesTest(){
|
public void parseCookiesTest(){
|
||||||
String cookieStr = "cookieName=\"cookieValue\";Path=\"/\";Domain=\"cookiedomain.com\"";
|
final String cookieStr = "cookieName=\"cookieValue\";Path=\"/\";Domain=\"cookiedomain.com\"";
|
||||||
final List<HttpCookie> httpCookies = NetUtil.parseCookies(cookieStr);
|
final List<HttpCookie> httpCookies = NetUtil.parseCookies(cookieStr);
|
||||||
Assert.assertEquals(1, httpCookies.size());
|
Assert.assertEquals(1, httpCookies.size());
|
||||||
|
|
||||||
@ -78,10 +78,17 @@ public class NetUtilTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Ignore
|
||||||
public void getLocalHostNameTest() {
|
public void getLocalHostNameTest() {
|
||||||
|
// 注意此方法会触发反向DNS解析,导致阻塞,阻塞时间取决于网络!
|
||||||
Assert.assertNotNull(NetUtil.getLocalHostName());
|
Assert.assertNotNull(NetUtil.getLocalHostName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getLocalHostTest() {
|
||||||
|
Assert.assertNotNull(NetUtil.getLocalhost());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void pingTest(){
|
public void pingTest(){
|
||||||
Assert.assertTrue(NetUtil.ping("127.0.0.1"));
|
Assert.assertTrue(NetUtil.ping("127.0.0.1"));
|
||||||
@ -90,7 +97,7 @@ public class NetUtilTest {
|
|||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Ignore
|
||||||
public void isOpenTest(){
|
public void isOpenTest(){
|
||||||
InetSocketAddress address = new InetSocketAddress("www.hutool.cn", 443);
|
final InetSocketAddress address = new InetSocketAddress("www.hutool.cn", 443);
|
||||||
Assert.assertTrue(NetUtil.isOpen(address, 200));
|
Assert.assertTrue(NetUtil.isOpen(address, 200));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user