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.OutputStream;
|
||||
import java.math.BigInteger;
|
||||
import java.net.Authenticator;
|
||||
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.net.*;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.util.ArrayList;
|
||||
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;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 网络相关工具
|
||||
@ -632,7 +612,8 @@ public class NetUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取主机名称,一次获取会缓存名称
|
||||
* 获取主机名称,一次获取会缓存名称<br>
|
||||
* 注意此方法会触发反向DNS解析,导致阻塞,阻塞时间取决于网络!
|
||||
*
|
||||
* @return 主机名称
|
||||
* @since 5.4.4
|
||||
@ -643,6 +624,7 @@ public class NetUtil {
|
||||
}
|
||||
|
||||
final InetAddress localhost = getLocalhost();
|
||||
|
||||
if (null != localhost) {
|
||||
String name = localhost.getHostName();
|
||||
if (StrUtil.isEmpty(name)) {
|
||||
|
@ -23,37 +23,37 @@ public class NetUtilTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void getLocalhostStrTest() {
|
||||
String localhost = NetUtil.getLocalhostStr();
|
||||
final String localhost = NetUtil.getLocalhostStr();
|
||||
Assert.assertNotNull(localhost);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void getLocalhostTest() {
|
||||
InetAddress localhost = NetUtil.getLocalhost();
|
||||
final InetAddress localhost = NetUtil.getLocalhost();
|
||||
Assert.assertNotNull(localhost);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void getLocalMacAddressTest() {
|
||||
String macAddress = NetUtil.getLocalMacAddress();
|
||||
final String macAddress = NetUtil.getLocalMacAddress();
|
||||
Assert.assertNotNull(macAddress);
|
||||
|
||||
// 验证MAC地址正确
|
||||
boolean match = ReUtil.isMatch(PatternPool.MAC_ADDRESS, macAddress);
|
||||
final boolean match = ReUtil.isMatch(PatternPool.MAC_ADDRESS, macAddress);
|
||||
Assert.assertTrue(match);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void longToIpTest() {
|
||||
String ipv4 = NetUtil.longToIpv4(2130706433L);
|
||||
final String ipv4 = NetUtil.longToIpv4(2130706433L);
|
||||
Assert.assertEquals("127.0.0.1", ipv4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ipToLongTest() {
|
||||
long ipLong = NetUtil.ipv4ToLong("127.0.0.1");
|
||||
final long ipLong = NetUtil.ipv4ToLong("127.0.0.1");
|
||||
Assert.assertEquals(2130706433L, ipLong);
|
||||
}
|
||||
|
||||
@ -65,7 +65,7 @@ public class NetUtilTest {
|
||||
|
||||
@Test
|
||||
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);
|
||||
Assert.assertEquals(1, httpCookies.size());
|
||||
|
||||
@ -78,10 +78,17 @@ public class NetUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void getLocalHostNameTest() {
|
||||
// 注意此方法会触发反向DNS解析,导致阻塞,阻塞时间取决于网络!
|
||||
Assert.assertNotNull(NetUtil.getLocalHostName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLocalHostTest() {
|
||||
Assert.assertNotNull(NetUtil.getLocalhost());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pingTest(){
|
||||
Assert.assertTrue(NetUtil.ping("127.0.0.1"));
|
||||
@ -90,7 +97,7 @@ public class NetUtilTest {
|
||||
@Test
|
||||
@Ignore
|
||||
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));
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user