FunctionRegistry { public Function getFunction(String functionName) { return functions.get(functionName); } FunctionRegistry(Function... functions); private  FunctionRegistry(Map<String, Function> functions0, Function... functions1); static FunctionRegistry defaultRegistry(); Function getFunction(String functionName); FunctionRegistry extend(Function... functions);  }
@Test public void aCustomRegistryDoesNotContainTheDefaultFunctions() { FunctionRegistry customRegistry = new FunctionRegistry( new TestFunction("foo", ArgumentConstraints.typeOf(JmesPathType.STRING)) ); for (String functionName : DEFAULT_FUNCTION_NAMES) { assertThat(customRegistry.getFunction(functionName), is(nullValue())); } }
@Test public void aCustomRegistryContainsTheProvidedFunctions() { FunctionRegistry customRegistry = new FunctionRegistry( new TestFunction("foo", ArgumentConstraints.typeOf(JmesPathType.STRING)), new TestFunction("bar", ArgumentConstraints.typeOf(JmesPathType.NUMBER)) ); assertThat(customRegistry.getFunction("foo").name(), is("foo")); assertThat(customRegistry.getFunction("bar").name(), is("bar")); }
@Test public void theLastFunctionIsUsedWhenThereAreDuplicatedNames() { FunctionRegistry customRegistry = new FunctionRegistry( new TestFunction("foo", ArgumentConstraints.typeOf(JmesPathType.STRING)), new TestFunction("foo", ArgumentConstraints.typeOf(JmesPathType.NUMBER)) ); Function function = customRegistry.getFunction("foo"); Object result = function.call(runtime, createValueArguments(3L)); assertThat(result, is((Object) 3L)); }