You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ro...@apache.org on 2019/01/15 10:38:27 UTC

[lucene-solr] 08/09: undeprecate and move TestToken to test-framework tests

This is an automated email from the ASF dual-hosted git repository.

romseygeek pushed a commit to branch master-deprecations
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git

commit 8c9cfd5715d7634a275d85029a243dc3a30447ab
Author: Alan Woodward <ro...@apache.org>
AuthorDate: Mon Jan 14 18:09:34 2019 +0000

    undeprecate and move TestToken to test-framework tests
---
 .../test/org/apache/lucene/analysis/TestToken.java | 49 ++++++++++++++++------
 1 file changed, 37 insertions(+), 12 deletions(-)

diff --git a/lucene/core/src/test/org/apache/lucene/analysis/TestToken.java b/lucene/test-framework/src/test/org/apache/lucene/analysis/TestToken.java
similarity index 78%
rename from lucene/core/src/test/org/apache/lucene/analysis/TestToken.java
rename to lucene/test-framework/src/test/org/apache/lucene/analysis/TestToken.java
index b444aa8..67f4148 100644
--- a/lucene/core/src/test/org/apache/lucene/analysis/TestToken.java
+++ b/lucene/test-framework/src/test/org/apache/lucene/analysis/TestToken.java
@@ -17,18 +17,25 @@
 package org.apache.lucene.analysis;
 
 
-import org.apache.lucene.analysis.tokenattributes.*;
-import org.apache.lucene.util.AttributeReflector;
-import org.apache.lucene.util.LuceneTestCase;
+import java.io.StringReader;
+import java.util.HashMap;
+
+import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
+import org.apache.lucene.analysis.tokenattributes.FlagsAttribute;
+import org.apache.lucene.analysis.tokenattributes.OffsetAttribute;
+import org.apache.lucene.analysis.tokenattributes.PayloadAttribute;
+import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;
+import org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute;
+import org.apache.lucene.analysis.tokenattributes.TermFrequencyAttribute;
+import org.apache.lucene.analysis.tokenattributes.TermToBytesRefAttribute;
+import org.apache.lucene.analysis.tokenattributes.TypeAttribute;
 import org.apache.lucene.util.Attribute;
 import org.apache.lucene.util.AttributeImpl;
+import org.apache.lucene.util.AttributeReflector;
 import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util.TestUtil;
 
-import java.io.StringReader;
-import java.util.HashMap;
-
-@Deprecated
 public class TestToken extends LuceneTestCase {
 
   public void testCtor() throws Exception {
@@ -51,20 +58,20 @@ public class TestToken extends LuceneTestCase {
     char[] content = "hello".toCharArray();
     t.copyBuffer(content, 0, 5);
     char[] buf = t.buffer();
-    Token copy = TestCharTermAttributeImpl.assertCloneIsEqual(t);
+    Token copy = assertCloneIsEqual(t);
     assertEquals(t.toString(), copy.toString());
     assertNotSame(buf, copy.buffer());
 
     BytesRef pl = new BytesRef(new byte[]{1,2,3,4});
     t.setPayload(pl);
-    copy = TestCharTermAttributeImpl.assertCloneIsEqual(t);
+    copy = assertCloneIsEqual(t);
     assertEquals(pl, copy.getPayload());
     assertNotSame(pl, copy.getPayload());
   }
   
   public void testCopyTo() throws Exception {
     Token t = new Token();
-    Token copy = TestCharTermAttributeImpl.assertCopyIsEqual(t);
+    Token copy = assertCopyIsEqual(t);
     assertEquals("", t.toString());
     assertEquals("", copy.toString());
 
@@ -73,13 +80,13 @@ public class TestToken extends LuceneTestCase {
     char[] content = "hello".toCharArray();
     t.copyBuffer(content, 0, 5);
     char[] buf = t.buffer();
-    copy = TestCharTermAttributeImpl.assertCopyIsEqual(t);
+    copy = assertCopyIsEqual(t);
     assertEquals(t.toString(), copy.toString());
     assertNotSame(buf, copy.buffer());
 
     BytesRef pl = new BytesRef(new byte[]{1,2,3,4});
     t.setPayload(pl);
-    copy = TestCharTermAttributeImpl.assertCopyIsEqual(t);
+    copy = assertCopyIsEqual(t);
     assertEquals(pl, copy.getPayload());
     assertNotSame(pl, copy.getPayload());
   }
@@ -140,4 +147,22 @@ public class TestToken extends LuceneTestCase {
           put(TermFrequencyAttribute.class.getName() + "#termFrequency", 42);
         }});
   }
+
+
+  public static <T extends AttributeImpl> T assertCloneIsEqual(T att) {
+    @SuppressWarnings("unchecked")
+    T clone = (T) att.clone();
+    assertEquals("Clone must be equal", att, clone);
+    assertEquals("Clone's hashcode must be equal", att.hashCode(), clone.hashCode());
+    return clone;
+  }
+
+  public static <T extends AttributeImpl> T assertCopyIsEqual(T att) throws Exception {
+    @SuppressWarnings("unchecked")
+    T copy = (T) att.getClass().newInstance();
+    att.copyTo(copy);
+    assertEquals("Copied instance must be equal", att, copy);
+    assertEquals("Copied instance's hashcode must be equal", att.hashCode(), copy.hashCode());
+    return copy;
+  }
 }