mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-19 15:54:52 +01:00
implemented necassary test case
Former-commit-id: d1115558dc86f88372ee815300c688f719934f18
This commit is contained in:
@@ -47,6 +47,24 @@ public final class TokenPairConcatenatingFilter extends TokenFilter {
|
|||||||
*/
|
*/
|
||||||
private final LinkedList<String> words;
|
private final LinkedList<String> words;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the previous word. This is needed in the test cases.
|
||||||
|
*
|
||||||
|
* @return te previous word
|
||||||
|
*/
|
||||||
|
protected String getPreviousWord() {
|
||||||
|
return previousWord;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the words list. This is needed in the test cases.
|
||||||
|
*
|
||||||
|
* @return the words list
|
||||||
|
*/
|
||||||
|
protected LinkedList<String> getWords() {
|
||||||
|
return words;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new TokenPairConcatenatingFilter.
|
* Constructs a new TokenPairConcatenatingFilter.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -6,12 +6,18 @@ package org.owasp.dependencycheck.data.lucene;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
|
import java.io.StringReader;
|
||||||
import org.apache.lucene.analysis.Analyzer;
|
import org.apache.lucene.analysis.Analyzer;
|
||||||
import org.apache.lucene.analysis.BaseTokenStreamTestCase;
|
import org.apache.lucene.analysis.BaseTokenStreamTestCase;
|
||||||
import static org.apache.lucene.analysis.BaseTokenStreamTestCase.assertAnalyzesTo;
|
import static org.apache.lucene.analysis.BaseTokenStreamTestCase.assertAnalyzesTo;
|
||||||
|
import static org.apache.lucene.analysis.BaseTokenStreamTestCase.assertTokenStreamContents;
|
||||||
import static org.apache.lucene.analysis.BaseTokenStreamTestCase.checkOneTerm;
|
import static org.apache.lucene.analysis.BaseTokenStreamTestCase.checkOneTerm;
|
||||||
import org.apache.lucene.analysis.MockTokenizer;
|
import org.apache.lucene.analysis.MockTokenizer;
|
||||||
|
import org.apache.lucene.analysis.TokenStream;
|
||||||
import org.apache.lucene.analysis.Tokenizer;
|
import org.apache.lucene.analysis.Tokenizer;
|
||||||
|
import org.apache.lucene.analysis.core.WhitespaceTokenizer;
|
||||||
|
import org.apache.lucene.analysis.tokenattributes.TypeAttributeImpl;
|
||||||
|
import org.apache.lucene.util.Version;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -25,19 +31,6 @@ import static org.junit.Assert.*;
|
|||||||
*/
|
*/
|
||||||
public class TokenPairConcatenatingFilterTest extends BaseTokenStreamTestCase {
|
public class TokenPairConcatenatingFilterTest extends BaseTokenStreamTestCase {
|
||||||
|
|
||||||
private Analyzer analyzer;
|
|
||||||
|
|
||||||
public TokenPairConcatenatingFilterTest() {
|
|
||||||
analyzer = new Analyzer() {
|
|
||||||
@Override
|
|
||||||
protected Analyzer.TokenStreamComponents createComponents(String fieldName,
|
|
||||||
Reader reader) {
|
|
||||||
Tokenizer source = new MockTokenizer(reader, MockTokenizer.WHITESPACE, false);
|
|
||||||
return new Analyzer.TokenStreamComponents(source, new TokenPairConcatenatingFilter(source));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUpClass() {
|
public static void setUpClass() {
|
||||||
}
|
}
|
||||||
@@ -60,21 +53,25 @@ public class TokenPairConcatenatingFilterTest extends BaseTokenStreamTestCase {
|
|||||||
* test some examples
|
* test some examples
|
||||||
*/
|
*/
|
||||||
public void testExamples() throws IOException {
|
public void testExamples() throws IOException {
|
||||||
//TODO figure outwhy I am getting "Failed: incrementtoken() called while in wrong state"
|
Tokenizer wsTokenizer = new WhitespaceTokenizer(Version.LUCENE_43, new StringReader("one two three"));
|
||||||
// String[] expected = new String[3];
|
TokenStream filter = new TokenPairConcatenatingFilter(wsTokenizer);
|
||||||
// expected[0] = "one";
|
assertTokenStreamContents(filter,
|
||||||
// expected[1] = "onetwo";
|
new String[]{"one", "onetwo", "two", "twothree", "three"});
|
||||||
// expected[2] = "two";
|
|
||||||
// checkOneTerm(analyzer, "one", "one");
|
|
||||||
// assertAnalyzesTo(analyzer, "two", new String[]{"onetwo", "two"});
|
|
||||||
//checkOneTerm(analyzer, "two", "onetwo");
|
|
||||||
//checkOneTerm(analyzer, "three", "two");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of clear method, of class TokenPairConcatenatingFilter.
|
* Test of clear method, of class TokenPairConcatenatingFilter.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testClear() {
|
public void testClear() throws IOException {
|
||||||
|
|
||||||
|
TokenStream ts = new WhitespaceTokenizer(Version.LUCENE_43, new StringReader("one two three"));
|
||||||
|
TokenPairConcatenatingFilter filter = new TokenPairConcatenatingFilter(ts);
|
||||||
|
assertTokenStreamContents(filter, new String[]{"one", "onetwo", "two", "twothree", "three"});
|
||||||
|
|
||||||
|
assertNotNull(filter.getPreviousWord());
|
||||||
|
filter.clear();
|
||||||
|
assertNull(filter.getPreviousWord());
|
||||||
|
assertTrue(filter.getWords().isEmpty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user