[Optimize] 整理单元测试代码;

[Optimize] HashSingleCacheStoreTest, ListCacheStoreTest 整理代码;
This commit is contained in:
LamGC 2020-09-04 17:51:02 +08:00
parent 003f571aad
commit 372363085d
Signed by: LamGC
GPG Key ID: 6C5AE2A913941E1D
2 changed files with 11 additions and 2 deletions

View File

@ -33,11 +33,15 @@ public class HashSingleCacheStoreTest {
@Test @Test
public void nullThrowTest() { public void nullThrowTest() {
final SingleCacheStore<String> cacheStore = new HashSingleCacheStore<>(); final SingleCacheStore<String> cacheStore = new HashSingleCacheStore<>();
// HashSingleCacheStore
Assert.assertThrows(NullPointerException.class, () -> cacheStore.set(null, "testValue")); Assert.assertThrows(NullPointerException.class, () -> cacheStore.set(null, "testValue"));
Assert.assertThrows(NullPointerException.class, () -> cacheStore.set("testKey", null)); Assert.assertThrows(NullPointerException.class, () -> cacheStore.set("testKey", null));
Assert.assertThrows(NullPointerException.class, () -> cacheStore.get(null)); Assert.assertThrows(NullPointerException.class, () -> cacheStore.get(null));
Assert.assertThrows(NullPointerException.class, () -> cacheStore.setIfNotExist(null, "testValue")); Assert.assertThrows(NullPointerException.class, () -> cacheStore.setIfNotExist(null, "testValue"));
Assert.assertThrows(NullPointerException.class, () -> cacheStore.setIfNotExist("testKey", null)); Assert.assertThrows(NullPointerException.class, () -> cacheStore.setIfNotExist("testKey", null));
// HashCacheStore
Assert.assertThrows(NullPointerException.class, () -> cacheStore.exists(null)); Assert.assertThrows(NullPointerException.class, () -> cacheStore.exists(null));
Assert.assertThrows(NullPointerException.class, () -> cacheStore.getTimeToLive(null)); Assert.assertThrows(NullPointerException.class, () -> cacheStore.getTimeToLive(null));
Assert.assertThrows(NullPointerException.class, () -> cacheStore.setTimeToLive(null, 0)); Assert.assertThrows(NullPointerException.class, () -> cacheStore.setTimeToLive(null, 0));
@ -49,6 +53,7 @@ public class HashSingleCacheStoreTest {
SingleCacheStore<String> cacheStore = new HashSingleCacheStore<>(); SingleCacheStore<String> cacheStore = new HashSingleCacheStore<>();
final String key = "test01"; final String key = "test01";
final String value = "testValue"; final String value = "testValue";
Assert.assertTrue("Set operation failed!", cacheStore.set(key, value)); Assert.assertTrue("Set operation failed!", cacheStore.set(key, value));
Assert.assertEquals(value, cacheStore.get("test01")); Assert.assertEquals(value, cacheStore.get("test01"));
Assert.assertTrue("Remove operation failed!", cacheStore.remove(key)); Assert.assertTrue("Remove operation failed!", cacheStore.remove(key));
@ -62,6 +67,7 @@ public class HashSingleCacheStoreTest {
final String value = "testValue"; final String value = "testValue";
final String value2 = "testValue02"; final String value2 = "testValue02";
Assert.assertTrue("Set operation failed!", cacheStore.set(key, value)); Assert.assertTrue("Set operation failed!", cacheStore.set(key, value));
Assert.assertFalse(cacheStore.setIfNotExist(key, value2)); Assert.assertFalse(cacheStore.setIfNotExist(key, value2));
Assert.assertEquals(value, cacheStore.get(key)); Assert.assertEquals(value, cacheStore.get(key));
} }
@ -110,10 +116,12 @@ public class HashSingleCacheStoreTest {
final SingleCacheStore<String> cacheStore = new HashSingleCacheStore<>(); final SingleCacheStore<String> cacheStore = new HashSingleCacheStore<>();
final String key = "test01"; final String key = "test01";
final String value = "testValue"; final String value = "testValue";
Assert.assertTrue("Set operation failed!", cacheStore.set(key, value)); 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.assertTrue("Clear operation failed!", cacheStore.clear());
Assert.assertFalse("after-exists operation failed!", cacheStore.exists(key)); Assert.assertFalse(cacheStore.exists(key));
} }
@Test @Test

View File

@ -60,6 +60,7 @@ public class ListCacheStoreTest {
public void notExistCacheTest() { public void notExistCacheTest() {
final ListCacheStore<String> cacheStore = new CopyOnWriteArrayListCacheStore<>(); final ListCacheStore<String> cacheStore = new CopyOnWriteArrayListCacheStore<>();
final String key = "testKey"; final String key = "testKey";
Assert.assertFalse(cacheStore.clearCollection(key)); Assert.assertFalse(cacheStore.clearCollection(key));
Assert.assertFalse(cacheStore.isEmpty(key)); Assert.assertFalse(cacheStore.isEmpty(key));
Assert.assertEquals(-1, cacheStore.elementsLength(key)); Assert.assertEquals(-1, cacheStore.elementsLength(key));