FlattenFunction extends BaseFEELFunction { public FEELFnResult<List> invoke(@ParameterName( "list" ) Object list) { if ( list == null ) { return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "list", "cannot be null")); } final List<Object> result = new ArrayList<>(); flattenList( list, result ); return FEELFnResult.ofResult( result ); } FlattenFunction(); FEELFnResult<List> invoke(@ParameterName( "list" ) Object list);  }
@Test public void invokeNull() { FunctionTestUtil.assertResultError(flattenFunction.invoke(null), InvalidParametersEvent.class); }
@Test public void invokeParamNotCollection() { FunctionTestUtil.assertResult(flattenFunction.invoke(BigDecimal.valueOf(10.2)), Collections.singletonList(BigDecimal.valueOf(10.2))); FunctionTestUtil.assertResult(flattenFunction.invoke("test"), Collections.singletonList("test")); }
@Test public void invokeParamCollection() { FunctionTestUtil.assertResult(flattenFunction.invoke(Arrays.asList("test", 1, 2)), Arrays.asList("test", 1, 2)); FunctionTestUtil.assertResult(flattenFunction.invoke(Arrays.asList("test", 1, 2, Arrays.asList(3, 4))), Arrays.asList("test", 1, 2, 3, 4)); FunctionTestUtil.assertResult(flattenFunction.invoke(Arrays.asList("test", 1, 2, Arrays.asList(1, 2))), Arrays.asList("test", 1, 2, 1, 2)); FunctionTestUtil.assertResult( flattenFunction.invoke( Arrays.asList("test", 1, Arrays.asList(BigDecimal.ZERO, 3), 2, Arrays.asList(1, 2))), Arrays.asList("test", 1, BigDecimal.ZERO, 3, 2, 1, 2)); FunctionTestUtil.assertResult( flattenFunction.invoke( Arrays.asList("test", 1, Arrays.asList(Arrays.asList(10, 15), BigDecimal.ZERO, 3), 2, Arrays.asList(1, 2))), Arrays.asList("test", 1, 10, 15, BigDecimal.ZERO, 3, 2, 1, 2)); }