add for test

This commit is contained in:
binbin.hou
2021-07-07 10:46:51 +08:00
parent b75e47ab34
commit 56decce3d9
5 changed files with 168 additions and 26 deletions

View File

@@ -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("测试");
}
}

View File

@@ -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("我的自定义敏感词");
}
}

View File

@@ -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());
}
}

View File

@@ -1 +1,2 @@
自定义敏感词
敏感词
自定义敏感词