Coalesce must have at least two arguments
This commit is contained in:
parent
998eefc869
commit
6e02baaa8a
@ -46,7 +46,7 @@ public class Coalesce implements Function {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object call(Properties bindings, Object[] args) {
|
public Object call(Properties bindings, Object[] args) {
|
||||||
if (args.length> 0) {
|
if (args.length> 1) {
|
||||||
for (int i = 0; i < args.length; i++){
|
for (int i = 0; i < args.length; i++){
|
||||||
if (args[i] == null) {
|
if (args[i] == null) {
|
||||||
continue;
|
continue;
|
||||||
@ -56,7 +56,7 @@ public class Coalesce implements Function {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects at least one argument");
|
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects at least two arguments");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -65,8 +65,8 @@ public class Coalesce implements Function {
|
|||||||
|
|
||||||
writer.object();
|
writer.object();
|
||||||
writer.key("description"); writer.value("Returns the first non-null from a series of values");
|
writer.key("description"); writer.value("Returns the first non-null from a series of values");
|
||||||
writer.key("params"); writer.value("one or more objects");
|
writer.key("params"); writer.value("two or more objects");
|
||||||
writer.key("returns"); writer.value("object");
|
writer.key("returns"); writer.value("object or null");
|
||||||
writer.endObject();
|
writer.endObject();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,13 +88,12 @@ public class CoalesceTests extends RefineTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testCoalesceInvalidParams() {
|
public void testCoalesceInvalidParams() {
|
||||||
Assert.assertTrue(invoke("coalesce") instanceof EvalError);
|
Assert.assertTrue(invoke("coalesce") instanceof EvalError);
|
||||||
|
Assert.assertTrue(invoke("coalesce", 1) instanceof EvalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCoalesce() {
|
public void testCoalesce() {
|
||||||
Assert.assertNull(invoke("coalesce", (Object) null));
|
Assert.assertNull(invoke("coalesce", (Object) null, (Object) null));
|
||||||
Assert.assertEquals(invoke("coalesce", "string"),"string");
|
|
||||||
Assert.assertEquals(invoke("coalesce", 1),1);
|
|
||||||
Assert.assertEquals(invoke("coalesce", (Object) null, "string"),"string");
|
Assert.assertEquals(invoke("coalesce", (Object) null, "string"),"string");
|
||||||
Assert.assertEquals(invoke("coalesce", (Object) null, (Object) null, "string"),"string");
|
Assert.assertEquals(invoke("coalesce", (Object) null, (Object) null, "string"),"string");
|
||||||
Assert.assertEquals(invoke("coalesce", (Object) null, 1),1);
|
Assert.assertEquals(invoke("coalesce", (Object) null, 1),1);
|
||||||
|
Loading…
Reference in New Issue
Block a user