This is an automated email from the ASF dual-hosted git repository. liubao pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git
commit ae6596d1a9325646fd0ee4b9aca8a0fe24e586d5 Author: laijianbin <[email protected]> AuthorDate: Fri Jun 29 09:54:00 2018 +0800 Update TestNetUtils.java --- .../servicecomb/foundation/common/net/TestNetUtils.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/net/TestNetUtils.java b/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/net/TestNetUtils.java index 34efa4e..f80ce51 100644 --- a/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/net/TestNetUtils.java +++ b/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/net/TestNetUtils.java @@ -111,18 +111,13 @@ public class TestNetUtils { @Test public void testGetHostName() throws Exception { - Assert.assertNotEquals(null, NetUtils.getHostAddress()); Assert.assertNotEquals(null, NetUtils.getHostName()); - - Class<?> clazz = Class.forName("org.apache.servicecomb.foundation.common.net.NetUtils"); - Field hostNameField = clazz.getDeclaredField("hostName"); - hostNameField.setAccessible(true); - hostNameField.set(NetUtils.class, null); + Assert.assertNotEquals(null, NetUtils.getHostAddress()); + + Deencapsulation.setField(NetUtils.class, "hostName", null); Assert.assertNotEquals(null, NetUtils.getHostName()); - - Field hostAddressField = clazz.getDeclaredField("hostAddress"); - hostAddressField.setAccessible(true); - hostAddressField.set(NetUtils.class, null); + + Deencapsulation.setField(NetUtils.class, "hostAddress", null); Assert.assertNotEquals(null, NetUtils.getHostAddress()); }
