DistinctValuesFunction extends BaseFEELFunction { public FEELFnResult<List<Object>> 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<>(); if ( list instanceof Collection ) { for (Object o : (Collection) list) { if ( !result.contains( o ) ) { result.add(o); } } } else { result.add( list ); } return FEELFnResult.ofResult( result ); } DistinctValuesFunction(); FEELFnResult<List<Object>> invoke(@ParameterName( "list" ) Object list);  }
@Test public void invokeNull() { FunctionTestUtil.assertResultError(distinctValuesFunction.invoke(null), InvalidParametersEvent.class); }
@Test public void invokeParamNotCollection() { FunctionTestUtil.assertResultList( distinctValuesFunction.invoke(BigDecimal.valueOf(10.1)), Collections.singletonList(BigDecimal.valueOf(10.1))); }
@Test public void invokeParamArray() { FunctionTestUtil.assertResultList( distinctValuesFunction.invoke(new Object[]{BigDecimal.valueOf(10.1)}), Collections.singletonList(new Object[]{BigDecimal.valueOf(10.1)})); }
@Test public void invokeEmptyList() { FunctionTestUtil.assertResultList(distinctValuesFunction.invoke(Collections.emptyList()), Collections.emptyList()); }
@Test public void invokeList() { final List testValues = Arrays.asList(1, BigDecimal.valueOf(10.1), "test", 1, "test", BigDecimal.valueOf(10.1)); FunctionTestUtil.assertResultList( distinctValuesFunction.invoke(testValues), Arrays.asList(1, BigDecimal.valueOf(10.1), "test")); }