From fdd3cc3e62e5e687936831d3f2208f4ae5bd329b Mon Sep 17 00:00:00 2001 From: onewe Date: Mon, 13 Jun 2022 16:39:34 +0800 Subject: [PATCH] [ISSUE #8515] add tearDown method for the unit test - reformat by nacos-style --- .../main/java/com/alibaba/nacos/sys/utils/InetUtils.java | 6 ++++-- .../java/com/alibaba/nacos/sys/utils/InetUtilsTest.java | 8 +++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/sys/src/main/java/com/alibaba/nacos/sys/utils/InetUtils.java b/sys/src/main/java/com/alibaba/nacos/sys/utils/InetUtils.java index cfe32ca1ea7..d796528bd51 100644 --- a/sys/src/main/java/com/alibaba/nacos/sys/utils/InetUtils.java +++ b/sys/src/main/java/com/alibaba/nacos/sys/utils/InetUtils.java @@ -125,9 +125,10 @@ private static void refreshIp() { } /** - * Get ip address from environment. - * System property nacos.server.ip. + * Get ip address from environment + * System property nacos.server.ip * Spring property nacos.inetutils.ip-address. + * * @return ip address */ private static String getNacosIp() { @@ -146,6 +147,7 @@ private static String getNacosIp() { /** * Get ip address. + * * @return ip address */ private static String getPreferHostnameOverIP() { diff --git a/sys/src/test/java/com/alibaba/nacos/sys/utils/InetUtilsTest.java b/sys/src/test/java/com/alibaba/nacos/sys/utils/InetUtilsTest.java index feec5055926..23ee6f3a973 100644 --- a/sys/src/test/java/com/alibaba/nacos/sys/utils/InetUtilsTest.java +++ b/sys/src/test/java/com/alibaba/nacos/sys/utils/InetUtilsTest.java @@ -19,6 +19,7 @@ import com.alibaba.nacos.common.utils.StringUtils; import com.alibaba.nacos.sys.env.Constants; import com.alibaba.nacos.sys.env.EnvUtil; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -47,8 +48,13 @@ public void testRefreshIp() throws InterruptedException { selfIP = InetUtils.getSelfIP(); Assert.assertTrue(StringUtils.equalsIgnoreCase(selfIP, "1.1.1.2")); - + + } + + @After + public void tearDown() { System.clearProperty(NACOS_SERVER_IP); System.clearProperty(Constants.AUTO_REFRESH_TIME); } + } \ No newline at end of file