saynotobugsorg / confidence

A declarative Java Assertion Framework
Apache License 2.0
11 stars 1 forks source link

Ensure Resources are closed in order #123

Closed dmfs closed 11 months ago

dmfs commented 11 months ago

At present it may happen that a resource is closed before its derived resources are closed. In most cases this is not an issue, but there may be cases when this could become an issue.

dmfs commented 11 months ago

implementation idea: change the interface to something like this

public interface Resource<T>
{
    T value(User user);

    void close(User user) throws Exception;
}

where User is a type that identifies an Assertion decorator (WithResource) or another Resource that uses the given resource. A Resource would be closed when all Users have closed it. This would prevent eager usage (because you can't provide a reasonable User) and enable test class instantiation without creating test resources at the same time.