Skip to content

Commit e3c5383

Browse files
committed
Rename to TestInstantiationAwareExtension
1 parent 0da53ce commit e3c5383

File tree

14 files changed

+64
-73
lines changed

14 files changed

+64
-73
lines changed

documentation/src/docs/asciidoc/release-notes/release-notes-5.12.0-M1.adoc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@ JUnit repository on GitHub.
5858
extensions.
5959
* Allow determining "shared resources" at runtime via the new `@ResourceLock#providers`
6060
attribute that accepts implementations of `ResourceLocksProvider`.
61-
* Extensions that participate in the construction of test class instances may override the
62-
`getExtensionContextScopeDuringTestClassInstanceConstruction()` method to enable using a
63-
test-scoped `ExtensionContext` in `Extension` methods called during test class instance
64-
construction. This behavior will become the default in future versions of JUnit.
61+
* Extensions that implement `TestInstancePreConstructCallback`, `TestInstanceFactory`,
62+
`TestInstancePostProcessor`, `ParameterResolver`, or `InvocationInterceptor` may
63+
override the `getTestInstantiationExtensionContextScope()` method to enable receiving
64+
a test-scoped `ExtensionContext` in `Extension` methods called during test class
65+
instantiation. This behavior will become the default in future versions of JUnit.
6566
* `@TempDir` is now supported on test class constructors.
6667

6768

documentation/src/docs/asciidoc/user-guide/extensions.adoc

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,7 @@ instances and their lifecycle.
383383

384384
[NOTE]
385385
====
386-
You may override the
387-
`getExtensionContextScopeDuringTestClassInstanceConstruction(...)` method to return
386+
You may override the `getTestInstantiationExtensionContextScope(...)` method to return
388387
`TEST_SCOPED` for revised handling of `CloseableResource` and to make test-specific data
389388
available to your implementation.
390389
====
@@ -417,8 +416,7 @@ registered for any specific test class.
417416

418417
[NOTE]
419418
====
420-
You may override the
421-
`getExtensionContextScopeDuringTestClassInstanceConstruction(...)` method to return
419+
You may override the `getTestInstantiationExtensionContextScope(...)` method to return
422420
`TEST_SCOPED` for revised handling of `CloseableResource` and to make test-specific data
423421
available to your implementation.
424422
====
@@ -437,8 +435,7 @@ For a concrete example, consult the source code for the `{MockitoExtension}` and
437435

438436
[NOTE]
439437
====
440-
You may override the
441-
`getExtensionContextScopeDuringTestClassInstanceConstruction(...)` method to return
438+
You may override the `getTestInstantiationExtensionContextScope(...)` method to return
442439
`TEST_SCOPED` for revised handling of `CloseableResource` and to make test-specific data
443440
available to your implementation.
444441
====
@@ -491,8 +488,7 @@ those provided in `java.lang.reflect.Parameter` in order to avoid this bug in th
491488

492489
[NOTE]
493490
====
494-
You may override the
495-
`getExtensionContextScopeDuringTestClassInstanceConstruction(...)` method to return
491+
You may override the `getTestInstantiationExtensionContextScope(...)` method to return
496492
`TEST_SCOPED` to support injecting test specific data into constructor parameters of the
497493
test class instance. Doing so causes a test-specific `{ExtensionContext}` to be used while
498494
resolving constructor parameters, unless the
@@ -731,8 +727,7 @@ include::{testDir}/example/interceptor/SwingEdtInterceptor.java[tags=user_guide]
731727

732728
[NOTE]
733729
====
734-
You may override the
735-
`getExtensionContextScopeDuringTestClassInstanceConstruction(...)` method to return
730+
You may override the `getTestInstantiationExtensionContextScope(...)` method to return
736731
`TEST_SCOPED` to make test-specific data available to your implementation of
737732
`interceptTestClassConstructor` and for a revised scope of the provided `Store` instance.
738733
====

