From 372363085d1b469d9528634debe42c7c1b5aa88a Mon Sep 17 00:00:00 2001 From: LamGC Date: Fri, 4 Sep 2020 17:51:02 +0800 Subject: [PATCH] =?UTF-8?q?[Optimize]=20=E6=95=B4=E7=90=86=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95=E4=BB=A3=E7=A0=81;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [Optimize] HashSingleCacheStoreTest, ListCacheStoreTest 整理代码; --- .../bot/cache/local/HashSingleCacheStoreTest.java | 12 ++++++++++-- .../cgj/bot/cache/local/ListCacheStoreTest.java | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/ContentGrabbingJi-CacheStore-local/src/test/java/net/lamgc/cgj/bot/cache/local/HashSingleCacheStoreTest.java b/ContentGrabbingJi-CacheStore-local/src/test/java/net/lamgc/cgj/bot/cache/local/HashSingleCacheStoreTest.java index 18ad180..f97b27d 100644 --- a/ContentGrabbingJi-CacheStore-local/src/test/java/net/lamgc/cgj/bot/cache/local/HashSingleCacheStoreTest.java +++ b/ContentGrabbingJi-CacheStore-local/src/test/java/net/lamgc/cgj/bot/cache/local/HashSingleCacheStoreTest.java @@ -33,11 +33,15 @@ public class HashSingleCacheStoreTest { @Test public void nullThrowTest() { final SingleCacheStore cacheStore = new HashSingleCacheStore<>(); + + // HashSingleCacheStore Assert.assertThrows(NullPointerException.class, () -> cacheStore.set(null, "testValue")); Assert.assertThrows(NullPointerException.class, () -> cacheStore.set("testKey", null)); Assert.assertThrows(NullPointerException.class, () -> cacheStore.get(null)); Assert.assertThrows(NullPointerException.class, () -> cacheStore.setIfNotExist(null, "testValue")); Assert.assertThrows(NullPointerException.class, () -> cacheStore.setIfNotExist("testKey", null)); + + // HashCacheStore Assert.assertThrows(NullPointerException.class, () -> cacheStore.exists(null)); Assert.assertThrows(NullPointerException.class, () -> cacheStore.getTimeToLive(null)); Assert.assertThrows(NullPointerException.class, () -> cacheStore.setTimeToLive(null, 0)); @@ -49,6 +53,7 @@ public class HashSingleCacheStoreTest { SingleCacheStore cacheStore = new HashSingleCacheStore<>(); final String key = "test01"; final String value = "testValue"; + Assert.assertTrue("Set operation failed!", cacheStore.set(key, value)); Assert.assertEquals(value, cacheStore.get("test01")); Assert.assertTrue("Remove operation failed!", cacheStore.remove(key)); @@ -62,6 +67,7 @@ public class HashSingleCacheStoreTest { final String value = "testValue"; final String value2 = "testValue02"; Assert.assertTrue("Set operation failed!", cacheStore.set(key, value)); + Assert.assertFalse(cacheStore.setIfNotExist(key, value2)); Assert.assertEquals(value, cacheStore.get(key)); } @@ -110,10 +116,12 @@ public class HashSingleCacheStoreTest { final SingleCacheStore cacheStore = new HashSingleCacheStore<>(); final String key = "test01"; final String value = "testValue"; + Assert.assertTrue("Set operation failed!", cacheStore.set(key, value)); - Assert.assertTrue("before-exists operation failed!", cacheStore.exists(key)); + + Assert.assertTrue(cacheStore.exists(key)); Assert.assertTrue("Clear operation failed!", cacheStore.clear()); - Assert.assertFalse("after-exists operation failed!", cacheStore.exists(key)); + Assert.assertFalse(cacheStore.exists(key)); } @Test diff --git a/ContentGrabbingJi-CacheStore-local/src/test/java/net/lamgc/cgj/bot/cache/local/ListCacheStoreTest.java b/ContentGrabbingJi-CacheStore-local/src/test/java/net/lamgc/cgj/bot/cache/local/ListCacheStoreTest.java index 910689d..4db32bc 100644 --- a/ContentGrabbingJi-CacheStore-local/src/test/java/net/lamgc/cgj/bot/cache/local/ListCacheStoreTest.java +++ b/ContentGrabbingJi-CacheStore-local/src/test/java/net/lamgc/cgj/bot/cache/local/ListCacheStoreTest.java @@ -60,6 +60,7 @@ public class ListCacheStoreTest { public void notExistCacheTest() { final ListCacheStore cacheStore = new CopyOnWriteArrayListCacheStore<>(); final String key = "testKey"; + Assert.assertFalse(cacheStore.clearCollection(key)); Assert.assertFalse(cacheStore.isEmpty(key)); Assert.assertEquals(-1, cacheStore.elementsLength(key));