Apache Solr open-source search software
LUCENE-4779: add replacement for TestSort
Robert Muir0160c32a7337
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestSort2.java b/lucene/core/src/test/org/apache/lucene/search/TestSort2.javanew file mode 100644index 00000000000..1ecc6bbe487--- /dev/null+++ b/lucene/core/src/test/org/apache/lucene/search/TestSort2.java@@ -0,0 +1,72 @@+package org.apache.lucene.search;++/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import java.io.IOException;++import org.apache.lucene.document.Document;+import org.apache.lucene.document.Field;+import org.apache.lucene.index.IndexReader;+import org.apache.lucene.index.RandomIndexWriter;+import org.apache.lucene.store.Directory;+import org.apache.lucene.util.LuceneTestCase;++/*+ * Very simple tests of sorting.+ *+ * THE RULES:+ * 1. keywords like 'abstract' and 'static' should not appear in this file.+ * 2. each test method should be self-contained and understandable.+ * 3. no test methods should not share code with other test methods.+ * 4. no testing of things unrelated to sorting.+ * 5. no tracers.+ * 6. keyword 'class' should appear only once in this file, here ----+ * |+ * -----------------------------------------------------------+ * |+ * \./+ */+public class TestSort2 extends LuceneTestCase {++ public void testDemo() throws IOException {+ Directory dir = newDirectory();+ RandomIndexWriter writer = new RandomIndexWriter(random(), dir);+ Document doc = new Document();+ doc.add(newStringField("id", "1", Field.Store.YES));+ doc.add(newStringField("value", "foo", Field.Store.NO));+ writer.addDocument(doc);+ doc = new Document();+ doc.add(newStringField("id", "2", Field.Store.YES));+ doc.add(newStringField("value", "bar", Field.Store.NO));+ writer.addDocument(doc);+ IndexReader ir = writer.getReader();+ writer.close();++ IndexSearcher searcher = new IndexSearcher(ir);+ Sort sort = new Sort(new SortField("value", SortField.Type.STRING));++ TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort);+ assertEquals(2, td.totalHits);+ // 'bar' comes before 'foo'+ assertEquals("2", searcher.doc(td.scoreDocs[0].doc).get("id"));+ assertEquals("1", searcher.doc(td.scoreDocs[1].doc).get("id"));++ ir.close();+ dir.close();+ }+}