pipeline) {
+ pipeline.addLast(wordDeny);
+
+ if(ArrayUtil.isNotEmpty(others)) {
+ for(IWordDeny other : others) {
+ pipeline.addLast(other);
+ }
+ }
+ }
+ };
+ }
+
+ /**
+ * 系统实现
+ * @return 结果
+ * @since 0.0.13
+ */
+ public static IWordDeny system() {
+ return Instances.singleton(WordDenySystem.class);
+ }
+
+}
diff --git a/src/main/resources/dict.txt b/src/main/resources/dict.txt
index 127800d..a15e8db 100644
--- a/src/main/resources/dict.txt
+++ b/src/main/resources/dict.txt
@@ -1,4 +1,3 @@
-
001工程
007手机防盗软件任意显软件
007间谍专业版
diff --git a/src/test/java/com/github/houbb/sensitive/word/bs/SensitiveWordBsTest.java b/src/test/java/com/github/houbb/sensitive/word/bs/SensitiveWordBsTest.java
index 75cea85..7067d5c 100644
--- a/src/test/java/com/github/houbb/sensitive/word/bs/SensitiveWordBsTest.java
+++ b/src/test/java/com/github/houbb/sensitive/word/bs/SensitiveWordBsTest.java
@@ -1,5 +1,7 @@
package com.github.houbb.sensitive.word.bs;
+import com.github.houbb.sensitive.word.support.allow.WordAllows;
+import com.github.houbb.sensitive.word.support.deny.WordDenys;
import org.junit.Assert;
import org.junit.Test;
@@ -97,4 +99,15 @@ public class SensitiveWordBsTest {
Assert.assertEquals("fuck", word);
}
+ @Test
+ public void configTest() {
+ SensitiveWordBs wordBs = SensitiveWordBs.newInstance()
+ .wordDeny(WordDenys.system())
+ .wordAllow(WordAllows.system())
+ .init();
+
+ final String text = "五星红旗迎风飘扬,毛主席的画像屹立在天安门前。";
+ Assert.assertTrue(wordBs.contains(text));
+ }
+
}
diff --git a/src/test/java/com/github/houbb/sensitive/word/core/SensitiveWordHelperTest.java b/src/test/java/com/github/houbb/sensitive/word/core/SensitiveWordHelperTest.java
new file mode 100644
index 0000000..1357206
--- /dev/null
+++ b/src/test/java/com/github/houbb/sensitive/word/core/SensitiveWordHelperTest.java
@@ -0,0 +1,100 @@
+package com.github.houbb.sensitive.word.core;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.List;
+
+/**
+ * project: sensitive-word-SensitiveWordBsTest
+ * create on 2020/1/7 23:43
+ *
+ * @author Administrator
+ * @since 0.0.13
+ */
+public class SensitiveWordHelperTest {
+
+ /**
+ * 是否包含
+ * @since 0.0.1
+ */
+ @Test
+ public void containsTest() {
+ final String text = "五星红旗迎风飘扬,毛主席的画像屹立在天安门前。";
+
+ Assert.assertTrue(SensitiveWordHelper.contains(text));
+ }
+
+ /**
+ * 返回所有敏感词
+ * @since 0.0.1
+ */
+ @Test
+ public void findAllTest() {
+ final String text = "五星红旗迎风飘扬,毛主席的画像屹立在天安门前。";
+
+ List wordList = SensitiveWordHelper.findAll(text);
+ Assert.assertEquals("[五星红旗, 毛主席, 天安门]", wordList.toString());
+ }
+
+ /**
+ * 返回所有第一个匹配的敏感词
+ * @since 0.0.1
+ */
+ @Test
+ public void findFirstTest() {
+ final String text = "五星红旗迎风飘扬,毛主席的画像屹立在天安门前。";
+
+ String word = SensitiveWordHelper.findFirst(text);
+ Assert.assertEquals("五星红旗", word);
+ }
+
+ /**
+ * 默认的替换策略
+ * @since 0.0.2
+ */
+ @Test
+ public void replaceTest() {
+ final String text = "五星红旗迎风飘扬,毛主席的画像屹立在天安门前。";
+
+ String result = SensitiveWordHelper.replace(text);
+ Assert.assertEquals("****迎风飘扬,***的画像屹立在***前。", result);
+ }
+
+ /**
+ * 自定义字符的替换策略
+ * @since 0.0.2
+ */
+ @Test
+ public void replaceCharTest() {
+ final String text = "五星红旗迎风飘扬,毛主席的画像屹立在天安门前。";
+
+ String result = SensitiveWordHelper.replace(text, '0');
+ Assert.assertEquals("0000迎风飘扬,000的画像屹立在000前。", result);
+ }
+
+ /**
+ * 忽略大小写
+ * @since 0.0.4
+ */
+ @Test
+ public void ignoreCaseTest() {
+ final String text = "fuCK the bad words.";
+
+ String word = SensitiveWordHelper.findFirst(text);
+ Assert.assertEquals("fuCK", word);
+ }
+
+ /**
+ * 忽略半角圆角
+ * @since 0.0.4
+ */
+ @Test
+ public void ignoreWidthTest() {
+ final String text = "fuck the bad words.";
+
+ String word = SensitiveWordHelper.findFirst(text);
+ Assert.assertEquals("fuck", word);
+ }
+
+}