SortFunction extends BaseFEELFunction { public FEELFnResult<List<Object>> invoke(@ParameterName( "ctx" ) EvaluationContext ctx, @ParameterName("list") List list, @ParameterName("precedes") FEELFunction function) { if ( function == null ) { return invoke( list ); } else { return invoke(list, (a, b) -> { final Object result = function.invokeReflectively(ctx, new Object[]{a, b}); if (!(result instanceof Boolean) || ((Boolean) result)) { return -1; } else { return 1; } } ); } } SortFunction(); FEELFnResult<List<Object>> invoke(@ParameterName( "ctx" ) EvaluationContext ctx,
                                             @ParameterName("list") List list,
                                             @ParameterName("precedes") FEELFunction function); FEELFnResult<List<Object>> invoke(@ParameterName("list") List list);  }
@Test public void invokeListParamNull() { FunctionTestUtil.assertResultError(sortFunction.invoke(null), InvalidParametersEvent.class); }
@Test public void invokeListEmpty() { FunctionTestUtil.assertResultList(sortFunction.invoke(Collections.emptyList()), Collections.emptyList()); }
@Test public void invokeListSingleItem() { FunctionTestUtil.assertResultList(sortFunction.invoke(Collections.singletonList(10)), Collections.singletonList(10)); }
@Test public void invokeListTypeHeterogenous() { FunctionTestUtil.assertResultError( sortFunction.invoke(Arrays.asList(10, "test", BigDecimal.TEN)), InvalidParametersEvent.class); }
@Test public void invokeList() { FunctionTestUtil.assertResultList(sortFunction.invoke(Arrays.asList(10, 4, 5, 12)), Arrays.asList(4, 5, 10, 12)); FunctionTestUtil.assertResultList(sortFunction.invoke(Arrays.asList("a", "c", "b")), Arrays.asList("a", "b", "c")); }
@Test public void invokeWithSortFunctionNull() { FunctionTestUtil.assertResultList( sortFunction.invoke(null, Arrays.asList(10, 4, 5, 12), null), Arrays.asList(4, 5, 10, 12)); }
@Test public void invokeWithSortFunction() { FunctionTestUtil.assertResultList( sortFunction.invoke(null, Arrays.asList(10, 4, 5, 12), getBooleanFunction(true)), Arrays.asList(12, 5, 4, 10)); FunctionTestUtil.assertResultList( sortFunction.invoke(null, Arrays.asList(10, 4, 5, 12), getBooleanFunction(false)), Arrays.asList(10, 4, 5, 12)); }
@Test public void invokeExceptionInSortFunction() { FunctionTestUtil.assertResultError( sortFunction.invoke(null, Arrays.asList(10, 4, 5, 12), getFunctionThrowingException()), InvalidParametersEvent.class); }