Class MockScriptEngine

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, ScriptEngine

    public class MockScriptEngine
    extends java.lang.Object
    implements ScriptEngine
    A mocked script engine that can be used for testing purpose. This script engine allows to define a set of predefined scripts that basically a combination of a key and a function: The key can be anything as long as it is a String and is used to resolve the scripts at compilation time. For inline scripts, the key can be a description of the script. For stored and file scripts, the source must match a key in the predefined set of scripts. The function is used to provide the result of the script execution and can return anything.
    • Constructor Detail

      • MockScriptEngine

        public MockScriptEngine​(java.lang.String type,
                                java.util.Map<java.lang.String,​java.util.function.Function<java.util.Map<java.lang.String,​java.lang.Object>,​java.lang.Object>> scripts,
                                java.util.Map<ScriptContext<?>,​MockScriptEngine.ContextCompiler> contexts)
      • MockScriptEngine

        public MockScriptEngine()
    • Method Detail

      • getType

        public java.lang.String getType()
        Specified by:
        getType in interface ScriptEngine
      • compile

        public <T> T compile​(java.lang.String name,
                             java.lang.String source,
                             ScriptContext<T> context,
                             java.util.Map<java.lang.String,​java.lang.String> params)
        Specified by:
        compile in interface ScriptEngine
      • mockInlineScript

        public static Script mockInlineScript​(java.lang.String script)