dev.gradleplugins.fixtures.junit4.internal.SupplierExternalResource Maven / Gradle / Ivy
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