ListContainsFunction extends BaseFEELFunction { public FEELFnResult<Boolean> invoke(@ParameterName("list") List list, @ParameterName("element") Object element) { if ( list == null ) { return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "list", "cannot be null")); } else { if (element == null) { return FEELFnResult.ofResult(list.contains(element)); } else { Object e = EvalHelper.coerceNumber(element); boolean found = false; ListIterator<?> it = list.listIterator(); while (it.hasNext() && !found) { Object next = EvalHelper.coerceNumber(it.next()); found = e.equals(next); } return FEELFnResult.ofResult(found); } } } ListContainsFunction(); FEELFnResult<Boolean> invoke(@ParameterName("list") List list, @ParameterName("element") Object element);  }
@Test public void invokeListNull() { FunctionTestUtil.assertResultError(listContainsFunction.invoke((List) null, null), InvalidParametersEvent.class); FunctionTestUtil.assertResultError(listContainsFunction.invoke(null, new Object()), InvalidParametersEvent.class); }
@Test public void invokeContainsNull() { FunctionTestUtil.assertResult(listContainsFunction.invoke(Collections.singletonList(null), null), true); FunctionTestUtil.assertResult(listContainsFunction.invoke(Arrays.asList(1, null), null), true); FunctionTestUtil.assertResult(listContainsFunction.invoke(Arrays.asList(null, 1), null), true); }
@Test public void invokeNotContainsNull() { FunctionTestUtil.assertResult(listContainsFunction.invoke(Collections.emptyList(), null), false); FunctionTestUtil.assertResult(listContainsFunction.invoke(Collections.singletonList(1), null), false); FunctionTestUtil.assertResult(listContainsFunction.invoke(Arrays.asList(1, 2), null), false); }
@Test public void invokeContains() { FunctionTestUtil.assertResult(listContainsFunction.invoke(Arrays.asList(1, 2, "test"), "test"), true); FunctionTestUtil.assertResult(listContainsFunction.invoke(Arrays.asList(1, 2, "test"), 1), true); FunctionTestUtil.assertResult(listContainsFunction.invoke(Arrays.asList(1, 2, "test"), BigDecimal.ONE), true); }
@Test public void invokeNotContains() { FunctionTestUtil.assertResult(listContainsFunction.invoke(Arrays.asList(1, 2, "test"), "testtt"), false); FunctionTestUtil.assertResult(listContainsFunction.invoke(Arrays.asList(1, 2, "test"), 3), false); FunctionTestUtil.assertResult(listContainsFunction.invoke(Arrays.asList(1, 2, "test"), BigDecimal.valueOf(3)), false); }