YearsAndMonthsFunction extends BaseFEELFunction { public FEELFnResult<TemporalAmount> invoke(@ParameterName("from") Temporal from, @ParameterName("to") Temporal to) { if ( from == null ) { return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "from", "cannot be null")); } if ( to == null ) { return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "to", "cannot be null")); } final LocalDate fromDate = getLocalDateFromTemporal(from); if (fromDate == null) { return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "from", "is of type not suitable for years and months function")); } final LocalDate toDate = getLocalDateFromTemporal(to); if (toDate == null) { return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "to", "is of type not suitable for years and months function")); } return FEELFnResult.ofResult(new ComparablePeriod(Period.between(fromDate, toDate).withDays(0))); } YearsAndMonthsFunction(); FEELFnResult<TemporalAmount> invoke(@ParameterName("from") Temporal from, @ParameterName("to") Temporal to);  }
@Test public void invokeNull() { FunctionTestUtil.assertResultError(yamFunction.invoke((Temporal) null, null), InvalidParametersEvent.class); FunctionTestUtil.assertResultError(yamFunction.invoke(null, LocalDate.now()), InvalidParametersEvent.class); FunctionTestUtil.assertResultError(yamFunction.invoke(LocalDate.now(), null), InvalidParametersEvent.class); }
@Test public void invokeUnsupportedTemporal() { FunctionTestUtil.assertResultError(yamFunction.invoke(Instant.EPOCH, Instant.EPOCH), InvalidParametersEvent.class); FunctionTestUtil.assertResultError(yamFunction.invoke(LocalDate.of(2017, 1, 1), Instant.EPOCH), InvalidParametersEvent.class); }
@Test public void invokeYear() { FunctionTestUtil.assertResult(yamFunction.invoke(Year.of(2017), Year.of(2020)), ComparablePeriod.of(3, 0, 0)); FunctionTestUtil.assertResult(yamFunction.invoke(Year.of(2017), Year.of(2014)), ComparablePeriod.of(-3, 0, 0)); }
@Test public void invokeYearMonth() { FunctionTestUtil.assertResult( yamFunction.invoke(YearMonth.of(2017, 6), Year.of(2020)), ComparablePeriod.of(2, 7, 0)); FunctionTestUtil.assertResult( yamFunction.invoke(YearMonth.of(2017, 6), Year.of(2014)), ComparablePeriod.of(-3, -5, 0)); }
@Test public void invokeYearLocalDate() { FunctionTestUtil.assertResult( yamFunction.invoke(LocalDate.of(2017, 6, 12), Year.of(2020)), ComparablePeriod.of(2, 6, 0)); }
@Test public void invokeYearMonthLocalDate() { FunctionTestUtil.assertResult( yamFunction.invoke( LocalDate.of(2017, 6, 12), YearMonth.of(2020, 4)), ComparablePeriod.of(2, 9, 0)); }
@Test public void testYearsAndMonthsFunction_invokeLocalDateTime() { FunctionTestUtil.assertResult( yamFunction.invoke( LocalDateTime.of(2017, 6, 12, 12, 43), LocalDate.of(2020, 7, 13)), ComparablePeriod.of(3, 1, 0)); }
@Test public void invokeLocalDateLocalDate() { FunctionTestUtil.assertResult( yamFunction.invoke( LocalDate.of(2017, 6, 12), LocalDate.of(2020, 7, 13)), ComparablePeriod.of(3, 1, 0)); }