AfterFunction extends BaseFEELFunction { public FEELFnResult<Boolean> invoke(@ParameterName( "value1" ) Comparable value1, @ParameterName( "value2" ) Comparable value2) { if ( value1 == null ) { return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "value1", "cannot be null")); } if ( value2 == null ) { return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "value2", "cannot be null")); } try { boolean result = value1.compareTo( value2 ) > 0; return FEELFnResult.ofResult( result ); } catch( Exception e ) { return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "value1", "cannot be compared to value2")); } } AfterFunction(); FEELFnResult<Boolean> invoke(@ParameterName( "value1" ) Comparable value1, @ParameterName( "value2" ) Comparable value2); FEELFnResult<Boolean> invoke(@ParameterName( "value" ) Comparable value, @ParameterName( "range" ) Range range); FEELFnResult<Boolean> invoke(@ParameterName( "range" ) Range range, @ParameterName( "value" ) Comparable value); FEELFnResult<Boolean> invoke(@ParameterName( "range1" ) Range range1, @ParameterName( "range2" ) Range range2); static final AfterFunction INSTANCE; }
@Test public void invokeParamIsNull() { FunctionTestUtil.assertResultError( afterFunction.invoke((Comparable) null, (Comparable) "b" ), InvalidParametersEvent.class ); FunctionTestUtil.assertResultError( afterFunction.invoke((Comparable) "a", (Comparable) null ), InvalidParametersEvent.class ); }
@Test public void invokeParamsCantBeCompared() { FunctionTestUtil.assertResultError( afterFunction.invoke("a", BigDecimal.valueOf(2) ), InvalidParametersEvent.class ); }
@Test public void invokeParamSingles() { FunctionTestUtil.assertResult( afterFunction.invoke( "a", "b" ), Boolean.FALSE ); FunctionTestUtil.assertResult( afterFunction.invoke( "a", "a" ), Boolean.FALSE ); FunctionTestUtil.assertResult( afterFunction.invoke( "b", "a" ), Boolean.TRUE ); FunctionTestUtil.assertResult( afterFunction.invoke( BigDecimal.valueOf(2), BigDecimal.valueOf(1) ), Boolean.TRUE ); FunctionTestUtil.assertResult( afterFunction.invoke( BigDecimal.valueOf(1), BigDecimal.valueOf(2) ), Boolean.FALSE ); FunctionTestUtil.assertResult( afterFunction.invoke( BigDecimal.valueOf(1), BigDecimal.valueOf(1) ), Boolean.FALSE ); }
@Test public void invokeParamSingleAndRange() { FunctionTestUtil.assertResult( afterFunction.invoke( "a", new RangeImpl( Range.RangeBoundary.CLOSED, "a", "f", Range.RangeBoundary.CLOSED )), Boolean.FALSE ); FunctionTestUtil.assertResult( afterFunction.invoke( "f", new RangeImpl( Range.RangeBoundary.CLOSED, "a", "f", Range.RangeBoundary.CLOSED )), Boolean.FALSE ); FunctionTestUtil.assertResult( afterFunction.invoke( "f", new RangeImpl( Range.RangeBoundary.CLOSED, "a", "f", Range.RangeBoundary.OPEN )), Boolean.TRUE ); FunctionTestUtil.assertResult( afterFunction.invoke( "g", new RangeImpl( Range.RangeBoundary.CLOSED, "a", "f", Range.RangeBoundary.CLOSED )), Boolean.TRUE ); }
@Test public void invokeParamRangeAndSingle() { FunctionTestUtil.assertResult( afterFunction.invoke( new RangeImpl( Range.RangeBoundary.CLOSED, "a", "f", Range.RangeBoundary.CLOSED ), "f" ), Boolean.FALSE ); FunctionTestUtil.assertResult( afterFunction.invoke( new RangeImpl( Range.RangeBoundary.CLOSED, "a", "f", Range.RangeBoundary.CLOSED ), "a"), Boolean.FALSE ); FunctionTestUtil.assertResult( afterFunction.invoke( new RangeImpl( Range.RangeBoundary.OPEN, "a", "f", Range.RangeBoundary.CLOSED ), "a" ), Boolean.TRUE ); FunctionTestUtil.assertResult( afterFunction.invoke( new RangeImpl( Range.RangeBoundary.CLOSED, "b", "f", Range.RangeBoundary.CLOSED ), "a" ), Boolean.TRUE ); }
@Test public void invokeParamRangeAndRange() { FunctionTestUtil.assertResult( afterFunction.invoke( new RangeImpl( Range.RangeBoundary.CLOSED, "a", "f", Range.RangeBoundary.CLOSED ), new RangeImpl( Range.RangeBoundary.CLOSED, "a", "f", Range.RangeBoundary.CLOSED ) ), Boolean.FALSE ); FunctionTestUtil.assertResult( afterFunction.invoke( new RangeImpl( Range.RangeBoundary.CLOSED, "g", "k", Range.RangeBoundary.CLOSED ), new RangeImpl( Range.RangeBoundary.CLOSED, "a", "f", Range.RangeBoundary.CLOSED ) ), Boolean.TRUE ); FunctionTestUtil.assertResult( afterFunction.invoke( new RangeImpl( Range.RangeBoundary.CLOSED, "f", "k", Range.RangeBoundary.CLOSED ), new RangeImpl( Range.RangeBoundary.CLOSED, "a", "f", Range.RangeBoundary.CLOSED ) ), Boolean.FALSE ); FunctionTestUtil.assertResult( afterFunction.invoke( new RangeImpl( Range.RangeBoundary.OPEN, "f", "k", Range.RangeBoundary.CLOSED ), new RangeImpl( Range.RangeBoundary.CLOSED, "a", "f", Range.RangeBoundary.CLOSED ) ), Boolean.TRUE ); FunctionTestUtil.assertResult( afterFunction.invoke( new RangeImpl( Range.RangeBoundary.CLOSED, "f", "k", Range.RangeBoundary.CLOSED ), new RangeImpl( Range.RangeBoundary.CLOSED, "a", "f", Range.RangeBoundary.OPEN ) ), Boolean.TRUE ); }