private static Map.Entry<String, String> grabConsoleOutputAndError(Runnable runnable) {
        ByteArrayOutputStream outBuf = new ByteArrayOutputStream();
        ByteArrayOutputStream errBuf = new ByteArrayOutputStream();
        PrintStream out = new PrintStream(outBuf);
        PrintStream err = new PrintStream(errBuf);
        try {
            Console.withOut(out, () -> {
                Console.withErr(err, () -> {
                    runnable.run();
                    return null;
                });
                return null;
            });
        } finally {
            out.flush();
            err.flush();
        }

        return new SimpleImmutableEntry<>(outBuf.toString(), errBuf.toString());
    }
Capture both the console output and console error during the execution of the provided function.
core/src/test/java/kafka/admin/AclCommandTest.java