mirror of
https://github.com/LamGC/ContentGrabbingJi.git
synced 2025-07-01 21:07:25 +00:00
[Add] CacheStore-Local 添加单元测试以完善模块单元测试覆盖;
[Add] LocalCacheStoreFactoryTest 添加针对 LocalCacheStoreFactory 的单元测试类; [Add] HashSetCacheStoreTest 添加针对 HashSetCacheStore 的单元测试类;
This commit is contained in:
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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<String> store = new HashSetCacheStore<>();
|
||||||
|
final CacheKey key = new CacheKey("test");
|
||||||
|
Assert.assertNull(store.getCacheItemCollection(key, false));
|
||||||
|
|
||||||
|
Set<String> collection = store.getCacheItemCollection(key, true);
|
||||||
|
Assert.assertNotNull(collection);
|
||||||
|
|
||||||
|
Assert.assertEquals(collection, store.getCacheItemCollection(key, false));
|
||||||
|
}
|
||||||
|
}
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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<String> 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<String> cacheStore = createLocalCacheStoreFactory().newSingleCacheStore(IDENTIFY, CONVERTER);
|
||||||
|
Assert.assertEquals(HashSingleCacheStore.class, cacheStore.getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void newListCacheStore() {
|
||||||
|
ListCacheStore<String> cacheStore = createLocalCacheStoreFactory().newListCacheStore(IDENTIFY, CONVERTER);
|
||||||
|
Assert.assertEquals(CopyOnWriteArrayListCacheStore.class, cacheStore.getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void newSetCacheStore() {
|
||||||
|
SetCacheStore<String> cacheStore = createLocalCacheStoreFactory().newSetCacheStore(IDENTIFY, CONVERTER);
|
||||||
|
Assert.assertEquals(HashSetCacheStore.class, cacheStore.getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void newMapCacheStore() {
|
||||||
|
MapCacheStore<String> cacheStore = createLocalCacheStoreFactory().newMapCacheStore(IDENTIFY, CONVERTER);
|
||||||
|
Assert.assertEquals(HashMapCacheStore.class, cacheStore.getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void canGetCacheStore() {
|
||||||
|
Assert.assertTrue(createLocalCacheStoreFactory().canGetCacheStore());
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user