Apache Lucene open-source search software
SOLR-13207: Fix tests
Tomas Fernandez Lobbe5c6a299eff99
diff --git a/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java b/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.javaindex c4ad454cf1f..9bc8d257a4a 100644--- a/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java+++ b/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java@@ -678,11 +678,11 @@ public class SolrPluginUtils {spec = spaceAroundLessThanPattern.matcher(spec).replaceAll("<");for (String s : spacePattern.split(spec)) {String[] parts = lessThanPattern.split(s,0);- if (parts.length == 0) {+ if (parts.length < 2) {throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,- "Operator < must be followed by a number");+ "Invalid 'mm' spec: '" + s + "'. Expecting values before and after '<'");}- int upperBound = checkedParseInt(parts[0], "Operator < must be followed by a number");+ int upperBound = checkedParseInt(parts[0], "Invalid 'mm' spec. Expecting an integer.");if (optionalClauseCount <= upperBound) {return result;} else {@@ -699,11 +699,11 @@ public class SolrPluginUtils {/* percentage - assume the % was the last char. If not, let Integer.parseInt fail. */spec = spec.substring(0,spec.length()-1);int percent = checkedParseInt(spec,- "% must be preceded by a number and not combined with other operators");+ "Invalid 'mm' spec. Expecting an integer.");float calc = (result * percent) * (1/100f);result = calc < 0 ? result + (int)calc : (int)calc;} else {- int calc = checkedParseInt(spec, "Input should be a number");+ int calc = checkedParseInt(spec, "Invalid 'mm' spec. Expecting an integer.");result = calc < 0 ? result + calc : calc;}diff --git a/solr/core/src/test/org/apache/solr/util/SolrPluginUtilsTest.java b/solr/core/src/test/org/apache/solr/util/SolrPluginUtilsTest.javaindex 58d56a171b7..f5034c4e6b6 100644--- a/solr/core/src/test/org/apache/solr/util/SolrPluginUtilsTest.java+++ b/solr/core/src/test/org/apache/solr/util/SolrPluginUtilsTest.java@@ -341,11 +341,21 @@ public class SolrPluginUtilsTest extends SolrTestCaseJ4 {@Testpublic void testMinShouldMatchBadQueries() {- expectThrows(SolrException.class, () -> calcMSM(1, "1<"));- expectThrows(SolrException.class, () -> calcMSM(1, "1<x"));- expectThrows(SolrException.class, () -> calcMSM(1, "x%"));- expectThrows(SolrException.class, () -> calcMSM(1, "%%"));- expectThrows(SolrException.class, () -> calcMSM(1, "x"));+ Exception e = expectThrows(SolrException.class, () -> calcMSM(2, "1<"));+ assertEquals("Invalid 'mm' spec: '1<'. Expecting values before and after '<'" , e.getMessage());+ e = expectThrows(SolrException.class, () -> calcMSM(2, "1<x"));+ assertEquals("Invalid 'mm' spec. Expecting an integer.", e.getMessage());+ e = expectThrows(SolrException.class, () -> calcMSM(1, "x%"));+ assertEquals("Invalid 'mm' spec. Expecting an integer.", e.getMessage());+ e = expectThrows(SolrException.class, () -> calcMSM(1, "%%"));+ assertEquals("Invalid 'mm' spec. Expecting an integer.", e.getMessage());+ e = expectThrows(SolrException.class, () -> calcMSM(1, "x"));+ assertEquals("Invalid 'mm' spec. Expecting an integer.", e.getMessage());++ e = expectThrows(SolrException.class, () -> calcMSM(10, "2<-25% 9<X"));+ assertEquals("Invalid 'mm' spec. Expecting an integer." , e.getMessage());+ e = expectThrows(SolrException.class, () -> calcMSM(10, "2<-25% 9<"));+ assertEquals("Invalid 'mm' spec: '9<'. Expecting values before and after '<'" , e.getMessage());}@Test