Apache Lucene open-source search software
SOLR-3688: fix spellcheck test relying on map order
Yonik Seeleyeb80f5e897bd
diff --git a/solr/core/src/test/org/apache/solr/handler/component/DummyCustomParamSpellChecker.java b/solr/core/src/test/org/apache/solr/handler/component/DummyCustomParamSpellChecker.javaindex a4ef1c59a52..bc78dfcd324 100644--- a/solr/core/src/test/org/apache/solr/handler/component/DummyCustomParamSpellChecker.java+++ b/solr/core/src/test/org/apache/solr/handler/component/DummyCustomParamSpellChecker.java@@ -8,8 +8,10 @@ import org.apache.solr.spelling.SpellingOptions;import org.apache.solr.spelling.SpellingResult;import java.io.IOException;+import java.util.ArrayList;import java.util.Collections;import java.util.Iterator;+import java.util.List;/** Licensed to the Apache Software Foundation (ASF) under one or more* contributor license agreements. See the NOTICE file distributed with@@ -49,12 +51,20 @@ public class DummyCustomParamSpellChecker extends SolrSpellChecker {SpellingResult result = new SpellingResult();//just spit back out the results++ // sort the keys to make ordering predictableIterator<String> iterator = options.customParams.getParameterNamesIterator();+ List<String> lst = new ArrayList<String>();+ while (iterator.hasNext()) {+ lst.add(iterator.next());+ }+ Collections.sort(lst);+int i = 0;- while (iterator.hasNext()){- String name = iterator.next();+ for (String name : lst) {String value = options.customParams.get(name);- result.add(new Token(name, i++, i++), Collections.singletonList(value));+ result.add(new Token(name, i, i+1), Collections.singletonList(value));+ i += 2;}return result;}diff --git a/solr/core/src/test/org/apache/solr/handler/component/SpellCheckComponentTest.java b/solr/core/src/test/org/apache/solr/handler/component/SpellCheckComponentTest.javaindex 77dbf1ab95e..ea252705d85 100644--- a/solr/core/src/test/org/apache/solr/handler/component/SpellCheckComponentTest.java+++ b/solr/core/src/test/org/apache/solr/handler/component/SpellCheckComponentTest.java@@ -100,7 +100,6 @@ public class SpellCheckComponentTest extends SolrTestCaseJ4 {@Testpublic void testPerDictionary() throws Exception {- assumeFalse("This test fails in most cases with Java 8+, looks like it depends on order of some HashSet/HashMap whatever", Constants.JRE_IS_MINIMUM_JAVA8);assertJQ(req("json.nl","map", "qt",rh, SpellCheckComponent.COMPONENT_NAME, "true", SpellingParams.SPELLCHECK_BUILD, "true", "q","documemt", SpellingParams.SPELLCHECK_DICT, "perDict", SpellingParams.SPELLCHECK_PREFIX + ".perDict.foo", "bar", SpellingParams.SPELLCHECK_PREFIX + ".perDict.bar", "foo"),"/spellcheck/suggestions/bar=={'numFound':1, 'startOffset':0, 'endOffset':1, 'suggestion':['foo']}"