StartsWithFunction extends BaseFEELFunction { public FEELFnResult<Boolean> invoke(@ParameterName("string") String string, @ParameterName("match") String match) { if ( string == null ) { return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "string", "cannot be null")); } if ( match == null ) { return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "match", "cannot be null")); } return FEELFnResult.ofResult( string.startsWith( match ) ); } StartsWithFunction(); FEELFnResult<Boolean> invoke(@ParameterName("string") String string, @ParameterName("match") String match);  }
@Test public void invokeNull() { FunctionTestUtil.assertResultError(startsWithFunction.invoke((String) null, null), InvalidParametersEvent.class); FunctionTestUtil.assertResultError(startsWithFunction.invoke(null, "test"), InvalidParametersEvent.class); FunctionTestUtil.assertResultError(startsWithFunction.invoke("test", null), InvalidParametersEvent.class); }
@Test public void invokeEmptyString() { FunctionTestUtil.assertResult(startsWithFunction.invoke("", ""), true); FunctionTestUtil.assertResult(startsWithFunction.invoke("", "test"), false); FunctionTestUtil.assertResult(startsWithFunction.invoke("test", ""), true); }
@Test public void invokeStartsWith() { FunctionTestUtil.assertResult(startsWithFunction.invoke("test", "te"), true); FunctionTestUtil.assertResult(startsWithFunction.invoke("test", "t"), true); FunctionTestUtil.assertResult(startsWithFunction.invoke("test", "test"), true); }
@Test public void invokeNotStartsWith() { FunctionTestUtil.assertResult(startsWithFunction.invoke("test", "tte"), false); FunctionTestUtil.assertResult(startsWithFunction.invoke("test", "tt"), false); FunctionTestUtil.assertResult(startsWithFunction.invoke("test", "ttest"), false); }