/** * Checks if the specified path contains any class file. * @param path * the path to check * @return * <code>true</code> if the path contains at least one class file */ private boolean containsClassFiles(final Path path) { return runUnchecked(() -> Files.list(path).anyMatch(this::isClassFile)); }
/** * Executes a specified task. If an exception occurs it will be wrapped in a RuntimeException * @param runnable * the task to be executed * @return * the result of the task execution */ public static void runUnchecked(Runnable runnable) { //NOSONAR runProtected(runnable).mapException(Exception.class, UncheckedException::new).get(); }
/** * Executes a specified task, regardless if it throws a checked or unchecked exception. * If an exception occurs it will be caught and wrapped in the execution result. * @param call * the task to be executed * @param <T> * the type of the return value * @return * the result of the task execution */ public static <T> T runUnchecked(Callable<T> call) { return runProtected(call).mapException(Exception.class, UncheckedException::new).get(); }
/** * Initializes the specified context in the provided classloader, given the classloader is a different one than * of the specified context * @param ctx * the context that should be transferred to the other classloader * @param cl * the classloader whose context should be initialized */ public static void init(final TestExecutionContext ctx, final ClassLoader cl) { //avoid overwriting the context in the same classloader if (!Objects.equals(ctx.getClass().getClassLoader(), cl)) { //NOSONAR runUnchecked(() -> cl.loadClass(ctx.getClass().getName()) .getMethod("init", Properties.class, Properties.class) .invoke(null, ctx.getInput(), ctx.getEnv())); } }