Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-1901: Add a test (also to Token.java)

Uwe Schindler8f67ba481108
diff --git a/src/test/org/apache/lucene/analysis/TestToken.java b/src/test/org/apache/lucene/analysis/TestToken.java
index bc000c416f9..b494cfe3dc0 100644
--- a/src/test/org/apache/lucene/analysis/TestToken.java
+++ b/src/test/org/apache/lucene/analysis/TestToken.java
@@ -150,6 +150,21 @@ public class TestToken extends LuceneTestCase {
assertEquals("(hi there,0,5)", t.toString());
}
+ public void testTermBufferEquals() throws Exception {
+ Token t1a = new Token();
+ char[] content1a = "hello".toCharArray();
+ t1a.setTermBuffer(content1a, 0, 5);
+ Token t1b = new Token();
+ char[] content1b = "hello".toCharArray();
+ t1b.setTermBuffer(content1b, 0, 5);
+ Token t2 = new Token();
+ char[] content2 = "hello2".toCharArray();
+ t2.setTermBuffer(content2, 0, 6);
+ assertTrue(t1a.equals(t1b));
+ assertFalse(t1a.equals(t2));
+ assertFalse(t2.equals(t1b));
+ }
+
public void testMixedStringArray() throws Exception {
Token t = new Token("hello", 0, 5);
assertEquals(t.termText(), "hello");
diff --git a/src/test/org/apache/lucene/analysis/tokenattributes/TestTermAttributeImpl.java b/src/test/org/apache/lucene/analysis/tokenattributes/TestTermAttributeImpl.java
index eb333dc0fbb..f7b0a77fff2 100644
--- a/src/test/org/apache/lucene/analysis/tokenattributes/TestTermAttributeImpl.java
+++ b/src/test/org/apache/lucene/analysis/tokenattributes/TestTermAttributeImpl.java
@@ -146,6 +146,21 @@ public class TestTermAttributeImpl extends LuceneTestCase {
assertNotSame(buf, copy.termBuffer());
}
+ public void testEquals() throws Exception {
+ TermAttributeImpl t1a = new TermAttributeImpl();
+ char[] content1a = "hello".toCharArray();
+ t1a.setTermBuffer(content1a, 0, 5);
+ TermAttributeImpl t1b = new TermAttributeImpl();
+ char[] content1b = "hello".toCharArray();
+ t1b.setTermBuffer(content1b, 0, 5);
+ TermAttributeImpl t2 = new TermAttributeImpl();
+ char[] content2 = "hello2".toCharArray();
+ t2.setTermBuffer(content2, 0, 6);
+ assertTrue(t1a.equals(t1b));
+ assertFalse(t1a.equals(t2));
+ assertFalse(t2.equals(t1b));
+ }
+
public void testCopyTo() throws Exception {
TermAttributeImpl t = new TermAttributeImpl();
TermAttributeImpl copy = (TermAttributeImpl) TestSimpleAttributeImpls.assertCopyIsEqual(t);