JavaExecutionCachedEngine extends ExecutionCachedEngine<JavaExecutor> implements JavaExecutionEngine { @Override public Object execute(String dependency, String className, String methodName, JavaExecutionParametersProvider parametersProvider) { JavaExecutor executor = allocateExecutor((dependency == null || dependency.isEmpty()) ? Sets.<String>newHashSet() : Sets.newHashSet(dependency)); try { return executor.execute(className, methodName, parametersProvider); } finally { releaseExecutor(executor); } }  @Override Object execute(String dependency, String className, String methodName, JavaExecutionParametersProvider parametersProvider);  }
@Test public void testJavaExecutorReleasedAfterSuccessExecution() { final JavaExecutor javaExecutor = mock(JavaExecutor.class); JavaExecutionCachedEngine engine = new JavaExecutionCachedEngine() { public JavaExecutor allocateExecutor(Set<String> dependencies) { return javaExecutor; } }; engine.execute("", "", "", null); verify(javaExecutor).release(); }
@Test public void testJavaExecutorReleasedAfterException() { final JavaExecutor javaExecutor = mock(JavaExecutor.class); final String gav = ""; final String className = ""; final String methodName = ""; JavaExecutionParametersProvider provider = null; when(javaExecutor.execute(className, methodName, provider)).thenThrow(new IllegalArgumentException("")); JavaExecutionCachedEngine engine = new JavaExecutionCachedEngine() { public JavaExecutor allocateExecutor(Set<String> dependencies) { return javaExecutor; } }; try { engine.execute(gav, className, methodName, provider); } catch (Throwable t) { assertTrue(t instanceof IllegalArgumentException); } verify(javaExecutor).release(); }