diff --git a/ContentGrabbingJi-common/src/main/java/net/lamgc/cgj/bot/cache/FactoryInfo.java b/ContentGrabbingJi-common/src/main/java/net/lamgc/cgj/bot/cache/FactoryInfo.java
index 09e15b0..16eff5c 100644
--- a/ContentGrabbingJi-common/src/main/java/net/lamgc/cgj/bot/cache/FactoryInfo.java
+++ b/ContentGrabbingJi-common/src/main/java/net/lamgc/cgj/bot/cache/FactoryInfo.java
@@ -84,11 +84,11 @@ public final class FactoryInfo {
return false;
}
FactoryInfo that = (FactoryInfo) o;
- return factoryName.equals(that.factoryName);
+ return factoryName.equals(that.factoryName) && storeSource == that.storeSource;
}
@Override
public int hashCode() {
- return Objects.hash(factoryName);
+ return Objects.hash(factoryName, storeSource);
}
}
diff --git a/ContentGrabbingJi-common/src/test/java/net/lamgc/cgj/bot/cache/FactoryInfoTest.java b/ContentGrabbingJi-common/src/test/java/net/lamgc/cgj/bot/cache/FactoryInfoTest.java
new file mode 100644
index 0000000..dff662b
--- /dev/null
+++ b/ContentGrabbingJi-common/src/test/java/net/lamgc/cgj/bot/cache/FactoryInfoTest.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2020 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;
+
+import net.lamgc.cgj.bot.cache.factory.*;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class FactoryInfoTest {
+
+
+ @Test
+ public void analyticTest() {
+ FactoryInfo infoA = new FactoryInfo(FactoryInfoTestFactory.class);
+ Assert.assertEquals("test-factoryInfo", infoA.getFactoryName());
+ Assert.assertEquals(6, infoA.getFactoryPriority());
+ Assert.assertEquals(CacheStoreSource.MEMORY, infoA.getStoreSource());
+
+ FactoryInfo infoB = new FactoryInfo(FactoryInfoTestFactory.class);
+
+ Assert.assertEquals(infoA, infoB);
+ Assert.assertEquals(infoA.hashCode(), infoB.hashCode());
+ }
+
+ @Test
+ @SuppressWarnings({"SimplifiableAssertion", "EqualsWithItself", "ConstantConditions"})
+ public void equalsTest() {
+ FactoryInfo infoA = new FactoryInfo(FactoryInfoTestFactory.class);
+ FactoryInfo infoB = new FactoryInfo(FactoryInfoTestFactory.class);
+
+ Assert.assertTrue(infoA.equals(infoA));
+ Assert.assertTrue(infoA.equals(infoB));
+
+ Assert.assertFalse(infoA.equals(null));
+ Assert.assertFalse(infoA.equals(new Object()));
+
+ Assert.assertFalse(
+ new FactoryInfo(NameNoEqualFactoryA.class)
+ .equals(new FactoryInfo(NameNoEqualFactoryB.class)));
+
+ Assert.assertFalse(
+ new FactoryInfo(NameNoEqualFactoryA.class)
+ .equals(new FactoryInfo(CacheStoreSourceNoEqualFactory.class)));
+
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void noAnnotationTest() {
+ new FactoryInfo(NoAnnotationFactory.class);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void unnamedTest() {
+ new FactoryInfo(UnnamedFactory.class);
+ }
+
+ @Test
+ public void priorityCheckTest() {
+ FactoryInfo toHighPriorityFactoryInfo = new FactoryInfo(TooHighPriorityFactory.class);
+ Assert.assertEquals(FactoryPriority.PRIORITY_HIGHEST,
+ toHighPriorityFactoryInfo.getFactoryPriority());
+
+ FactoryInfo toLowPriorityFactoryInfo = new FactoryInfo(TooLowPriorityFactory.class);
+ Assert.assertEquals(FactoryPriority.PRIORITY_LOWEST,
+ toLowPriorityFactoryInfo.getFactoryPriority());
+
+ Assert.assertNotEquals(toHighPriorityFactoryInfo, toLowPriorityFactoryInfo);
+
+ }
+
+}
diff --git a/ContentGrabbingJi-common/src/test/java/net/lamgc/cgj/bot/cache/factory/CacheStoreSourceNoEqualFactory.java b/ContentGrabbingJi-common/src/test/java/net/lamgc/cgj/bot/cache/factory/CacheStoreSourceNoEqualFactory.java
new file mode 100644
index 0000000..1d08a64
--- /dev/null
+++ b/ContentGrabbingJi-common/src/test/java/net/lamgc/cgj/bot/cache/factory/CacheStoreSourceNoEqualFactory.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2020 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.factory;
+
+import net.lamgc.cgj.bot.cache.*;
+import net.lamgc.cgj.bot.cache.convert.StringConverter;
+import net.lamgc.cgj.bot.cache.exception.GetCacheStoreException;
+
+import java.io.File;
+
+@Factory(name = "test-NameNoEqualA", source = CacheStoreSource.REMOTE)
+public class CacheStoreSourceNoEqualFactory implements CacheStoreFactory {
+ @Override
+ public void initial(File dataDirectory) {
+
+ }
+
+ @Override
+ public SingleCacheStore newSingleCacheStore(String identify, StringConverter converter) throws GetCacheStoreException {
+ return null;
+ }
+
+ @Override
+ public ListCacheStore newListCacheStore(String identify, StringConverter converter) throws GetCacheStoreException {
+ return null;
+ }
+
+ @Override
+ public SetCacheStore newSetCacheStore(String identify, StringConverter converter) throws GetCacheStoreException {
+ return null;
+ }
+
+ @Override
+ public MapCacheStore newMapCacheStore(String identify, StringConverter converter) throws GetCacheStoreException {
+ return null;
+ }
+
+ @Override
+ public boolean canGetCacheStore() {
+ return false;
+ }
+}
diff --git a/ContentGrabbingJi-common/src/test/java/net/lamgc/cgj/bot/cache/factory/FactoryInfoTestFactory.java b/ContentGrabbingJi-common/src/test/java/net/lamgc/cgj/bot/cache/factory/FactoryInfoTestFactory.java
new file mode 100644
index 0000000..1ddabc8
--- /dev/null
+++ b/ContentGrabbingJi-common/src/test/java/net/lamgc/cgj/bot/cache/factory/FactoryInfoTestFactory.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2020 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.factory;
+
+import net.lamgc.cgj.bot.cache.*;
+import net.lamgc.cgj.bot.cache.convert.StringConverter;
+import net.lamgc.cgj.bot.cache.exception.GetCacheStoreException;
+
+import java.io.File;
+
+@Factory(name = "test-factoryInfo", source = CacheStoreSource.MEMORY, priority = 6)
+public class FactoryInfoTestFactory implements CacheStoreFactory {
+ @Override
+ public void initial(File dataDirectory) {
+
+ }
+
+ @Override
+ public SingleCacheStore newSingleCacheStore(String identify, StringConverter converter) throws GetCacheStoreException {
+ return null;
+ }
+
+ @Override
+ public ListCacheStore newListCacheStore(String identify, StringConverter converter) throws GetCacheStoreException {
+ return null;
+ }
+
+ @Override
+ public SetCacheStore newSetCacheStore(String identify, StringConverter converter) throws GetCacheStoreException {
+ return null;
+ }
+
+ @Override
+ public MapCacheStore newMapCacheStore(String identify, StringConverter converter) throws GetCacheStoreException {
+ return null;
+ }
+
+ @Override
+ public boolean canGetCacheStore() {
+ return false;
+ }
+}
diff --git a/ContentGrabbingJi-common/src/test/java/net/lamgc/cgj/bot/cache/factory/NameNoEqualFactoryA.java b/ContentGrabbingJi-common/src/test/java/net/lamgc/cgj/bot/cache/factory/NameNoEqualFactoryA.java
new file mode 100644
index 0000000..2fc41c5
--- /dev/null
+++ b/ContentGrabbingJi-common/src/test/java/net/lamgc/cgj/bot/cache/factory/NameNoEqualFactoryA.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2020 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.factory;
+
+import net.lamgc.cgj.bot.cache.*;
+import net.lamgc.cgj.bot.cache.convert.StringConverter;
+import net.lamgc.cgj.bot.cache.exception.GetCacheStoreException;
+
+import java.io.File;
+
+@Factory(name = "test-NameNoEqualA")
+public class NameNoEqualFactoryA implements CacheStoreFactory {
+ @Override
+ public void initial(File dataDirectory) {
+
+ }
+
+ @Override
+ public SingleCacheStore newSingleCacheStore(String identify, StringConverter converter) throws GetCacheStoreException {
+ return null;
+ }
+
+ @Override
+ public ListCacheStore newListCacheStore(String identify, StringConverter converter) throws GetCacheStoreException {
+ return null;
+ }
+
+ @Override
+ public SetCacheStore newSetCacheStore(String identify, StringConverter converter) throws GetCacheStoreException {
+ return null;
+ }
+
+ @Override
+ public MapCacheStore newMapCacheStore(String identify, StringConverter converter) throws GetCacheStoreException {
+ return null;
+ }
+
+ @Override
+ public boolean canGetCacheStore() {
+ return false;
+ }
+}
diff --git a/ContentGrabbingJi-common/src/test/java/net/lamgc/cgj/bot/cache/factory/NameNoEqualFactoryB.java b/ContentGrabbingJi-common/src/test/java/net/lamgc/cgj/bot/cache/factory/NameNoEqualFactoryB.java
new file mode 100644
index 0000000..6103b24
--- /dev/null
+++ b/ContentGrabbingJi-common/src/test/java/net/lamgc/cgj/bot/cache/factory/NameNoEqualFactoryB.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2020 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.factory;
+
+import net.lamgc.cgj.bot.cache.*;
+import net.lamgc.cgj.bot.cache.convert.StringConverter;
+import net.lamgc.cgj.bot.cache.exception.GetCacheStoreException;
+
+import java.io.File;
+
+@Factory(name = "test-NameNoEqualB")
+public class NameNoEqualFactoryB implements CacheStoreFactory {
+ @Override
+ public void initial(File dataDirectory) {
+
+ }
+
+ @Override
+ public SingleCacheStore newSingleCacheStore(String identify, StringConverter converter) throws GetCacheStoreException {
+ return null;
+ }
+
+ @Override
+ public ListCacheStore newListCacheStore(String identify, StringConverter converter) throws GetCacheStoreException {
+ return null;
+ }
+
+ @Override
+ public SetCacheStore newSetCacheStore(String identify, StringConverter converter) throws GetCacheStoreException {
+ return null;
+ }
+
+ @Override
+ public MapCacheStore newMapCacheStore(String identify, StringConverter converter) throws GetCacheStoreException {
+ return null;
+ }
+
+ @Override
+ public boolean canGetCacheStore() {
+ return false;
+ }
+}
diff --git a/ContentGrabbingJi-common/src/test/java/net/lamgc/cgj/bot/cache/factory/TooHighPriorityFactory.java b/ContentGrabbingJi-common/src/test/java/net/lamgc/cgj/bot/cache/factory/TooHighPriorityFactory.java
new file mode 100644
index 0000000..b3529a1
--- /dev/null
+++ b/ContentGrabbingJi-common/src/test/java/net/lamgc/cgj/bot/cache/factory/TooHighPriorityFactory.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2020 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.factory;
+
+import net.lamgc.cgj.bot.cache.*;
+import net.lamgc.cgj.bot.cache.convert.StringConverter;
+import net.lamgc.cgj.bot.cache.exception.GetCacheStoreException;
+
+import java.io.File;
+
+@Factory(name = "test-factoryInfo-tooHighPriority", priority = 15)
+public class TooHighPriorityFactory implements CacheStoreFactory {
+ @Override
+ public void initial(File dataDirectory) {
+
+ }
+
+ @Override
+ public SingleCacheStore newSingleCacheStore(String identify, StringConverter converter) throws GetCacheStoreException {
+ return null;
+ }
+
+ @Override
+ public ListCacheStore newListCacheStore(String identify, StringConverter converter) throws GetCacheStoreException {
+ return null;
+ }
+
+ @Override
+ public SetCacheStore newSetCacheStore(String identify, StringConverter converter) throws GetCacheStoreException {
+ return null;
+ }
+
+ @Override
+ public MapCacheStore newMapCacheStore(String identify, StringConverter converter) throws GetCacheStoreException {
+ return null;
+ }
+
+ @Override
+ public boolean canGetCacheStore() {
+ return false;
+ }
+}
diff --git a/ContentGrabbingJi-common/src/test/java/net/lamgc/cgj/bot/cache/factory/TooLowPriorityFactory.java b/ContentGrabbingJi-common/src/test/java/net/lamgc/cgj/bot/cache/factory/TooLowPriorityFactory.java
new file mode 100644
index 0000000..674008a
--- /dev/null
+++ b/ContentGrabbingJi-common/src/test/java/net/lamgc/cgj/bot/cache/factory/TooLowPriorityFactory.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2020 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.factory;
+
+import net.lamgc.cgj.bot.cache.*;
+import net.lamgc.cgj.bot.cache.convert.StringConverter;
+import net.lamgc.cgj.bot.cache.exception.GetCacheStoreException;
+
+import java.io.File;
+
+@Factory(name = "test-factoryInfo-tooLowPriority", priority = -5)
+public class TooLowPriorityFactory implements CacheStoreFactory {
+ @Override
+ public void initial(File dataDirectory) {
+
+ }
+
+ @Override
+ public SingleCacheStore newSingleCacheStore(String identify, StringConverter converter) throws GetCacheStoreException {
+ return null;
+ }
+
+ @Override
+ public ListCacheStore newListCacheStore(String identify, StringConverter converter) throws GetCacheStoreException {
+ return null;
+ }
+
+ @Override
+ public SetCacheStore newSetCacheStore(String identify, StringConverter converter) throws GetCacheStoreException {
+ return null;
+ }
+
+ @Override
+ public MapCacheStore newMapCacheStore(String identify, StringConverter converter) throws GetCacheStoreException {
+ return null;
+ }
+
+ @Override
+ public boolean canGetCacheStore() {
+ return false;
+ }
+}
diff --git a/ContentGrabbingJi-common/src/test/java/net/lamgc/cgj/bot/cache/factory/UnnamedFactory.java b/ContentGrabbingJi-common/src/test/java/net/lamgc/cgj/bot/cache/factory/UnnamedFactory.java
new file mode 100644
index 0000000..b564b3e
--- /dev/null
+++ b/ContentGrabbingJi-common/src/test/java/net/lamgc/cgj/bot/cache/factory/UnnamedFactory.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2020 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.factory;
+
+import net.lamgc.cgj.bot.cache.*;
+import net.lamgc.cgj.bot.cache.convert.StringConverter;
+import net.lamgc.cgj.bot.cache.exception.GetCacheStoreException;
+
+import java.io.File;
+
+@Factory(name = "")
+public class UnnamedFactory implements CacheStoreFactory {
+ @Override
+ public void initial(File dataDirectory) {
+
+ }
+
+ @Override
+ public SingleCacheStore newSingleCacheStore(String identify, StringConverter converter) throws GetCacheStoreException {
+ return null;
+ }
+
+ @Override
+ public ListCacheStore newListCacheStore(String identify, StringConverter converter) throws GetCacheStoreException {
+ return null;
+ }
+
+ @Override
+ public SetCacheStore newSetCacheStore(String identify, StringConverter converter) throws GetCacheStoreException {
+ return null;
+ }
+
+ @Override
+ public MapCacheStore newMapCacheStore(String identify, StringConverter converter) throws GetCacheStoreException {
+ return null;
+ }
+
+ @Override
+ public boolean canGetCacheStore() {
+ return false;
+ }
+}