Fixed empty banned words list muting all chat.

This commit is contained in:
ryanhamshire 2015-10-03 20:25:56 -07:00
parent bdbc35dc59
commit 26cef61d7f
2 changed files with 12 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package me.ryanhamshire.GriefPrevention;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.Arrays;
import org.junit.Test;
@ -57,4 +58,11 @@ public class Tests
WordFinder finder = new WordFinder(Arrays.asList("alpha"));
assertFalse(finder.hasMatch("Unit testing is smart."));
}
@Test
public void WordFinder_EmptyList()
{
WordFinder finder = new WordFinder(new ArrayList<String>());
assertFalse(finder.hasMatch("alpha"));
}
}

View File

@ -10,6 +10,8 @@ class WordFinder
WordFinder(List<String> wordsToFind)
{
if(wordsToFind.size() == 0) return;
StringBuilder patternBuilder = new StringBuilder();
for(String word : wordsToFind)
{
@ -28,6 +30,8 @@ class WordFinder
boolean hasMatch(String input)
{
if(this.pattern == null) return false;
Matcher matcher = this.pattern.matcher(input);
return matcher.find();
}