Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit introduces the @autoclose annotation, AutoCloseUtils class, and AutoCloseExtension class to enhance resource management in JUnit 5 tests.
The @autoclose Annotation:
The @autoclose annotation is a custom annotation created in the org.junit.jupiter.api package. It can be applied to fields within JUnit 5 test classes. This annotation indicates that the annotated resource
should be automatically closed after test execution. It specifically
targets ElementType.FIELD elements.
AutoCloseUtils Class:
The AutoCloseUtils class is added to the org.junit.jupiter.api
package. It provides utility methods for automatically closing
resources used in tests. The closeResources method takes a test
instance as a parameter and closes all fields annotated with
@autoclose within that instance.
AutoCloseExtension Class:
The AutoCloseExtension class is introduced in the
org.junit.jupiter.api.extension package. It implements the
AfterEachCallback interface and acts as a JUnit 5 extension. By using
the @ExtendWith(AutoCloseExtension.class) annotation on test classes
or methods, the extension invokes AutoCloseUtils.closeResources to
automatically close resources annotated with @autoclose after each
test execution.
These changes aim to simplify resource cleanup in JUnit 5 tests,
reduce boilerplate code, and enhance the readability of test code.
Please review the introduced changes and provide any feedback or
suggestions for improvement.
Overview
I hereby agree to the terms of the JUnit Contributor License Agreement.
Definition of Done
@API
annotations