private static BiConsumer<String, String> defaultConsumer() { return (key, value) -> TestExecutionContext.current() .map(TestExecutionContext::getOutput) .ifPresent(output -> output.setProperty(key, value)); }
/** * Destroys the test context for the current thread. */ public static Properties destroy() { final Properties output = current().map(TestExecutionContext::getOutput) .orElseThrow(() -> new IllegalStateException("Context not initialized")); CURRENT_CONTEXT.remove(); return output; }
public ParameterProvider() { this.provider = key -> Optional.ofNullable(TestExecutionContext.current() .map(TestExecutionContext::getInput) .orElse(System.getProperties()) .getProperty(key)); }
private static Result invokeRun(final String className, final ClassLoader cl) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, IOException, InvocationTargetException { TestExecutionContext.current().ifPresent(ctx -> { System.getProperties().putAll(ctx.getEnv()); init(ctx, cl); }); try { final Class<?> testClass = cl.loadClass(className); final Object runner = cl.loadClass(JUnitRunner.class.getName()).newInstance(); final Method run = runner.getClass().getDeclaredMethod("run", Class.class); return new ResultHelper().deserialize((byte[]) run.invoke(runner, testClass)); } finally { TestExecutionContext.current().ifPresent(ctx -> destroy(ctx, cl)); } }