From 87e6dbb9e7cda8846d1637e876bc49849ac85302 Mon Sep 17 00:00:00 2001 From: LamGC Date: Fri, 1 Jan 2021 12:30:06 +0800 Subject: [PATCH] =?UTF-8?q?[Add]=20CacheStore-Local=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95=E4=BB=A5=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95=E8=A6=86?= =?UTF-8?q?=E7=9B=96;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [Add] LocalCacheStoreFactoryTest 添加针对 LocalCacheStoreFactory 的单元测试类; [Add] HashSetCacheStoreTest 添加针对 HashSetCacheStore 的单元测试类; --- .../cache/local/HashSetCacheStoreTest.java | 45 +++++++++ .../local/LocalCacheStoreFactoryTest.java | 93 +++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 ContentGrabbingJi-CacheStore-local/src/test/java/net/lamgc/cgj/bot/cache/local/HashSetCacheStoreTest.java create mode 100644 ContentGrabbingJi-CacheStore-local/src/test/java/net/lamgc/cgj/bot/cache/local/LocalCacheStoreFactoryTest.java diff --git a/ContentGrabbingJi-CacheStore-local/src/test/java/net/lamgc/cgj/bot/cache/local/HashSetCacheStoreTest.java b/ContentGrabbingJi-CacheStore-local/src/test/java/net/lamgc/cgj/bot/cache/local/HashSetCacheStoreTest.java new file mode 100644 index 0000000..ff85bfa --- /dev/null +++ b/ContentGrabbingJi-CacheStore-local/src/test/java/net/lamgc/cgj/bot/cache/local/HashSetCacheStoreTest.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2021 LamGC + * + * ContentGrabbingJi is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * ContentGrabbingJi is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package net.lamgc.cgj.bot.cache.local; + +import net.lamgc.cgj.bot.cache.CacheKey; +import org.junit.Assert; +import org.junit.Test; + +import java.util.HashSet; +import java.util.Set; + +import static org.junit.Assert.*; + +/** + * @see HashSetCacheStore + */ +public class HashSetCacheStoreTest { + + @Test + public void getCacheItemCollection() { + HashSetCacheStore store = new HashSetCacheStore<>(); + final CacheKey key = new CacheKey("test"); + Assert.assertNull(store.getCacheItemCollection(key, false)); + + Set collection = store.getCacheItemCollection(key, true); + Assert.assertNotNull(collection); + + Assert.assertEquals(collection, store.getCacheItemCollection(key, false)); + } +} \ No newline at end of file diff --git a/ContentGrabbingJi-CacheStore-local/src/test/java/net/lamgc/cgj/bot/cache/local/LocalCacheStoreFactoryTest.java b/ContentGrabbingJi-CacheStore-local/src/test/java/net/lamgc/cgj/bot/cache/local/LocalCacheStoreFactoryTest.java new file mode 100644 index 0000000..c0b446a --- /dev/null +++ b/ContentGrabbingJi-CacheStore-local/src/test/java/net/lamgc/cgj/bot/cache/local/LocalCacheStoreFactoryTest.java @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2021 LamGC + * + * ContentGrabbingJi is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * ContentGrabbingJi is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package net.lamgc.cgj.bot.cache.local; + +import net.lamgc.cgj.bot.cache.ListCacheStore; +import net.lamgc.cgj.bot.cache.MapCacheStore; +import net.lamgc.cgj.bot.cache.SetCacheStore; +import net.lamgc.cgj.bot.cache.SingleCacheStore; +import net.lamgc.cgj.bot.cache.convert.StringConverter; +import net.lamgc.cgj.bot.cache.convert.StringToStringConverter; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import java.io.File; +import java.io.IOException; + +/** + * @see LocalCacheStoreFactory + */ +public class LocalCacheStoreFactoryTest { + + private final static TemporaryFolder tempFolder = TemporaryFolder.builder() + .build(); + + private final static String IDENTIFY = "test"; + private final static StringConverter CONVERTER = new StringToStringConverter(); + private static File storeFolder; + + @BeforeClass + public static void beforeProcess() throws IOException { + tempFolder.create(); + storeFolder = tempFolder.newFolder("cache", "Local-Memory"); + Assert.assertNotNull(createLocalCacheStoreFactory()); + } + + private static LocalCacheStoreFactory createLocalCacheStoreFactory() { + LocalCacheStoreFactory factory = new LocalCacheStoreFactory(); + Assert.assertNotNull(storeFolder); + factory.initial(storeFolder); + return factory; + } + + @Test + public void initial() { + Assert.assertNotNull(createLocalCacheStoreFactory()); + } + + @Test + public void newSingleCacheStore() { + SingleCacheStore cacheStore = createLocalCacheStoreFactory().newSingleCacheStore(IDENTIFY, CONVERTER); + Assert.assertEquals(HashSingleCacheStore.class, cacheStore.getClass()); + } + + @Test + public void newListCacheStore() { + ListCacheStore cacheStore = createLocalCacheStoreFactory().newListCacheStore(IDENTIFY, CONVERTER); + Assert.assertEquals(CopyOnWriteArrayListCacheStore.class, cacheStore.getClass()); + } + + @Test + public void newSetCacheStore() { + SetCacheStore cacheStore = createLocalCacheStoreFactory().newSetCacheStore(IDENTIFY, CONVERTER); + Assert.assertEquals(HashSetCacheStore.class, cacheStore.getClass()); + } + + @Test + public void newMapCacheStore() { + MapCacheStore cacheStore = createLocalCacheStoreFactory().newMapCacheStore(IDENTIFY, CONVERTER); + Assert.assertEquals(HashMapCacheStore.class, cacheStore.getClass()); + } + + @Test + public void canGetCacheStore() { + Assert.assertTrue(createLocalCacheStoreFactory().canGetCacheStore()); + } +} \ No newline at end of file