AbsFunction extends BaseFEELFunction { public FEELFnResult<BigDecimal> invoke(@ParameterName( "n" ) BigDecimal number) { if ( number == null ) { return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "number", "cannot be null")); } return FEELFnResult.ofResult( number.abs() ); } AbsFunction(); FEELFnResult<BigDecimal> invoke(@ParameterName( "n" ) BigDecimal number); FEELFnResult<Period> invoke(@ParameterName( "n" ) Period duration); FEELFnResult<Duration> invoke(@ParameterName( "n" ) Duration duration); static final AbsFunction INSTANCE; }
@Test public void testAbsFunctionNumber() { FunctionTestUtil.assertResult(absFunction.invoke(valueOf(10)), valueOf(10)); FunctionTestUtil.assertResult(absFunction.invoke(valueOf(-10)), valueOf(10)); FunctionTestUtil.assertResultError(absFunction.invoke((BigDecimal) null), InvalidParametersEvent.class); }
@Test public void testAbsFunctionDuration() { FunctionTestUtil.assertResult(absFunction.invoke(Duration.ofSeconds(100, 50 )), Duration.ofSeconds(100, 50)); FunctionTestUtil.assertResult(absFunction.invoke(Duration.ofSeconds(-100, 50 )), Duration.ofSeconds(100, -50)); FunctionTestUtil.assertResult(absFunction.invoke(Duration.ofSeconds(100, -50 )), Duration.ofSeconds(100, -50)); FunctionTestUtil.assertResult(absFunction.invoke(Duration.ofSeconds(-100, -50 )), Duration.ofSeconds(100, 50)); FunctionTestUtil.assertResultError(absFunction.invoke((Duration)null), InvalidParametersEvent.class); }
@Test public void testAbsFunctionPeriod() { FunctionTestUtil.assertResult(absFunction.invoke(Period.of( 100, 50, 0 ) ), Period.of(100, 50, 0)); FunctionTestUtil.assertResult(absFunction.invoke(Period.of( -100, 50, 0 ) ), Period.of(100, -50, 0)); FunctionTestUtil.assertResult(absFunction.invoke(Period.of( 100, -50, 0 ) ), Period.of(100, -50, 0)); FunctionTestUtil.assertResult(absFunction.invoke(Period.of( -100, -50, 0 ) ), Period.of(100, 50, 0)); FunctionTestUtil.assertResult(absFunction.invoke(Period.of( -1, 30, 0 ) ), Period.of(-1, 30, 0)); FunctionTestUtil.assertResultError(absFunction.invoke((Period) null ), InvalidParametersEvent.class); }