All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tdder.junit.jupiter.extension.TeardownRegistryImpl Maven / Gradle / Ivy

The newest version!
package com.tdder.junit.jupiter.extension;

import java.util.Deque;
import java.util.LinkedList;

class TeardownRegistryImpl implements TeardownRegistry {

    private final Deque tasks_ = new LinkedList<>();

    @Override
    public  T add(final T closeable) {
        tasks_.add(closeable);
        return closeable;
    }

    int size() {
        return tasks_.size();
    }

    public void teardown(final ExceptionHandler exceptionHandler) throws Exception {
        while (!tasks_.isEmpty()) {
            // teardown in reverse order
            final AutoCloseable task = tasks_.removeLast();
            try {
                task.close();
            } catch (final Exception e) {
                exceptionHandler.add(e);
            }
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy