mirror of https://github.com/apache/lucene.git
SOLR-13207: Fix tests
This commit is contained in:
parent
d49b36ec9c
commit
332f1d7741
|
@ -678,11 +678,11 @@ public class SolrPluginUtils {
|
||||||
spec = spaceAroundLessThanPattern.matcher(spec).replaceAll("<");
|
spec = spaceAroundLessThanPattern.matcher(spec).replaceAll("<");
|
||||||
for (String s : spacePattern.split(spec)) {
|
for (String s : spacePattern.split(spec)) {
|
||||||
String[] parts = lessThanPattern.split(s,0);
|
String[] parts = lessThanPattern.split(s,0);
|
||||||
if (parts.length == 0) {
|
if (parts.length < 2) {
|
||||||
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
|
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) {
|
if (optionalClauseCount <= upperBound) {
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
|
@ -699,11 +699,11 @@ public class SolrPluginUtils {
|
||||||
/* percentage - assume the % was the last char. If not, let Integer.parseInt fail. */
|
/* percentage - assume the % was the last char. If not, let Integer.parseInt fail. */
|
||||||
spec = spec.substring(0,spec.length()-1);
|
spec = spec.substring(0,spec.length()-1);
|
||||||
int percent = checkedParseInt(spec,
|
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);
|
float calc = (result * percent) * (1/100f);
|
||||||
result = calc < 0 ? result + (int)calc : (int)calc;
|
result = calc < 0 ? result + (int)calc : (int)calc;
|
||||||
} else {
|
} 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;
|
result = calc < 0 ? result + calc : calc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -341,11 +341,21 @@ public class SolrPluginUtilsTest extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMinShouldMatchBadQueries() {
|
public void testMinShouldMatchBadQueries() {
|
||||||
expectThrows(SolrException.class, () -> calcMSM(1, "1<"));
|
Exception e = expectThrows(SolrException.class, () -> calcMSM(2, "1<"));
|
||||||
expectThrows(SolrException.class, () -> calcMSM(1, "1<x"));
|
assertEquals("Invalid 'mm' spec: '1<'. Expecting values before and after '<'" , e.getMessage());
|
||||||
expectThrows(SolrException.class, () -> calcMSM(1, "x%"));
|
e = expectThrows(SolrException.class, () -> calcMSM(2, "1<x"));
|
||||||
expectThrows(SolrException.class, () -> calcMSM(1, "%%"));
|
assertEquals("Invalid 'mm' spec. Expecting an integer.", e.getMessage());
|
||||||
expectThrows(SolrException.class, () -> calcMSM(1, "x"));
|
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
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue