UnionFunction extends BaseFEELFunction { public FEELFnResult<List<Object>> invoke(@ParameterName("list") Object[] lists) { if ( lists == null ) { return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "lists", "cannot be null")); } final Set<Object> resultSet = new LinkedHashSet<>(); for ( final Object list : lists ) { if ( list instanceof Collection ) { resultSet.addAll((Collection) list); } else { resultSet.add(list); } } return FEELFnResult.ofResult( new ArrayList<>(resultSet) ); } UnionFunction(); FEELFnResult<List<Object>> invoke(@ParameterName("list") Object[] lists);  }
@Test public void invokeNull() { FunctionTestUtil.assertResultError(unionFunction.invoke(null), InvalidParametersEvent.class); }
@Test public void invokeEmptyArray() { FunctionTestUtil.assertResultList(unionFunction.invoke(new Object[]{}), Collections.emptyList()); }
@Test public void invokeSingleObject() { FunctionTestUtil.assertResult(unionFunction.invoke(new Object[]{10}), Collections.singletonList(10)); }
@Test public void invokeSingleObjectInAList() { FunctionTestUtil.assertResult(unionFunction.invoke(new Object[]{Collections.singletonList(10)}), Collections.singletonList(10)); }
@Test public void invokeSingleObjectInAnArray() { final int[] testArray = new int[]{10}; FunctionTestUtil.assertResult(unionFunction.invoke(new Object[]{testArray}), Collections.singletonList(testArray)); }
@Test public void invokeListIsNull() { FunctionTestUtil.assertResult(unionFunction.invoke(new Object[]{null}), Collections.singletonList(null)); }
@Test public void invokeListContainsNull() { FunctionTestUtil.assertResult(unionFunction.invoke(new Object[]{Arrays.asList(null, 10, null)}), Arrays.asList(null, 10)); }
@Test public void invokeListsNoDuplicates() { final Object[] params = new Object[]{Arrays.asList(10, 8, 3), Arrays.asList(1, 15, 2)}; FunctionTestUtil.assertResultList(unionFunction.invoke(params), Arrays.asList(10, 8, 3, 1, 15, 2)); }
@Test public void invokeListsSomeDuplicates() { final Object[] params = new Object[]{Arrays.asList(10, 8, 3), Arrays.asList(1, 10, 2), Arrays.asList(10, 3, 2, 5)}; FunctionTestUtil.assertResultList(unionFunction.invoke(params), Arrays.asList(10, 8, 3, 1, 2, 5)); }
@Test public void invokeListsAllDuplicates() { final Object[] params = new Object[]{Arrays.asList(10, 8, 3), Arrays.asList(10, 8, 3), Arrays.asList(3, 10, 8)}; FunctionTestUtil.assertResultList(unionFunction.invoke(params), Arrays.asList(10, 8, 3)); }
@Test public void invokeListAndSingleObject() { FunctionTestUtil.assertResultList(unionFunction.invoke(new Object[]{Arrays.asList(10, 4, 5), 1}), Arrays.asList(10, 4, 5, 1)); }
@Test public void invokeListAndSingleObjectWithDuplicates() { FunctionTestUtil.assertResultList(unionFunction.invoke(new Object[]{5, Arrays.asList(10, 4, 5), 10}), Arrays.asList(5, 10, 4)); }
@Test public void invokeMixedTypes() { FunctionTestUtil.assertResultList( unionFunction.invoke(new Object[]{"test", Arrays.asList(10, "test", 5), BigDecimal.TEN}), Arrays.asList("test", 10, 5, BigDecimal.TEN)); }