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

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@812690 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Uwe Schindler 2009-09-08 20:49:49 +00:00
parent c3063ec882
commit 8f67ba4811
2 changed files with 30 additions and 0 deletions

View File

@ -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");

View File

@ -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);