You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by tf...@apache.org on 2019/11/01 22:53:48 UTC

[lucene-solr] branch master updated: SOLR-13207: Fix tests

This is an automated email from the ASF dual-hosted git repository.

tflobbe pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/master by this push:
     new 5c6a299  SOLR-13207: Fix tests
5c6a299 is described below

commit 5c6a299eff9950d7a2640c8efd2496795ad7156d
Author: Tomas Fernandez Lobbe <tf...@apache.org>
AuthorDate: Fri Nov 1 15:53:38 2019 -0700

    SOLR-13207: Fix tests
---
 .../java/org/apache/solr/util/SolrPluginUtils.java   | 10 +++++-----
 .../org/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 c4ad454..9bc8d25 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 58d56a1..f5034c4 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<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