From 5c6a299eff9950d7a2640c8efd2496795ad7156d Mon Sep 17 00:00:00 2001 From: Tomas Fernandez Lobbe Date: Fri, 1 Nov 2019 15:53:38 -0700 Subject: [PATCH] SOLR-13207: Fix tests --- .../org/apache/solr/util/SolrPluginUtils.java | 10 +++++----- .../apache/solr/util/SolrPluginUtilsTest.java | 20 ++++++++++++++----- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java b/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java index 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.java index 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 { @Test public void testMinShouldMatchBadQueries() { - expectThrows(SolrException.class, () -> calcMSM(1, "1<")); - expectThrows(SolrException.class, () -> calcMSM(1, "1 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 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 calcMSM(10, "2<-25% 9<")); + assertEquals("Invalid 'mm' spec: '9<'. Expecting values before and after '<'" , e.getMessage()); } @Test