You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2018/05/15 10:57:17 UTC

[GitHub] beiwei30 closed pull request #1804: issue#1682: Enhance the test coverage part-4 : dubbo-common/src/main/java/com/alibaba/dubbo/common/status(store|threadpoolutils) modules

beiwei30 closed pull request #1804: issue#1682: Enhance the test coverage part-4 : dubbo-common/src/main/java/com/alibaba/dubbo/common/status(store|threadpoolutils) modules
URL: https://github.com/apache/incubator-dubbo/pull/1804
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/dubbo-common/src/main/java/com/alibaba/dubbo/common/utils/Assert.java b/dubbo-common/src/main/java/com/alibaba/dubbo/common/utils/Assert.java
index 72a242f9bc..040c43d3bb 100644
--- a/dubbo-common/src/main/java/com/alibaba/dubbo/common/utils/Assert.java
+++ b/dubbo-common/src/main/java/com/alibaba/dubbo/common/utils/Assert.java
@@ -28,9 +28,9 @@ public static void notNull(Object obj, String message) {
         }
     }
 
-    public static void notNull(Object obj, RuntimeException exeception) {
+    public static void notNull(Object obj, RuntimeException exception) {
         if (obj == null) {
-            throw exeception;
+            throw exception;
         }
     }
 
diff --git a/dubbo-common/src/main/java/com/alibaba/dubbo/common/utils/ClassHelper.java b/dubbo-common/src/main/java/com/alibaba/dubbo/common/utils/ClassHelper.java
index f6ac8d3bb1..ce9425639d 100644
--- a/dubbo-common/src/main/java/com/alibaba/dubbo/common/utils/ClassHelper.java
+++ b/dubbo-common/src/main/java/com/alibaba/dubbo/common/utils/ClassHelper.java
@@ -20,7 +20,6 @@
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 
@@ -57,12 +56,11 @@
 
         Set<Class<?>> primitiveTypeNames = new HashSet<Class<?>>(16);
         primitiveTypeNames.addAll(primitiveWrapperTypeMap.values());
-        primitiveTypeNames.addAll(Arrays
-                .asList(new Class<?>[]{boolean[].class, byte[].class, char[].class, double[].class,
-                        float[].class, int[].class, long[].class, short[].class}));
-        for (Iterator<Class<?>> it = primitiveTypeNames.iterator(); it.hasNext(); ) {
-            Class<?> primitiveClass = (Class<?>) it.next();
-            primitiveTypeNameMap.put(primitiveClass.getName(), primitiveClass);
+        primitiveTypeNames.addAll(Arrays.asList(
+                boolean[].class, byte[].class, char[].class, double[].class, float[].class, int[].class,
+                long[].class, short[].class));
+        for (Class<?> primitiveTypeName : primitiveTypeNames) {
+            primitiveTypeNameMap.put((primitiveTypeName).getName(), primitiveTypeName);
         }
     }
 
@@ -193,7 +191,7 @@ public static ClassLoader getClassLoader() {
         // SHOULD sit in a package, so a length check is worthwhile.
         if (name != null && name.length() <= 8) {
             // Could be a primitive - likely.
-            result = (Class<?>) primitiveTypeNameMap.get(name);
+            result = primitiveTypeNameMap.get(name);
         }
         return result;
     }
diff --git a/dubbo-common/src/test/java/com/alibaba/dubbo/common/threadpool/support/cached/CachedThreadPoolTest.java b/dubbo-common/src/test/java/com/alibaba/dubbo/common/threadpool/support/cached/CachedThreadPoolTest.java
index 63c7c93b74..083af0f263 100644
--- a/dubbo-common/src/test/java/com/alibaba/dubbo/common/threadpool/support/cached/CachedThreadPoolTest.java
+++ b/dubbo-common/src/test/java/com/alibaba/dubbo/common/threadpool/support/cached/CachedThreadPoolTest.java
@@ -66,7 +66,7 @@ public void run() {
             }
         });
 
