ScriptEngineLambda implements Function, Supplier, Consumer, Predicate, BiConsumer, TriConsumer { public boolean test(final Object a) { try { final Bindings bindings = new SimpleBindings(); bindings.put(A, a); return (boolean) this.engine.eval(this.script, bindings); } catch (final ScriptException e) { throw new IllegalArgumentException(e.getMessage()); } } ScriptEngineLambda(final String engineName, final String script); Object apply(final Object a); Object get(); void accept(final Object a); void accept(final Object a, final Object b); void accept(final Object a, final Object b, final Object c); boolean test(final Object a);  }
@Test public void shouldCallAsPredicate() { final ScriptEngineLambda lambda = new ScriptEngineLambda("nashorn", "a > 10"); assertThat(lambda.test(100), is(true)); }
@Test(expected = IllegalArgumentException.class) public void shouldThrowOnBadScriptAsPredicate() { new ScriptEngineLambda("nashorn", "1432423)a").test(1); }