@Test public void testRunnableDefaultExecution() throws ScriptException { DefaultExecutionStrategy executionStrategy = new DefaultExecutionStrategy(TestRunnableExecution.class); TestRunnableExecution instance = new TestRunnableExecution(); Object result = executionStrategy.execute(instance); assertThat(result).isNull(); assertThat(instance.counter).isEqualTo(1); }
@Override public Object execute(Object instance) throws ScriptException { if (instance instanceof Supplier) { Supplier<?> supplier = (Supplier<?>) instance; return supplier.get(); } if (instance instanceof Runnable) { Runnable runnable = (Runnable) instance; runnable.run(); return null; } if (method != null) { try { return method.invoke(instance); } catch (IllegalAccessException | InvocationTargetException e) { throw new ScriptException(e); } } if (instance == null) { throw new ScriptException("No static method found to execute of type " + clazz.getName()); } throw new ScriptException("No method found to execute instance of type " + clazz.getName()); }
DefaultExecutionStrategy implements ExecutionStrategy { @Override public Object execute(Object instance) throws ScriptException { if (instance instanceof Supplier) { Supplier<?> supplier = (Supplier<?>) instance; return supplier.get(); } if (instance instanceof Runnable) { Runnable runnable = (Runnable) instance; runnable.run(); return null; } if (method != null) { try { return method.invoke(instance); } catch (IllegalAccessException | InvocationTargetException e) { throw new ScriptException(e); } } if (instance == null) { throw new ScriptException("No static method found to execute of type " + clazz.getName()); } throw new ScriptException("No method found to execute instance of type " + clazz.getName()); } }
DefaultExecutionStrategy implements ExecutionStrategy { @Override public Object execute(Object instance) throws ScriptException { if (instance instanceof Supplier) { Supplier<?> supplier = (Supplier<?>) instance; return supplier.get(); } if (instance instanceof Runnable) { Runnable runnable = (Runnable) instance; runnable.run(); return null; } if (method != null) { try { return method.invoke(instance); } catch (IllegalAccessException | InvocationTargetException e) { throw new ScriptException(e); } } if (instance == null) { throw new ScriptException("No static method found to execute of type " + clazz.getName()); } throw new ScriptException("No method found to execute instance of type " + clazz.getName()); } DefaultExecutionStrategy(Class<?> clazz); }
DefaultExecutionStrategy implements ExecutionStrategy { @Override public Object execute(Object instance) throws ScriptException { if (instance instanceof Supplier) { Supplier<?> supplier = (Supplier<?>) instance; return supplier.get(); } if (instance instanceof Runnable) { Runnable runnable = (Runnable) instance; runnable.run(); return null; } if (method != null) { try { return method.invoke(instance); } catch (IllegalAccessException | InvocationTargetException e) { throw new ScriptException(e); } } if (instance == null) { throw new ScriptException("No static method found to execute of type " + clazz.getName()); } throw new ScriptException("No method found to execute instance of type " + clazz.getName()); } DefaultExecutionStrategy(Class<?> clazz); @Override Object execute(Object instance); }
DefaultExecutionStrategy implements ExecutionStrategy { @Override public Object execute(Object instance) throws ScriptException { if (instance instanceof Supplier) { Supplier<?> supplier = (Supplier<?>) instance; return supplier.get(); } if (instance instanceof Runnable) { Runnable runnable = (Runnable) instance; runnable.run(); return null; } if (method != null) { try { return method.invoke(instance); } catch (IllegalAccessException | InvocationTargetException e) { throw new ScriptException(e); } } if (instance == null) { throw new ScriptException("No static method found to execute of type " + clazz.getName()); } throw new ScriptException("No method found to execute instance of type " + clazz.getName()); } DefaultExecutionStrategy(Class<?> clazz); @Override Object execute(Object instance);  }