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
|
||||
public Object call(Properties bindings, Object[] args) {
|
||||
if (args.length> 0) {
|
||||
if (args.length> 1) {
|
||||
for (int i = 0; i < args.length; i++){
|
||||
if (args[i] == null) {
|
||||
continue;
|
||||
@ -56,7 +56,7 @@ public class Coalesce implements Function {
|
||||
}
|
||||
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
|
||||
@ -65,8 +65,8 @@ public class Coalesce implements Function {
|
||||
|
||||
writer.object();
|
||||
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("returns"); writer.value("object");
|
||||
writer.key("params"); writer.value("two or more objects");
|
||||
writer.key("returns"); writer.value("object or null");
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
|
@ -88,13 +88,12 @@ public class CoalesceTests extends RefineTest {
|
||||
@Test
|
||||
public void testCoalesceInvalidParams() {
|
||||
Assert.assertTrue(invoke("coalesce") instanceof EvalError);
|
||||
Assert.assertTrue(invoke("coalesce", 1) instanceof EvalError);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCoalesce() {
|
||||
Assert.assertNull(invoke("coalesce", (Object) null));
|
||||
Assert.assertEquals(invoke("coalesce", "string"),"string");
|
||||
Assert.assertEquals(invoke("coalesce", 1),1);
|
||||
public void testCoalesce() {
|
||||
Assert.assertNull(invoke("coalesce", (Object) null, (Object) null));
|
||||
Assert.assertEquals(invoke("coalesce", (Object) null, "string"),"string");
|
||||
Assert.assertEquals(invoke("coalesce", (Object) null, (Object) null, "string"),"string");
|
||||
Assert.assertEquals(invoke("coalesce", (Object) null, 1),1);
|
||||
|
Loading…
Reference in New Issue
Block a user