junit-jupiter-api/src/main/java/org/junit/jupiter/api/extension/InvocationInterceptor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
* @see ExtensionContext
5252
*/
5353
@API(status = STABLE, since = "5.10")
54-
public interface InvocationInterceptor extends TestClassInstanceConstructionParticipatingExtension {
54+
public interface InvocationInterceptor extends TestInstantiationAwareExtension {
5555

5656
/**
5757
* Intercept the invocation of a test class constructor.
@@ -60,7 +60,7 @@ public interface InvocationInterceptor extends TestClassInstanceConstructionPart
6060
* (static initialization) when this method is invoked.
6161
*
6262
* <p>Extensions may override
63-
* {@link #getExtensionContextScopeDuringTestClassInstanceConstruction} to
63+
* {@link #getTestInstantiationExtensionContextScope} to
6464
* make test-specific data available to the implementation of this method
6565
* and for a revised scope of the provided {@link Store Store} instance.
6666
*

junit-jupiter-api/src/main/java/org/junit/jupiter/api/extension/ParameterResolver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* {@code ParameterResolver}.
3333
*
3434
* <p>Extensions may override
35-
* {@link #getExtensionContextScopeDuringTestClassInstanceConstruction} to
35+
* {@link #getTestInstantiationExtensionContextScope} to
3636
* support injecting test specific data into constructor parameters of the test
3737
* class instance. Returning
3838
* {@link ExtensionContextScope#TEST_METHOD TEST_SCOPED} from this method,
@@ -54,7 +54,7 @@
5454
* @see TestInstancePreDestroyCallback
5555
*/
5656
@API(status = STABLE, since = "5.0")
57-
public interface ParameterResolver extends TestClassInstanceConstructionParticipatingExtension {
57+
public interface ParameterResolver extends TestInstantiationAwareExtension {
5858

5959
/**
6060
* Determine if this resolver supports resolution of an argument for the

junit-jupiter-api/src/main/java/org/junit/jupiter/api/extension/TestInstanceFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@
5252
*/
5353
@FunctionalInterface
5454
@API(status = STABLE, since = "5.7")
55-
public interface TestInstanceFactory extends TestClassInstanceConstructionParticipatingExtension {
55+
public interface TestInstanceFactory extends TestInstantiationAwareExtension {
5656

5757
/**
5858
* Callback for creating a test instance for the supplied context.
5959
*
6060
* <p>Extensions may override
61-
* {@link #getExtensionContextScopeDuringTestClassInstanceConstruction} for
61+
* {@link #getTestInstantiationExtensionContextScope} for
6262
* revised handling of {@link CloseableResource CloseableResource} and to
6363
* make test-specific data available to your implementation.
6464
*

junit-jupiter-api/src/main/java/org/junit/jupiter/api/extension/TestInstancePostProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@
4141
*/
4242
@FunctionalInterface
4343
@API(status = STABLE, since = "5.0")
44-
public interface TestInstancePostProcessor extends TestClassInstanceConstructionParticipatingExtension {
44+
public interface TestInstancePostProcessor extends TestInstantiationAwareExtension {
4545

4646
/**
4747
* Callback for post-processing the supplied test instance.
4848
*
4949
* <p>Extensions may override
50-
* {@link #getExtensionContextScopeDuringTestClassInstanceConstruction} for
50+
* {@link #getTestInstantiationExtensionContextScope} for
5151
* revised handling of {@link CloseableResource CloseableResource} and to
5252
* make test-specific data available to your implementation.
5353
*

junit-jupiter-api/src/main/java/org/junit/jupiter/api/extension/TestInstancePreConstructCallback.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@
4444
*/
4545
@FunctionalInterface
4646
@API(status = STABLE, since = "5.11")
47-
public interface TestInstancePreConstructCallback extends TestClassInstanceConstructionParticipatingExtension {
47+
public interface TestInstancePreConstructCallback extends TestInstantiationAwareExtension {
4848

4949
/**
5050
* Callback invoked prior to test instances being constructed.
5151
*
5252
* <p>Extensions may override
53-
* {@link #getExtensionContextScopeDuringTestClassInstanceConstruction} to
53+
* {@link #getTestInstantiationExtensionContextScope} to
5454
* make test-specific data available to the implementation of this method
5555
* and for a revised scope of the provided
5656
* {@link ExtensionContext.Store Store} instance.
Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,15 @@
1515

1616
import org.apiguardian.api.API;
1717
import org.junit.jupiter.api.TestInstance;
18+
import org.junit.jupiter.api.extension.ExtensionContext.Store;
19+
import org.junit.jupiter.api.extension.ExtensionContext.Store.CloseableResource;
1820

1921
/**
20-
* Interface for {@link Extension Extensions} that participate in the
21-
* construction of test class instances.
22+
* Interface for {@link Extension Extensions} that are aware and can influence
23+
* the instantiation of test instances.
24+
*
25+
* <p>This interface is not indented to be implemented directly. Instead, extend
26+
* one of its sub-interfaces.
2227
*
2328
* @since 5.12
2429
* @see InvocationInterceptor#interceptTestClassConstructor
@@ -28,14 +33,14 @@
2833
* @see TestInstanceFactory
2934
*/
3035
@API(status = EXPERIMENTAL, since = "5.12")
31-
public interface TestClassInstanceConstructionParticipatingExtension extends Extension {
36+
public interface TestInstantiationAwareExtension extends Extension {
3237

3338
/**
3439
* Whether this extension should receive a test-scoped
35-
* {@link ExtensionContext} during the creation of test instances.
40+
* {@link ExtensionContext} during the instantiation of test instances.
3641
*
3742
* <p>If an extension returns
38-
* {@link ExtensionContextScope#TEST_METHOD TEST_SCOPED} from this method,
43+
* {@link ExtensionContextScope#TEST_METHOD TEST_METHOD} from this method,
3944
* the following extension methods will be called with a test-scoped
4045
* {@link ExtensionContext} instead of a class-scoped one, unless the
4146
* {@link TestInstance.Lifecycle#PER_CLASS PER_CLASS} lifecycle is used:
@@ -57,45 +62,44 @@ public interface TestClassInstanceConstructionParticipatingExtension extends Ext
5762
* may refer to a nested test class.
5863
* Use {@link TestInstanceFactoryContext#getTestClass()} to get the class
5964
* under construction.</li>
60-
* <li>{@link ExtensionContext#getTestMethod() getTestMethod()} is no-longer
61-
* empty, unless the test class is annotated with
62-
* {@link TestInstance @TestInstance(Lifecycle.PER_CLASS)}.</li>
63-
* <li>If the callback adds a new {@link ExtensionContext.Store.CloseableResource} to the
64-
* {@link ExtensionContext.Store}, the resource is closed just after the instance is
65+
* <li>{@link ExtensionContext#getTestMethod() getTestMethod()} is no longer
66+
* empty, unless the {@link TestInstance.Lifecycle#PER_CLASS PER_CLASS}
67+
* lifecycle is used.</li>
68+
* <li>If the callback adds a new {@link CloseableResource} to the
69+
* {@link Store Store}, the resource is closed just after the instance is
6570
* destroyed.</li>
6671
* <li>The callbacks can now access data previously stored by
67-
* {@link TestTemplateInvocationContext}, unless the test class is annotated
68-
* with {@link TestInstance @TestInstance(Lifecycle.PER_CLASS)}.</li>
72+
* {@link TestTemplateInvocationContext}, unless the
73+
* {@link TestInstance.Lifecycle#PER_CLASS PER_CLASS} lifecycle is used.</li>
6974
* </ul>
7075
*
7176
* <p><strong>Note</strong>: The behavior which is enabled by returning
72-
* {@link ExtensionContextScope#TEST_METHOD TEST_SCOPED} from this method
73-
* will become the default in future versions of JUnit. To ensure future
77+
* {@link ExtensionContextScope#TEST_METHOD TEST_METHOD} from this method
78+
* will become the default in future versions of JUnit. To ensure forward
7479
* compatibility, extension implementors are therefore advised to opt in,
7580
* even if they don't require the new functionality.
7681
*
7782
* @implNote There are no guarantees about how often this method is called.
7883
* Therefore, implementations should be idempotent and avoid side
7984
* effects. They may, however, cache the result for performance in
80-
* the {@link ExtensionContext.Store Store} of the supplied
85+
* the {@link Store Store} of the supplied
8186
* {@link ExtensionContext}, if necessary.
8287
* @param rootContext the root extension context to allow inspection of
8388
* configuration parameters; never {@code null}
8489
* @since 5.12
8590
*/
8691
@API(status = EXPERIMENTAL, since = "5.12")
87-
default ExtensionContextScope getExtensionContextScopeDuringTestClassInstanceConstruction(
88-
ExtensionContext rootContext) {
92+
default ExtensionContextScope getTestInstantiationExtensionContextScope(ExtensionContext rootContext) {
8993
return ExtensionContextScope.DEFAULT;
9094
}
9195

9296
/**
9397
* {@code ExtensionContextScope} is used to define the scope of the
94-
* {@link ExtensionContext} passed to an extension during the construction
95-
* of test class instances.
98+
* {@link ExtensionContext} passed to an extension during the instantiation
99+
* of test instances.
96100
*
97101
* @since 5.12
98-
* @see TestClassInstanceConstructionParticipatingExtension#getExtensionContextScopeDuringTestClassInstanceConstruction
102+
* @see TestInstantiationAwareExtension#getTestInstantiationExtensionContextScope
99103
*/
100104
@API(status = EXPERIMENTAL, since = "5.12")
101105
enum ExtensionContextScope {

junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/execution/ExtensionContextSupplier.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@
1111
package org.junit.jupiter.engine.execution;
1212

1313
import static org.apiguardian.api.API.Status.INTERNAL;
14-
import static org.junit.jupiter.api.extension.TestClassInstanceConstructionParticipatingExtension.ExtensionContextScope.TEST_METHOD;
14+
import static org.junit.jupiter.api.extension.TestInstantiationAwareExtension.ExtensionContextScope.TEST_METHOD;
1515

1616
import org.apiguardian.api.API;
1717
import org.junit.jupiter.api.extension.ExtensionContext;
18-
import org.junit.jupiter.api.extension.TestClassInstanceConstructionParticipatingExtension;
18+
import org.junit.jupiter.api.extension.TestInstantiationAwareExtension;
1919

2020
/**
2121
* Container of two instances of {@link ExtensionContext} to simplify the legacy for
2222
* <a href="https://github.com/junit-team/junit5/issues/3445">#3445</a>.
2323
*
2424
* @since 5.12
25-
* @see TestClassInstanceConstructionParticipatingExtension
25+
* @see TestInstantiationAwareExtension
2626
*/
2727
@API(status = INTERNAL, since = "5.12")
2828
public final class ExtensionContextSupplier {
@@ -35,7 +35,7 @@ public ExtensionContextSupplier(ExtensionContext currentExtensionContext, Extens
3535
this.legacyExtensionContext = legacyExtensionContext;
3636
}
3737

38-
public ExtensionContext get(TestClassInstanceConstructionParticipatingExtension extension) {
38+
public ExtensionContext get(TestInstantiationAwareExtension extension) {
3939
if (currentExtensionContext == legacyExtensionContext || isTestScoped(extension)) {
4040
return currentExtensionContext;
4141
}
@@ -44,8 +44,8 @@ public ExtensionContext get(TestClassInstanceConstructionParticipatingExtension
4444
}
4545
}
4646

47-
private boolean isTestScoped(TestClassInstanceConstructionParticipatingExtension extension) {
47+
private boolean isTestScoped(TestInstantiationAwareExtension extension) {
4848
ExtensionContext rootContext = currentExtensionContext.getRoot();
49-
return extension.getExtensionContextScopeDuringTestClassInstanceConstruction(rootContext) == TEST_METHOD;
49+
return extension.getTestInstantiationExtensionContextScope(rootContext) == TEST_METHOD;
5050
}
5151
}

junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/TempDirectory.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import static java.nio.file.FileVisitResult.CONTINUE;
1414
import static java.util.stream.Collectors.joining;
15-
import static org.junit.jupiter.api.extension.TestClassInstanceConstructionParticipatingExtension.ExtensionContextScope.TEST_METHOD;
15+
import static org.junit.jupiter.api.extension.TestInstantiationAwareExtension.ExtensionContextScope.TEST_METHOD;
1616
import static org.junit.jupiter.api.io.CleanupMode.DEFAULT;
1717
import static org.junit.jupiter.api.io.CleanupMode.NEVER;
1818
import static org.junit.jupiter.api.io.CleanupMode.ON_SUCCESS;
@@ -94,8 +94,7 @@ public TempDirectory(JupiterConfiguration configuration) {
9494
}
9595

9696
@Override
97-
public ExtensionContextScope getExtensionContextScopeDuringTestClassInstanceConstruction(
98-
ExtensionContext rootContext) {
97+
public ExtensionContextScope getTestInstantiationExtensionContextScope(ExtensionContext rootContext) {
9998
return TEST_METHOD;
10099
}
101100

jupiter-tests/src/test/java/org/junit/jupiter/api/extension/KitchenSinkExtension.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,10 @@ public class KitchenSinkExtension implements
6565
// @formatter:on
6666
{
6767

68-
// --- Test Class Instance Construction ------------------------------------
68+
// --- Test Class Instantiation --------------------------------------------
6969

7070
@Override
71-
public ExtensionContextScope getExtensionContextScopeDuringTestClassInstanceConstruction(
72-
ExtensionContext rootContext) {
71+
public ExtensionContextScope getTestInstantiationExtensionContextScope(ExtensionContext rootContext) {
7372
return ExtensionContextScope.TEST_METHOD;
7473
}
7574

jupiter-tests/src/test/java/org/junit/jupiter/engine/extension/TestInstanceFactoryTests.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import static org.assertj.core.api.Assertions.assertThat;
1414
import static org.junit.jupiter.api.Assertions.assertEquals;
1515
import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;
16-
import static org.junit.jupiter.api.extension.TestClassInstanceConstructionParticipatingExtension.ExtensionContextScope.TEST_METHOD;
16+
import static org.junit.jupiter.api.extension.TestInstantiationAwareExtension.ExtensionContextScope.TEST_METHOD;
1717
import static org.junit.platform.commons.util.ClassUtils.nullSafeToString;
1818
import static org.junit.platform.testkit.engine.EventConditions.container;
1919
import static org.junit.platform.testkit.engine.EventConditions.engine;
@@ -723,16 +723,14 @@ public Object createTestInstance(TestInstanceFactoryContext factoryContext, Exte
723723

724724
private static class FooInstanceFactory extends AbstractTestInstanceFactory {
725725
@Override
726-
public ExtensionContextScope getExtensionContextScopeDuringTestClassInstanceConstruction(
727-
ExtensionContext rootContext) {
726+
public ExtensionContextScope getTestInstantiationExtensionContextScope(ExtensionContext rootContext) {
728727
return TEST_METHOD;
729728
}
730729
}
731730

732731
private static class BarInstanceFactory extends AbstractTestInstanceFactory {
733732
@Override
734-
public ExtensionContextScope getExtensionContextScopeDuringTestClassInstanceConstruction(
735-
ExtensionContext rootContext) {
733+
public ExtensionContextScope getTestInstantiationExtensionContextScope(ExtensionContext rootContext) {
736734
return TEST_METHOD;
737735
}
738736
}

jupiter-tests/src/test/java/org/junit/jupiter/engine/extension/TestInstancePostProcessorTests.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import static org.assertj.core.api.Assertions.assertThat;
1414
import static org.junit.jupiter.api.Assertions.assertEquals;
15-
import static org.junit.jupiter.api.extension.TestClassInstanceConstructionParticipatingExtension.ExtensionContextScope.TEST_METHOD;
15+
import static org.junit.jupiter.api.extension.TestInstantiationAwareExtension.ExtensionContextScope.TEST_METHOD;
1616

1717
import java.util.ArrayList;
1818
import java.util.HashMap;
@@ -206,8 +206,7 @@ static class FooInstancePostProcessor extends AbstractInstancePostProcessor {
206206
}
207207

208208
@Override
209-
public ExtensionContextScope getExtensionContextScopeDuringTestClassInstanceConstruction(
210-
ExtensionContext rootContext) {
209+
public ExtensionContextScope getTestInstantiationExtensionContextScope(ExtensionContext rootContext) {
211210
return TEST_METHOD;
212211
}
213212
}
@@ -218,8 +217,7 @@ static class BarInstancePostProcessor extends AbstractInstancePostProcessor {
218217
}
219218

220219
@Override
221-
public ExtensionContextScope getExtensionContextScopeDuringTestClassInstanceConstruction(
222-
ExtensionContext rootContext) {
220+
public ExtensionContextScope getTestInstantiationExtensionContextScope(ExtensionContext rootContext) {
223221
return TEST_METHOD;
224222
}
225223
}

0 commit comments

Comments
 (0)