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

dev.gradleplugins.fixtures.junit4.internal.SupplierExternalResource Maven / Gradle / Ivy

There is a newer version: 0.0.124
Show newest version
package dev.gradleplugins.fixtures.junit4.internal;

import org.junit.rules.ExternalResource;

import java.util.function.Supplier;

import static org.apache.commons.lang3.exception.ExceptionUtils.rethrow;

public class SupplierExternalResource extends ExternalResource {
    private Supplier supplier;
    private T resource;

    public SupplierExternalResource(Supplier supplier) {
        this.supplier = supplier;
    }

    @Override
    protected void before() throws Throwable {
        resource = supplier.get();
        supplier = null;
    }

    @Override
    protected void after() {
        try {
            if (resource instanceof AutoCloseable) {
                ((AutoCloseable) resource).close();
            }
        } catch (Exception e) {
            rethrow(e);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy