use of org.junit.jupiter.api.extension.ExtensionContext.Store.CloseableResource in project junit5 by junit-team.
the class ExtensionValuesStore method closeAllStoredCloseableValues.
/**
* Close all values that implement {@link CloseableResource}.
*
* @implNote Only close values stored in this instance. This implementation
* does not close values in parent stores.
*/
public void closeAllStoredCloseableValues() {
ThrowableCollector throwableCollector = createThrowableCollector();
//
storedValues.values().stream().filter(//
storedValue -> storedValue.evaluateSafely() instanceof CloseableResource).sorted(//
REVERSE_INSERT_ORDER).map(//
storedValue -> (CloseableResource) storedValue.evaluate()).forEach(resource -> throwableCollector.execute(resource::close));
throwableCollector.assertEmpty();
}
Aggregations