| 1 |
|
package org.apache.lucene.analysis; |
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
import junit.framework.TestCase; |
| 20 |
|
|
| 21 |
|
import java.io.StringReader; |
| 22 |
|
import java.io.IOException; |
| 23 |
|
import java.util.Set; |
| 24 |
|
import java.util.HashSet; |
| 25 |
|
|
|
|
|
| 87.5% |
Uncovered Elements: 4 (32) |
Complexity: 7 |
Complexity Density: 0.32 |
|
| 26 |
|
public class TestStopAnalyzer extends TestCase { |
| 27 |
|
|
| 28 |
|
private StopAnalyzer stop = new StopAnalyzer(); |
| 29 |
|
private Set inValidTokens = new HashSet(); |
| 30 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 31 |
2
|
public TestStopAnalyzer(String s) {... |
| 32 |
2
|
super(s); |
| 33 |
|
} |
| 34 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
| 35 |
2
|
protected void setUp() {... |
| 36 |
68
|
for (int i = 0; i < StopAnalyzer.ENGLISH_STOP_WORDS.length; i++) { |
| 37 |
66
|
inValidTokens.add(StopAnalyzer.ENGLISH_STOP_WORDS[i]); |
| 38 |
|
} |
| 39 |
|
} |
| 40 |
|
|
|
|
|
| 77.8% |
Uncovered Elements: 2 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
1
PASS
|
|
| 41 |
1
|
public void testDefaults() throws IOException {... |
| 42 |
1
|
assertTrue(stop != null); |
| 43 |
1
|
StringReader reader = new StringReader("This is a test of the english stop analyzer"); |
| 44 |
1
|
TokenStream stream = stop.tokenStream("test", reader); |
| 45 |
1
|
assertTrue(stream != null); |
| 46 |
1
|
Token token = null; |
| 47 |
?
|
while ((token = stream.next()) != null) { |
| 48 |
4
|
assertFalse(inValidTokens.contains(token.termText())); |
| 49 |
|
} |
| 50 |
|
} |
| 51 |
|
|
|
|
|
| 85.7% |
Uncovered Elements: 2 (14) |
Complexity: 2 |
Complexity Density: 0.17 |
1
PASS
|
|
| 52 |
1
|
public void testStopList() throws IOException {... |
| 53 |
1
|
Set stopWordsSet = new HashSet(); |
| 54 |
1
|
stopWordsSet.add("good"); |
| 55 |
1
|
stopWordsSet.add("test"); |
| 56 |
1
|
stopWordsSet.add("analyzer"); |
| 57 |
1
|
StopAnalyzer newStop = new StopAnalyzer((String[])stopWordsSet.toArray(new String[3])); |
| 58 |
1
|
StringReader reader = new StringReader("This is a good test of the english stop analyzer"); |
| 59 |
1
|
TokenStream stream = newStop.tokenStream("test", reader); |
| 60 |
1
|
assertNotNull(stream); |
| 61 |
1
|
Token token = null; |
| 62 |
?
|
while ((token = stream.next()) != null) { |
| 63 |
7
|
String text = token.termText(); |
| 64 |
7
|
assertFalse(stopWordsSet.contains(text)); |
| 65 |
|
} |
| 66 |
|
} |
| 67 |
|
|
| 68 |
|
} |