remove duplicated unused method and move unit test (#3446)
authorkezhenxu94 <kezhenxu94@163.com>
Mon, 11 Feb 2019 02:07:12 +0000 (10:07 +0800)
committerIan Luo <ian.luo@gmail.com>
Mon, 11 Feb 2019 02:07:12 +0000 (10:07 +0800)
dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
dubbo-common/src/test/java/org/apache/dubbo/common/URLTest.java
dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java
dubbo-registry/dubbo-registry-zookeeper/src/test/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistryTest.java

index 6e71e74..31ac91e 100644 (file)
@@ -436,9 +436,8 @@ class URL implements Serializable {
         return urls;\r
     }\r
 \r
-    private String appendDefaultPort(String address, int defaultPort) {\r
-        if (address != null && address.length() > 0\r
-                && defaultPort > 0) {\r
+    static String appendDefaultPort(String address, int defaultPort) {\r
+        if (address != null && address.length() > 0 && defaultPort > 0) {\r
             int i = address.indexOf(':');\r
             if (i < 0) {\r
                 return address + ":" + defaultPort;\r
index b4f547c..8061ab2 100644 (file)
@@ -18,6 +18,7 @@ package org.apache.dubbo.common;
 \r
 import org.apache.dubbo.common.utils.CollectionUtils;\r
 \r
+import org.junit.jupiter.api.Assertions;\r
 import org.junit.jupiter.api.Test;\r
 \r
 import java.io.File;\r
@@ -124,7 +125,7 @@ public class URLTest {
         assertEquals("home/user1/router.js", url.getPath());\r
         assertEquals(0, url.getParameters().size());\r
 \r
-        // Caution!! \r
+        // Caution!!\r
         url = URL.valueOf("file://home/user1/router.js");\r
         //                      ^^ only tow slash!\r
         assertEquals("file", url.getProtocol());\r
@@ -680,4 +681,10 @@ public class URLTest {
         assertEquals("1.0.0", url.getParameter("version"));\r
         assertEquals("morgan", url.getParameter("application"));\r
     }\r
-}
\ No newline at end of file
+\r
+    @Test\r
+    public void testDefaultPort() {\r
+        Assertions.assertEquals("10.20.153.10:2181", URL.appendDefaultPort("10.20.153.10:0", 2181));\r
+        Assertions.assertEquals("10.20.153.10:2181", URL.appendDefaultPort("10.20.153.10", 2181));\r
+    }\r
+}\r
index 3ead544..14c3304 100644 (file)
@@ -79,18 +79,6 @@ public class ZookeeperRegistry extends FailbackRegistry {
         });\r
     }\r
 \r
-    static String appendDefaultPort(String address) {\r
-        if (address != null && address.length() > 0) {\r
-            int i = address.indexOf(':');\r
-            if (i < 0) {\r
-                return address + ":" + DEFAULT_ZOOKEEPER_PORT;\r
-            } else if (Integer.parseInt(address.substring(i + 1)) == 0) {\r
-                return address.substring(0, i + 1) + DEFAULT_ZOOKEEPER_PORT;\r
-            }\r
-        }\r
-        return address;\r
-    }\r
-\r
     @Override\r
     public boolean isAvailable() {\r
         return zkClient.isConnected();\r
index 7420d83..c2dd231 100644 (file)
@@ -36,7 +36,9 @@ import java.util.Map;
 import java.util.Set;\r
 import java.util.concurrent.CountDownLatch;\r
 \r
-import static org.hamcrest.CoreMatchers.*;\r
+import static org.hamcrest.CoreMatchers.is;\r
+import static org.hamcrest.CoreMatchers.nullValue;\r
+import static org.hamcrest.CoreMatchers.not;\r
 import static org.hamcrest.MatcherAssert.assertThat;\r
 import static org.mockito.Mockito.mock;\r
 \r
@@ -66,12 +68,6 @@ public class ZookeeperRegistryTest {
     }\r
 \r
     @Test\r
-    public void testDefaultPort() {\r
-        Assertions.assertEquals("10.20.153.10:2181", ZookeeperRegistry.appendDefaultPort("10.20.153.10:0"));\r
-        Assertions.assertEquals("10.20.153.10:2181", ZookeeperRegistry.appendDefaultPort("10.20.153.10"));\r
-    }\r
-\r
-    @Test\r
     public void testAnyHost() {\r
         Assertions.assertThrows(IllegalStateException.class, () -> {\r
             URL errorUrl = URL.valueOf("multicast://0.0.0.0/");\r
@@ -153,13 +149,8 @@ public class ZookeeperRegistryTest {
     public void testSubscribeAnyValue() throws InterruptedException {\r
         final CountDownLatch latch = new CountDownLatch(1);\r
         zookeeperRegistry.register(serviceUrl);\r
-        zookeeperRegistry.subscribe(anyUrl, new NotifyListener() {\r
-            @Override\r
-            public void notify(List<URL> urls) {\r
-                latch.countDown();\r
-            }\r
-        });\r
+        zookeeperRegistry.subscribe(anyUrl, urls -> latch.countDown());\r
         zookeeperRegistry.register(serviceUrl);\r
         latch.await();\r
     }\r
-}
\ No newline at end of file
+}\r