-        latch.await(5000, TimeUnit.MICROSECONDS);
+        latch.await();
         assertThat(latch.getCount(), is(0L));
     }
 
diff --git a/dubbo-common/src/test/java/com/alibaba/dubbo/common/threadpool/support/eager/EagerThreadPoolTest.java b/dubbo-common/src/test/java/com/alibaba/dubbo/common/threadpool/support/eager/EagerThreadPoolTest.java
index a7f240896d..8d3e939601 100644
--- a/dubbo-common/src/test/java/com/alibaba/dubbo/common/threadpool/support/eager/EagerThreadPoolTest.java
+++ b/dubbo-common/src/test/java/com/alibaba/dubbo/common/threadpool/support/eager/EagerThreadPoolTest.java
@@ -67,7 +67,7 @@ public void run() {
             }
         });
 
-        latch.await(5000, TimeUnit.MICROSECONDS);
+        latch.await();
         assertThat(latch.getCount(), is(0L));
     }
 
diff --git a/dubbo-common/src/test/java/com/alibaba/dubbo/common/threadpool/support/fixed/FixedThreadPoolTest.java b/dubbo-common/src/test/java/com/alibaba/dubbo/common/threadpool/support/fixed/FixedThreadPoolTest.java
index faefe6f4d5..9d285f6511 100644
--- a/dubbo-common/src/test/java/com/alibaba/dubbo/common/threadpool/support/fixed/FixedThreadPoolTest.java
+++ b/dubbo-common/src/test/java/com/alibaba/dubbo/common/threadpool/support/fixed/FixedThreadPoolTest.java
@@ -67,7 +67,7 @@ public void run() {
             }
         });
 
-        latch.await(5000, TimeUnit.MICROSECONDS);
+        latch.await();
         assertThat(latch.getCount(), is(0L));
     }
 
diff --git a/dubbo-common/src/test/java/com/alibaba/dubbo/common/threadpool/support/limited/LimitedThreadPoolTest.java b/dubbo-common/src/test/java/com/alibaba/dubbo/common/threadpool/support/limited/LimitedThreadPoolTest.java
index b99ce6c8cc..d58da069b4 100644
--- a/dubbo-common/src/test/java/com/alibaba/dubbo/common/threadpool/support/limited/LimitedThreadPoolTest.java
+++ b/dubbo-common/src/test/java/com/alibaba/dubbo/common/threadpool/support/limited/LimitedThreadPoolTest.java
@@ -65,7 +65,7 @@ public void run() {
             }
         });
 
-        latch.await(5000, TimeUnit.MICROSECONDS);
+        latch.await();
         assertThat(latch.getCount(), is(0L));
     }
 
