@Override
    public void contextCleaned(StatementContext statementContext) {
        requireNonNull(statementContext, "statementContext is null!");

        assertTrue(contextElements.containsKey(statementContext),
            () -> format("statement context %s is unknown", statementContext));

        RecordingContext<Cleanable> context = contextElements.get(statementContext);

        Set<Cleanable> leakedCleanables = context.leakedElements();
        if (!leakedCleanables.isEmpty()) {
            fail(format("Found %d cleanables that were not removed [%s]", leakedCleanables.size(), leakedCleanables));
        }

        context.reset();
    }
A simple leak checker that tracks statement context and cleanable resource management.
testing/src/main/java/org/jdbi/v3/testing/junit5/internal/JdbiLeakChecker.java