### Question:
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);  }### Answer:
@Test public void testStaticMethodDefaultExecution() throws ScriptException { DefaultExecutionStrategy executionStrategy = new DefaultExecutionStrategy(TestStaticMethodExecution.class); Object result = executionStrategy.execute(null); assertThat(result).isEqualTo("static success"); }
@Test public void failStaticMethodDefaultExecution() throws ScriptException { DefaultExecutionStrategy executionStrategy = new DefaultExecutionStrategy(TestSupplierExecution.class); assertThatThrownBy(() -> { executionStrategy.execute(null); }).isInstanceOf(ScriptException.class); }
@Test public void testSupplierDefaultExecution() throws ScriptException { DefaultExecutionStrategy executionStrategy = new DefaultExecutionStrategy(TestSupplierExecution.class); TestSupplierExecution instance = new TestSupplierExecution(); Object result = executionStrategy.execute(instance); assertThat(result).isEqualTo("Supplier"); }
@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); }
@Test public void testMethodDefaultExecution() throws ScriptException { DefaultExecutionStrategy executionStrategy = new DefaultExecutionStrategy(TestMethodExecution.class); TestMethodExecution instance = new TestMethodExecution(); Object result = executionStrategy.execute(instance); assertThat(result).isEqualTo("success"); }
@Test public void testNoMethodDefaultExecution() { DefaultExecutionStrategy executionStrategy = new DefaultExecutionStrategy(TestNoMethodExecution.class); TestNoMethodExecution instance = new TestNoMethodExecution(); assertThatThrownBy(() -> { executionStrategy.execute(instance); }).isInstanceOf(ScriptException.class); }
@Test public void testAmbiguousMethodDefaultExecution() { DefaultExecutionStrategy executionStrategy = new DefaultExecutionStrategy(TestAmbiguousMethodExecution.class); TestAmbiguousMethodExecution instance = new TestAmbiguousMethodExecution(); assertThatThrownBy(() -> { executionStrategy.execute(instance); }).isInstanceOf(ScriptException.class); }
@Test public void testThrowExceptionDefaultExecution() { DefaultExecutionStrategy executionStrategy = new DefaultExecutionStrategy(TestThrowExceptionExecution.class); TestThrowExceptionExecution instance = new TestThrowExceptionExecution(); assertThatThrownBy(() -> { executionStrategy.execute(instance); }).isInstanceOf(ScriptException.class); }