/** * Destroys the context of the context in the provided classloader, given the classloader is a different one than * of the specified context. The output properties from the other classloader are taken over to the given * context * @param ctx * the context to which the output properties of teh other classloader should be transferred * @param cl * the classloader whose context should be destroyed */ public static void destroy(final TestExecutionContext ctx, final ClassLoader cl) { //avoid destroying the context in the same classloader try { Class<?> contextClass = cl.loadClass(ctx.getClass().getName()); if (!Objects.equals(ctx.getClass(), contextClass)) { final Properties props = (Properties) cl.loadClass(ctx.getClass().getName()) .getMethod("destroy") .invoke(null); ctx.getOutput().putAll(props); } } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { throw new UncheckedException("Unable to destroy context", e); } }