diff --git a/dubbo-common/src/test/java/com/alibaba/dubbo/common/utils/AssertTest.java b/dubbo-common/src/test/java/com/alibaba/dubbo/common/utils/AssertTest.java
new file mode 100644
index 0000000000..ec390b5ad8
--- /dev/null
+++ b/dubbo-common/src/test/java/com/alibaba/dubbo/common/utils/AssertTest.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.alibaba.dubbo.common.utils;
+
+import org.junit.Test;
+
+import static com.alibaba.dubbo.common.utils.Assert.notNull;
+
+public class AssertTest {
+    @Test(expected = IllegalArgumentException.class)
+    public void testNotNull1() throws Exception {
+        notNull(null, "null object");
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void testNotNull2() throws Exception {
+        notNull(null, new IllegalStateException("null object"));
+    }
+}
diff --git a/dubbo-common/src/test/java/com/alibaba/dubbo/common/utils/AtomicPositiveIntegerTest.java b/dubbo-common/src/test/java/com/alibaba/dubbo/common/utils/AtomicPositiveIntegerTest.java
index 65873530df..32d014e50d 100644
--- a/dubbo-common/src/test/java/com/alibaba/dubbo/common/utils/AtomicPositiveIntegerTest.java
+++ b/dubbo-common/src/test/java/com/alibaba/dubbo/common/utils/AtomicPositiveIntegerTest.java
@@ -19,27 +19,29 @@
 import org.junit.Test;
 
 import static org.hamcrest.CoreMatchers.allOf;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.fail;
-import static org.junit.matchers.JUnitMatchers.containsString;
 
 public class AtomicPositiveIntegerTest {
-    AtomicPositiveInteger i1 = new AtomicPositiveInteger();
+    private AtomicPositiveInteger i1 = new AtomicPositiveInteger();
 
-    AtomicPositiveInteger i2 = new AtomicPositiveInteger(127);
+    private AtomicPositiveInteger i2 = new AtomicPositiveInteger(127);
 
-    AtomicPositiveInteger i3 = new AtomicPositiveInteger(Integer.MAX_VALUE);
+    private AtomicPositiveInteger i3 = new AtomicPositiveInteger(Integer.MAX_VALUE);
 
     @Test
-    public void test_get() throws Exception {
+    public void testGet() throws Exception {
         assertEquals(0, i1.get());
         assertEquals(127, i2.get());
         assertEquals(Integer.MAX_VALUE, i3.get());
     }
 
     @Test
-    public void test_set() throws Exception {
+    public void testSet() throws Exception {
         i1.set(100);
         assertEquals(100, i1.get());
 
@@ -53,7 +55,7 @@ public void test_set() throws Exception {
     }
 
     @Test
-    public void test_getAndIncrement() throws Exception {
+    public void testGetAndIncrement() throws Exception {
         int get = i1.getAndIncrement();
         assertEquals(0, get);
         assertEquals(1, i1.get());
@@ -68,7 +70,7 @@ public void test_getAndIncrement() throws Exception {
     }
 
     @Test
-    public void test_getAndDecrement() throws Exception {
+    public void testGetAndDecrement() throws Exception {
         int get = i1.getAndDecrement();
         assertEquals(0, get);
         assertEquals(Integer.MAX_VALUE, i1.get());
@@ -83,7 +85,7 @@ public void test_getAndDecrement() throws Exception {
     }
 
     @Test
-    public void test_incrementAndGet() throws Exception {
+    public void testIncrementAndGet() throws Exception {
         int get = i1.incrementAndGet();
         assertEquals(1, get);
         assertEquals(1, i1.get());
@@ -98,7 +100,7 @@ public void test_incrementAndGet() throws Exception {
     }
 
     @Test
-    public void test_decrementAndGet() throws Exception {
+    public void testDecrementAndGet() throws Exception {
         int get = i1.decrementAndGet();
         assertEquals(Integer.MAX_VALUE, get);
         assertEquals(Integer.MAX_VALUE, i1.get());
@@ -113,7 +115,7 @@ public void test_decrementAndGet() throws Exception {
     }
 
     @Test
-    public void test_getAndSet() throws Exception {
+    public void testGetAndSet() throws Exception {
         int get = i1.getAndSet(100);
         assertEquals(0, get);
         assertEquals(100, i1.get());
@@ -127,7 +129,7 @@ public void test_getAndSet() throws Exception {
     }
 
     @Test
-    public void test_getAndAnd() throws Exception {
+    public void testGetAndAnd() throws Exception {
         int get = i1.getAndAdd(3);
         assertEquals(0, get);
         assertEquals(3, i1.get());
@@ -143,7 +145,7 @@ public void test_getAndAnd() throws Exception {
 
 
     @Test
-    public void test_addAndGet() throws Exception {
+    public void testAddAndGet() throws Exception {
         int get = i1.addAndGet(3);
         assertEquals(3, get);
         assertEquals(3, i1.get());
@@ -157,8 +159,42 @@ public void test_addAndGet() throws Exception {
         assertEquals(2, i3.get());
     }
 
+    @Test(expected = IllegalArgumentException.class)
+    public void testCompareAndSet1() throws Exception {
+        i1.compareAndSet(i1.get(), -1);
+    }
+
+    @Test
+    public void testCompareAndSet2() throws Exception {
+        assertThat(i1.compareAndSet(i1.get(), 2), is(true));
+        assertThat(i1.get(), is(2));
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testWeakCompareAndSet1() throws Exception {
+        i1.weakCompareAndSet(i1.get(), -1);
+    }
+
+    @Test
+    public void testWeakCompareAndSet2() throws Exception {
+        assertThat(i1.weakCompareAndSet(i1.get(), 2), is(true));
+        assertThat(i1.get(), is(2));
+    }
+
+    @Test
+    public void testValues() throws Exception {
+        Integer i = i1.get();
+        assertThat(i1.byteValue(), equalTo(i.byteValue()));
+        assertThat(i1.shortValue(), equalTo(i.shortValue()));
+        assertThat(i1.intValue(), equalTo(i.intValue()));
+        assertThat(i1.longValue(), equalTo(i.longValue()));
+        assertThat(i1.floatValue(), equalTo(i.floatValue()));
+        assertThat(i1.doubleValue(), equalTo(i.doubleValue()));
+        assertThat(i1.toString(), equalTo(i.toString()));
+    }
+
     @Test
-    public void test_equals() {
+    public void testEquals() {
         assertEquals(new AtomicPositiveInteger(), new AtomicPositiveInteger());
         assertEquals(new AtomicPositiveInteger(1), new AtomicPositiveInteger(1));
     }
diff --git a/dubbo-common/src/test/java/com/alibaba/dubbo/common/utils/ClassHelperTest.java b/dubbo-common/src/test/java/com/alibaba/dubbo/common/utils/ClassHelperTest.java
new file mode 100644
index 0000000000..834fcc1ad8
--- /dev/null
+++ b/dubbo-common/src/test/java/com/alibaba/dubbo/common/utils/ClassHelperTest.java
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.alibaba.dubbo.common.utils;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import static com.alibaba.dubbo.common.utils.ClassHelper.forName;
+import static com.alibaba.dubbo.common.utils.ClassHelper.getCallerClassLoader;
+import static com.alibaba.dubbo.common.utils.ClassHelper.getClassLoader;
+import static com.alibaba.dubbo.common.utils.ClassHelper.resolvePrimitiveClassName;
+import static com.alibaba.dubbo.common.utils.ClassHelper.toShortString;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.sameInstance;
+import static org.hamcrest.Matchers.startsWith;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.verify;
+
+public class ClassHelperTest {
+    @Test
+    public void testForNameWithThreadContextClassLoader() throws Exception {
+        ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
+        try {
+            ClassLoader classLoader = Mockito.mock(ClassLoader.class);
+            Thread.currentThread().setContextClassLoader(classLoader);
+            ClassHelper.forNameWithThreadContextClassLoader("a.b.c.D");
+            verify(classLoader).loadClass("a.b.c.D");
+        } finally {
+            Thread.currentThread().setContextClassLoader(oldClassLoader);
+        }
+    }
+
+    @Test
+    public void tetForNameWithCallerClassLoader() throws Exception {
+        Class c = ClassHelper.forNameWithCallerClassLoader(ClassHelper.class.getName(), ClassHelperTest.class);
+        assertThat(c == ClassHelper.class, is(true));
+    }
+
+    @Test
+    public void testGetCallerClassLoader() throws Exception {
+        assertThat(getCallerClassLoader(ClassHelperTest.class), sameInstance(ClassHelperTest.class.getClassLoader()));
+    }
+
+    @Test
+    public void testGetClassLoader1() throws Exception {
+        ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
+        try {
+            assertThat(getClassLoader(ClassHelperTest.class), sameInstance(oldClassLoader));
+            Thread.currentThread().setContextClassLoader(null);
+            assertThat(getClassLoader(ClassHelperTest.class), sameInstance(ClassHelperTest.class.getClassLoader()));
+        } finally {
+            Thread.currentThread().setContextClassLoader(oldClassLoader);
+        }
+    }
+
+    @Test
+    public void testGetClassLoader2() throws Exception {
+        assertThat(getClassLoader(), sameInstance(ClassHelper.class.getClassLoader()));
+    }
+
+    @Test
+    public void testForName1() throws Exception {
+        assertThat(forName(ClassHelperTest.class.getName()) == ClassHelperTest.class, is(true));
+    }
+
+    @Test
+    public void testForName2() throws Exception {
+        assertThat(forName("byte") == byte.class, is(true));
+        assertThat(forName("java.lang.String[]") == String[].class, is(true));
+        assertThat(forName("[Ljava.lang.String;") == String[].class, is(true));
+    }
+
+    @Test
+    public void testForName3() throws Exception {
+        ClassLoader classLoader = Mockito.mock(ClassLoader.class);
+        forName("a.b.c.D", classLoader);
+        verify(classLoader).loadClass("a.b.c.D");
+    }
+
+    @Test
+    public void testResolvePrimitiveClassName() throws Exception {
+        assertThat(resolvePrimitiveClassName("boolean") == boolean.class, is(true));
+        assertThat(resolvePrimitiveClassName("byte") == byte.class, is(true));
+        assertThat(resolvePrimitiveClassName("char") == char.class, is(true));
+        assertThat(resolvePrimitiveClassName("double") == double.class, is(true));
+        assertThat(resolvePrimitiveClassName("float") == float.class, is(true));
+        assertThat(resolvePrimitiveClassName("int") == int.class, is(true));
+        assertThat(resolvePrimitiveClassName("long") == long.class, is(true));
+        assertThat(resolvePrimitiveClassName("short") == short.class, is(true));
+        assertThat(resolvePrimitiveClassName("[Z") == boolean[].class, is(true));
+        assertThat(resolvePrimitiveClassName("[B") == byte[].class, is(true));
+        assertThat(resolvePrimitiveClassName("[C") == char[].class, is(true));
+        assertThat(resolvePrimitiveClassName("[D") == double[].class, is(true));
+        assertThat(resolvePrimitiveClassName("[F") == float[].class, is(true));
+        assertThat(resolvePrimitiveClassName("[I") == int[].class, is(true));
+        assertThat(resolvePrimitiveClassName("[J") == long[].class, is(true));
+        assertThat(resolvePrimitiveClassName("[S") == short[].class, is(true));
+    }
+
+    @Test
+    public void testToShortString() throws Exception {
+        assertThat(toShortString(null), equalTo("null"));
+        assertThat(toShortString(new ClassHelperTest()), startsWith("ClassHelperTest@"));
+    }
+}
diff --git a/dubbo-common/src/test/java/com/alibaba/dubbo/common/utils/CollectionUtilsTest.java b/dubbo-common/src/test/java/com/alibaba/dubbo/common/utils/CollectionUtilsTest.java
index d23f6d62df..996817e5cf 100644
--- a/dubbo-common/src/test/java/com/alibaba/dubbo/common/utils/CollectionUtilsTest.java
+++ b/dubbo-common/src/test/java/com/alibaba/dubbo/common/utils/CollectionUtilsTest.java
@@ -22,17 +22,27 @@
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 
+import static com.alibaba.dubbo.common.utils.CollectionUtils.isEmpty;
+import static com.alibaba.dubbo.common.utils.CollectionUtils.isNotEmpty;
+import static com.alibaba.dubbo.common.utils.CollectionUtils.toMap;
+import static com.alibaba.dubbo.common.utils.CollectionUtils.toStringMap;
+import static java.util.Collections.emptyList;
+import static java.util.Collections.singleton;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.is;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
 public class CollectionUtilsTest {
     @Test
-    public void test_sort() throws Exception {
+    public void testSort() throws Exception {
         List<Integer> list = new ArrayList<Integer>();
         list.add(100);
         list.add(10);
@@ -47,14 +57,14 @@ public void test_sort() throws Exception {
     }
 
     @Test
-    public void test_sort_null() throws Exception {
+    public void testSortNull() throws Exception {
         assertNull(CollectionUtils.sort(null));
 
         assertTrue(CollectionUtils.sort(new ArrayList<Integer>()).isEmpty());
     }
 
     @Test
-    public void test_sortSimpleName() throws Exception {
+    public void testSortSimpleName() throws Exception {
         List<String> list = new ArrayList<String>();
         list.add("aaa.z");
         list.add("b");
@@ -69,14 +79,14 @@ public void test_sortSimpleName() throws Exception {
     }
 
     @Test
-    public void test_sortSimpleName_null() throws Exception {
+    public void testSortSimpleNameNull() throws Exception {
         assertNull(CollectionUtils.sortSimpleName(null));
 
         assertTrue(CollectionUtils.sortSimpleName(new ArrayList<String>()).isEmpty());
     }
 
     @Test
-    public void test_splitAll() throws Exception {
+    public void testSplitAll() throws Exception {
         assertNull(CollectionUtils.splitAll(null, null));
         assertNull(CollectionUtils.splitAll(null, "-"));
 
@@ -98,7 +108,7 @@ public void test_splitAll() throws Exception {
     }
 
     @Test
-    public void test_joinAll() throws Exception {
+    public void testJoinAll() throws Exception {
         assertNull(CollectionUtils.joinAll(null, null));
         assertNull(CollectionUtils.joinAll(null, "-"));
 
@@ -125,7 +135,7 @@ public void test_joinAll() throws Exception {
     }
 
     @Test
-    public void test_joinList() throws Exception {
+    public void testJoinList() throws Exception {
         List<String> list = Arrays.asList();
         assertEquals("", CollectionUtils.join(list, "/"));
 
@@ -137,7 +147,7 @@ public void test_joinList() throws Exception {
     }
 
     @Test
-    public void test_mapEquals() throws Exception {
+    public void testMapEquals() throws Exception {
         assertTrue(CollectionUtils.mapEquals(null, null));
         assertFalse(CollectionUtils.mapEquals(null, new HashMap<String, String>()));
         assertFalse(CollectionUtils.mapEquals(new HashMap<String, String>(), null));
@@ -147,9 +157,18 @@ public void test_mapEquals() throws Exception {
     }
 
     @Test
-    public void test_toMap() throws Exception {
-        assertTrue(CollectionUtils.toMap().isEmpty());
+    public void testStringMap1() throws Exception {
+        assertThat(toStringMap("key", "value"), equalTo(Collections.singletonMap("key", "value")));
+    }
 
+    @Test(expected = IllegalArgumentException.class)
+    public void testStringMap2() throws Exception {
+        toStringMap("key", "value", "odd");
+    }
+
+    @Test
+    public void testToMap1() throws Exception {
+        assertTrue(CollectionUtils.toMap().isEmpty());
 
         Map<String, Integer> expected = new HashMap<String, Integer>();
         expected.put("a", 1);
@@ -158,4 +177,21 @@ public void test_toMap() throws Exception {
 
         assertEquals(expected, CollectionUtils.toMap("a", 1, "b", 2, "c", 3));
     }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testToMap2() throws Exception {
+        toMap("a", "b", "c");
+    }
+
+    @Test
+    public void testIsEmpty() throws Exception {
+        assertThat(isEmpty(null), is(true));
+        assertThat(isEmpty(new HashSet()), is(true));
+        assertThat(isEmpty(emptyList()), is(true));
+    }
+
+    @Test
+    public void testIsNotEmpty() throws Exception {
+        assertThat(isNotEmpty(singleton("a")), is(true));
+    }
 }
\ No newline at end of file


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org