Skip to content

Apache Lucene open-source search software

LUCENE-1926: a more improved version of the test to also fill the attributes with bogus values. This should e.g. detect bugs with position increment not correctly set in all cases

Uwe Schindlerc390d4929028
diff --git a/src/test/org/apache/lucene/analysis/BaseTokenStreamTestCase.java b/src/test/org/apache/lucene/analysis/BaseTokenStreamTestCase.java
index 1a1f829b414..f505372b26e 100644
--- a/src/test/org/apache/lucene/analysis/BaseTokenStreamTestCase.java
+++ b/src/test/org/apache/lucene/analysis/BaseTokenStreamTestCase.java
@@ -111,7 +111,13 @@ public abstract class BaseTokenStreamTestCase extends LuceneTestCase {
ts.reset();
for (int i = 0; i < output.length; i++) {
- ts.clearAttributes(); // extra safety to enforce, that the state is not preserved
+ // extra safety to enforce, that the state is not preserved and also assign bogus values
+ ts.clearAttributes();
+ termAtt.setTermBuffer("bogusTerm");
+ if (offsetAtt != null) offsetAtt.setOffset(14584724,24683243);
+ if (typeAtt != null) typeAtt.setType("bogusType");
+ if (posIncrAtt != null) posIncrAtt.setPositionIncrement(45987657);
+
assertTrue("token "+i+" exists", ts.incrementToken());
assertEquals("term "+i, output[i], termAtt.term());
if (startOffsets != null)