formatDenyList = InnerWordFormatUtils.formatWordList(denyList, context);
diff --git a/src/test/java/com/github/houbb/sensitive/word/bs/SensitiveWordBsAllowTest.java b/src/test/java/com/github/houbb/sensitive/word/bs/SensitiveWordBsAllowTest.java
new file mode 100644
index 0000000..036431a
--- /dev/null
+++ b/src/test/java/com/github/houbb/sensitive/word/bs/SensitiveWordBsAllowTest.java
@@ -0,0 +1,75 @@
+package com.github.houbb.sensitive.word.bs;
+
+import com.github.houbb.sensitive.word.api.IWordAllow;
+import com.github.houbb.sensitive.word.api.IWordDeny;
+import com.github.houbb.sensitive.word.support.allow.WordAllows;
+import com.github.houbb.sensitive.word.support.deny.WordDenys;
+import com.github.houbb.sensitive.word.support.replace.WordReplaces;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * project: sensitive-word-SensitiveWordBsTest
+ * create on 2020/1/7 23:43
+ *
+ * @author Administrator
+ * @since 0.21.0
+ */
+public class SensitiveWordBsAllowTest {
+
+ /**
+ * 是否包含
+ *
+ * https://github.com/houbb/sensitive-word/issues/76
+ *
+ * @since 0.0.1
+ */
+ @Test
+ public void findAllowTest() {
+ final String text = "三黄片黄片";
+
+ SensitiveWordBs sensitiveWordBs = SensitiveWordBs.newInstance()
+ .wordAllow(new IWordAllow() {
+ @Override
+ public List allow() {
+ return Arrays.asList("三黄片");
+ }
+ })
+ .init();
+
+ Assert.assertEquals("[黄片]", sensitiveWordBs.findAll(text).toString());
+ }
+
+ /**
+ * https://github.com/houbb/sensitive-word/issues/19
+ *
+ * @since 0.21.0
+ */
+ @Test
+ public void bug19FixTest() {
+ final String text = "共产党是白名单不会被检测";
+ final String text2 = "共产党是白名单不会被检测,但是共产是黑名单";
+
+ SensitiveWordBs sensitiveWordBs = SensitiveWordBs.newInstance()
+ .wordAllow(new IWordAllow() {
+ @Override
+ public List allow() {
+ return Arrays.asList("共产党");
+ }
+ })
+ .wordDeny(new IWordDeny() {
+ @Override
+ public List deny() {
+ return Arrays.asList("政府", "国家", "共产");
+ }
+ })
+ .init();
+
+ Assert.assertEquals("[]", sensitiveWordBs.findAll(text).toString());
+ Assert.assertEquals("[共产]", sensitiveWordBs.findAll(text2).toString());
+ }
+
+}
diff --git a/src/test/java/com/github/houbb/sensitive/word/bs/SensitiveWordBsEditWordTest.java b/src/test/java/com/github/houbb/sensitive/word/bs/SensitiveWordBsEditWordTest.java
index 08b79b5..e2df972 100644
--- a/src/test/java/com/github/houbb/sensitive/word/bs/SensitiveWordBsEditWordTest.java
+++ b/src/test/java/com/github/houbb/sensitive/word/bs/SensitiveWordBsEditWordTest.java
@@ -1,5 +1,6 @@
package com.github.houbb.sensitive.word.bs;
+import com.github.houbb.sensitive.word.api.IWordDeny;
import com.github.houbb.sensitive.word.support.allow.WordAllows;
import com.github.houbb.sensitive.word.support.deny.WordDenys;
import org.junit.Assert;
@@ -59,4 +60,52 @@ public class SensitiveWordBsEditWordTest {
Assert.assertEquals("[]", sensitiveWordBs.findAll(text).toString());
}
+
+ /**
+ * @since 0.21.0
+ */
+ @Test
+ public void editWordAllowTest() {
+ final String text = "测试一下新增敏感词白名单,验证一下删除和新增对不对";
+
+ SensitiveWordBs sensitiveWordBs =
+ SensitiveWordBs.newInstance()
+ .wordAllow(WordAllows.empty())
+ .wordDeny(new IWordDeny() {
+ @Override
+ public List deny() {
+ return Arrays.asList("测试", "新增");
+ }
+ })
+ .init();
+
+ // 当前
+ Assert.assertEquals("[测试, 新增, 新增]", sensitiveWordBs.findAll(text).toString());
+
+ // 新增单个
+ sensitiveWordBs.addWordAllow("测试");
+ sensitiveWordBs.addWordAllow("新增");
+ Assert.assertEquals("[]", sensitiveWordBs.findAll(text).toString());
+
+ // 删除单个
+ sensitiveWordBs.removeWordAllow("测试");
+ Assert.assertEquals("[测试]", sensitiveWordBs.findAll(text).toString());
+ sensitiveWordBs.removeWordAllow("新增");
+ Assert.assertEquals("[测试, 新增, 新增]", sensitiveWordBs.findAll(text).toString());
+
+ // 新增集合
+ sensitiveWordBs.addWordAllow(Arrays.asList("新增", "测试"));
+ Assert.assertEquals("[]", sensitiveWordBs.findAll(text).toString());
+ // 删除集合
+ sensitiveWordBs.removeWordAllow(Arrays.asList("新增", "测试"));
+ Assert.assertEquals("[测试, 新增, 新增]", sensitiveWordBs.findAll(text).toString());
+
+ // 新增数组
+ sensitiveWordBs.addWordAllow("新增", "测试");
+ Assert.assertEquals("[]", sensitiveWordBs.findAll(text).toString());
+ // 删除集合
+ sensitiveWordBs.removeWordAllow("新增", "测试");
+ Assert.assertEquals("[测试, 新增, 新增]", sensitiveWordBs.findAll(text).toString());
+ }
+
}