DuringFunction extends BaseFEELFunction { public FEELFnResult<Boolean> invoke(@ParameterName( "value" ) Comparable value, @ParameterName( "range" ) Range range) { if ( value == null ) { return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "value", "cannot be null")); } if ( range == null ) { return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "range", "cannot be null")); } try { boolean result = (range.getLowEndPoint().compareTo(value) < 0 && range.getHighEndPoint().compareTo(value) > 0) || (range.getLowEndPoint().compareTo(value) == 0 && range.getLowBoundary() == RangeBoundary.CLOSED) || (range.getHighEndPoint().compareTo(value) == 0 && range.getHighBoundary() == RangeBoundary.CLOSED); return FEELFnResult.ofResult( result ); } catch( Exception e ) { return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "value", "cannot be compared to range")); } } DuringFunction(); FEELFnResult<Boolean> invoke(@ParameterName( "value" ) Comparable value, @ParameterName( "range" ) Range range); FEELFnResult<Boolean> invoke(@ParameterName( "range1" ) Range range1, @ParameterName( "range2" ) Range range2); static final DuringFunction INSTANCE; }
@Test public void invokeParamIsNull() { FunctionTestUtil.assertResultError( duringFunction.invoke((Comparable) null, (Range) new RangeImpl() ), InvalidParametersEvent.class ); FunctionTestUtil.assertResultError( duringFunction.invoke((Comparable) "a", (Range) null ), InvalidParametersEvent.class ); }
@Test public void invokeParamsCantBeCompared() { FunctionTestUtil.assertResultError( duringFunction.invoke( new RangeImpl( Range.RangeBoundary.CLOSED, "a", "f", Range.RangeBoundary.CLOSED ), new RangeImpl( Range.RangeBoundary.CLOSED, 1, 2, Range.RangeBoundary.CLOSED ) ), InvalidParametersEvent.class ); }
@Test public void invokeParamSingleAndRange() { FunctionTestUtil.assertResult( duringFunction.invoke( "c", new RangeImpl( Range.RangeBoundary.CLOSED, "a", "f", Range.RangeBoundary.CLOSED )), Boolean.TRUE ); FunctionTestUtil.assertResult( duringFunction.invoke( "f", new RangeImpl( Range.RangeBoundary.CLOSED, "a", "f", Range.RangeBoundary.CLOSED )), Boolean.TRUE ); FunctionTestUtil.assertResult( duringFunction.invoke( "a", new RangeImpl( Range.RangeBoundary.OPEN, "a", "f", Range.RangeBoundary.CLOSED )), Boolean.FALSE ); FunctionTestUtil.assertResult( duringFunction.invoke( "a", new RangeImpl( Range.RangeBoundary.CLOSED, "b", "f", Range.RangeBoundary.CLOSED )), Boolean.FALSE ); }
@Test public void invokeParamRangeAndRange() { FunctionTestUtil.assertResult( duringFunction.invoke( new RangeImpl( Range.RangeBoundary.CLOSED, "a", "f", Range.RangeBoundary.CLOSED ), new RangeImpl( Range.RangeBoundary.CLOSED, "a", "f", Range.RangeBoundary.CLOSED ) ), Boolean.TRUE ); FunctionTestUtil.assertResult( duringFunction.invoke( new RangeImpl( Range.RangeBoundary.CLOSED, "c", "f", Range.RangeBoundary.CLOSED ), new RangeImpl( Range.RangeBoundary.CLOSED, "a", "k", Range.RangeBoundary.CLOSED ) ), Boolean.TRUE ); FunctionTestUtil.assertResult( duringFunction.invoke( new RangeImpl( Range.RangeBoundary.CLOSED, "a", "f", Range.RangeBoundary.CLOSED ), new RangeImpl( Range.RangeBoundary.CLOSED, "c", "d", Range.RangeBoundary.CLOSED ) ), Boolean.FALSE ); FunctionTestUtil.assertResult( duringFunction.invoke( new RangeImpl( Range.RangeBoundary.CLOSED, "a", "f", Range.RangeBoundary.CLOSED ), new RangeImpl( Range.RangeBoundary.OPEN, "a", "k", Range.RangeBoundary.CLOSED ) ), Boolean.FALSE ); }