Apache Solr open-source search software
SOLR-13812: Add javadocs, uneven rejection and basic test coverage for the SolrTestCaseJ4.params method. (Diego Ceccarelli, Christine Poerschke, Munendra S N)
Christine Poerschkeb51013a10b5a
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 9a986e82402..1b207e8384f 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -298,6 +298,9 @@ Other Changes* SOLR-13791: Remove remaining Commons BeanUtils references. (Andras Salamon, Christine Poerschke)+* SOLR-13812: Add javadocs, uneven rejection and basic test coverage for the SolrTestCaseJ4.params method.+ (Diego Ceccarelli, Christine Poerschke, Munendra S N)+================== 8.2.0 ==================Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.diff --git a/solr/core/src/test/org/apache/solr/SolrTestCaseJ4Test.java b/solr/core/src/test/org/apache/solr/SolrTestCaseJ4Test.javaindex 795c3e8ff31..fc995e3d4ff 100644--- a/solr/core/src/test/org/apache/solr/SolrTestCaseJ4Test.java+++ b/solr/core/src/test/org/apache/solr/SolrTestCaseJ4Test.java@@ -19,6 +19,7 @@ package org.apache.solr;import java.io.File;import org.apache.commons.io.FileUtils;+import org.apache.solr.common.params.ModifiableSolrParams;import org.junit.AfterClass;import org.junit.BeforeClass;import org.junit.Test;@@ -61,4 +62,25 @@ public class SolrTestCaseJ4Test extends SolrTestCaseJ4 {public void testCorrectCore() throws Exception {assertEquals("should be core1", "core1", h.getCore().getName());}++ @Test+ public void testParams() throws Exception {+ final ModifiableSolrParams params = new ModifiableSolrParams();+ assertEquals(params.toString(), params().toString());++ params.add("q", "*:*");+ assertEquals(params.toString(), params("q", "*:*").toString());++ params.add("rows", "42");+ assertEquals(params.toString(), params("q", "*:*", "rows", "42").toString());++ expectThrows(RuntimeException.class, () -> {+ params("parameterWithoutValue");+ });++ expectThrows(RuntimeException.class, () -> {+ params("q", "*:*", "rows", "42", "parameterWithoutValue");+ });+ }+}diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.javaindex 90203664fc1..8b5a8f97164 100644--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java@@ -1270,7 +1270,16 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {return d;}+ /**+ * Generates the correct SolrParams from an even list of strings.+ * A string in an even position will represent the name of a parameter, while the following string+ * at position (i+1) will be the assigned value.+ *+ * @param params an even list of strings+ * @return the ModifiableSolrParams generated from the given list of strings.+ */public static ModifiableSolrParams params(String... params) {+ if (params.length % 2 != 0) throw new RuntimeException("Params length should be even");ModifiableSolrParams msp = new ModifiableSolrParams();for (int i=0; i<params.length; i+=2) {msp.add(params[i], params[i+1]);