Apache Lucene open-source search software
LUCENE-3042: Add a more specific test that can be backported to 3.x and prev
Uwe Schindler2714ba90caf0
diff --git a/lucene/src/test/org/apache/lucene/util/TestAttributeSource.java b/lucene/src/test/org/apache/lucene/util/TestAttributeSource.javaindex bf1c0d1934d..3d464a03572 100644--- a/lucene/src/test/org/apache/lucene/util/TestAttributeSource.java+++ b/lucene/src/test/org/apache/lucene/util/TestAttributeSource.java@@ -147,4 +147,14 @@ public class TestAttributeSource extends LuceneTestCase {fail("Should throw IllegalArgumentException");} catch (IllegalArgumentException iae) {}}++ public void testLUCENE_3042() throws Exception {+ final AttributeSource src1 = new AttributeSource();+ src1.addAttribute(CharTermAttribute.class).append("foo");+ int hash1 = src1.hashCode(); // this triggers a cached state+ final AttributeSource src2 = new AttributeSource(src1);+ src2.addAttribute(TypeAttribute.class).setType("bar");+ assertTrue("The hashCode is identical, so the captured state was preserved.", hash1 != src1.hashCode());+ assertEquals(src2.hashCode(), src1.hashCode());+ }}