mirror of
https://github.com/houbb/sensitive-word.git
synced 2026-03-22 16:37:17 +08:00
add for test
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package com.github.houbb.sensitive.word.define;
|
||||
|
||||
import com.github.houbb.sensitive.word.api.IWordAllow;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author binbin.hou
|
||||
* @since 0.0.14
|
||||
*/
|
||||
public class MyWordAllow implements IWordAllow {
|
||||
|
||||
@Override
|
||||
public List<String> allow() {
|
||||
return Arrays.asList("测试");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.github.houbb.sensitive.word.define;
|
||||
|
||||
import com.github.houbb.sensitive.word.api.IWordDeny;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author binbin.hou
|
||||
* @since 0.0.14
|
||||
*/
|
||||
public class MyWordDeny implements IWordDeny {
|
||||
|
||||
@Override
|
||||
public List<String> deny() {
|
||||
return Arrays.asList("我的自定义敏感词");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.github.houbb.sensitive.word.define;
|
||||
|
||||
import com.github.houbb.sensitive.word.api.IWordAllow;
|
||||
import com.github.houbb.sensitive.word.api.IWordDeny;
|
||||
import com.github.houbb.sensitive.word.bs.SensitiveWordBs;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author binbin.hou
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class SensitiveWordBsDefineTest {
|
||||
|
||||
@Test
|
||||
public void defineDenyTest() {
|
||||
String text = "这是一个测试,我的自定义敏感词。";
|
||||
|
||||
SensitiveWordBs wordBs = SensitiveWordBs.newInstance()
|
||||
.wordDeny(new MyWordDeny())
|
||||
.wordAllow(new MyWordAllow())
|
||||
.init();
|
||||
|
||||
Assert.assertEquals("[我的自定义敏感词]", wordBs.findAll(text).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defineChainsTest() {
|
||||
String text = "这是一个测试。我的自定义敏感词。";
|
||||
|
||||
IWordDeny wordDeny = WordDenys.chains(WordDenys.system(), new MyWordDeny());
|
||||
IWordAllow wordAllow = WordAllows.chains(WordAllows.system(), new MyWordAllow());
|
||||
|
||||
SensitiveWordBs wordBs = SensitiveWordBs.newInstance()
|
||||
.wordDeny(wordDeny)
|
||||
.wordAllow(wordAllow)
|
||||
.init();
|
||||
|
||||
Assert.assertEquals("[我的自定义敏感词]", wordBs.findAll(text).toString());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1 +1,2 @@
|
||||
自定义敏感词
|
||||
敏感词
|
||||
自定义敏感词
|
||||
|
||||
Reference in New Issue
Block a user