-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Replace opt-in annotation with extension method #4062
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
marcphilipp
merged 5 commits into
main
from
marc/replace-annotation-with-extension-method
Oct 11, 2024
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1db2432
Replace annotation with boolean-returning method
marcphilipp 6b80f42
Return enum instead of boolean
marcphilipp bbafe10
Create specialized sub-interface of Extension
marcphilipp f8ca2d3
Revise naming and documentation of `ExtensionContextScope`
marcphilipp e062120
Rename to TestInstantiationAwareExtension
marcphilipp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 0 additions & 80 deletions
80
...api/src/main/java/org/junit/jupiter/api/extension/EnableTestScopedConstructorContext.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
.../org/junit/jupiter/api/extension/TestClassInstanceConstructionParticipatingExtension.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| /* | ||
| * Copyright 2015-2024 the original author or authors. | ||
| * | ||
| * All rights reserved. This program and the accompanying materials are | ||
| * made available under the terms of the Eclipse Public License v2.0 which | ||
| * accompanies this distribution and is available at | ||
| * | ||
| * https://www.eclipse.org/legal/epl-v20.html | ||
| */ | ||
|
|
||
| package org.junit.jupiter.api.extension; | ||
|
|
||
| import static org.apiguardian.api.API.Status.DEPRECATED; | ||
| import static org.apiguardian.api.API.Status.EXPERIMENTAL; | ||
|
|
||
| import org.apiguardian.api.API; | ||
| import org.junit.jupiter.api.TestInstance; | ||
|
|
||
| /** | ||
| * Interface for {@link Extension Extensions} that participate in the | ||
| * construction of test class instances. | ||
| * | ||
| * @since 5.12 | ||
| * @see InvocationInterceptor#interceptTestClassConstructor | ||
| * @see ParameterResolver | ||
| * @see TestInstancePreConstructCallback | ||
| * @see TestInstancePostProcessor | ||
| * @see TestInstanceFactory | ||
| */ | ||
| @API(status = EXPERIMENTAL, since = "5.12") | ||
| public interface TestClassInstanceConstructionParticipatingExtension extends Extension { | ||
marcphilipp marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Whether this extension should receive a test-scoped | ||
| * {@link ExtensionContext} during the creation of test instances. | ||
| * | ||
| * <p>If an extension returns | ||
| * {@link ExtensionContextScope#TEST_METHOD TEST_SCOPED} from this method, | ||
| * the following extension methods will be called with a test-scoped | ||
| * {@link ExtensionContext} instead of a class-scoped one, unless the | ||
| * {@link TestInstance.Lifecycle#PER_CLASS PER_CLASS} lifecycle is used: | ||
| * | ||
| * <ul> | ||
| * <li>{@link InvocationInterceptor#interceptTestClassConstructor}</li> | ||
| * <li>{@link ParameterResolver} when resolving constructor parameters</li> | ||
| * <li>{@link TestInstancePreConstructCallback}</li> | ||
| * <li>{@link TestInstancePostProcessor}</li> | ||
| * <li>{@link TestInstanceFactory}</li> | ||
| * </ul> | ||
| * | ||
| * <p>In such cases, implementations of these extension callbacks can | ||
| * observe the following differences: | ||
| * | ||
| * <ul> | ||
| * <li>{@link ExtensionContext#getElement() getElement()} may refer to the | ||
| * test method and {@link ExtensionContext#getTestClass() getTestClass()} | ||
| * may refer to a nested test class. | ||
| * Use {@link TestInstanceFactoryContext#getTestClass()} to get the class | ||
| * under construction.</li> | ||
| * <li>{@link ExtensionContext#getTestMethod() getTestMethod()} is no-longer | ||
| * empty, unless the test class is annotated with | ||
| * {@link TestInstance @TestInstance(Lifecycle.PER_CLASS)}.</li> | ||
| * <li>If the callback adds a new {@link ExtensionContext.Store.CloseableResource} to the | ||
| * {@link ExtensionContext.Store}, the resource is closed just after the instance is | ||
| * destroyed.</li> | ||
| * <li>The callbacks can now access data previously stored by | ||
| * {@link TestTemplateInvocationContext}, unless the test class is annotated | ||
| * with {@link TestInstance @TestInstance(Lifecycle.PER_CLASS)}.</li> | ||
| * </ul> | ||
| * | ||
| * <p><strong>Note</strong>: The behavior which is enabled by returning | ||
| * {@link ExtensionContextScope#TEST_METHOD TEST_SCOPED} from this method | ||
| * will become the default in future versions of JUnit. To ensure future | ||
| * compatibility, extension implementors are therefore advised to opt in, | ||
| * even if they don't require the new functionality. | ||
| * | ||
| * @implNote There are no guarantees about how often this method is called. | ||
| * Therefore, implementations should be idempotent and avoid side | ||
| * effects. They may, however, cache the result for performance in | ||
| * the {@link ExtensionContext.Store Store} of the supplied | ||
| * {@link ExtensionContext}, if necessary. | ||
| * @param rootContext the root extension context to allow inspection of | ||
| * configuration parameters; never {@code null} | ||
| * @since 5.12 | ||
| */ | ||
| @API(status = EXPERIMENTAL, since = "5.12") | ||
| default ExtensionContextScope getExtensionContextScopeDuringTestClassInstanceConstruction( | ||
marcphilipp marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ExtensionContext rootContext) { | ||
marcphilipp marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return ExtensionContextScope.DEFAULT; | ||
| } | ||
|
|
||
| /** | ||
| * {@code ExtensionContextScope} is used to define the scope of the | ||
| * {@link ExtensionContext} passed to an extension during the construction | ||
| * of test class instances. | ||
| * | ||
| * @since 5.12 | ||
| * @see TestClassInstanceConstructionParticipatingExtension#getExtensionContextScopeDuringTestClassInstanceConstruction | ||
| */ | ||
| @API(status = EXPERIMENTAL, since = "5.12") | ||
| enum ExtensionContextScope { | ||
marcphilipp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * The extension should receive an {@link ExtensionContext} scoped to | ||
| * the test class. | ||
| * | ||
| * @deprecated This behavior will be removed from future versions of | ||
| * JUnit and {@link #TEST_METHOD} will become the default. | ||
| */ | ||
| @API(status = DEPRECATED, since = "5.12") // | ||
| @Deprecated | ||
| DEFAULT, | ||
|
|
||
| /** | ||
| * The extension should receive an {@link ExtensionContext} scoped to | ||
| * the test method, unless the | ||
| * {@link TestInstance.Lifecycle#PER_CLASS PER_CLASS} lifecycle is used. | ||
| */ | ||
| TEST_METHOD | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.