junit-jupiter-api/src/main/java/org/junit/jupiter/api/extension/TestInstancePreConstructCallback.java
raw symbols SCIP| 1 | /* |
| 2 | * Copyright 2015-2024 the original author or authors. |
| 3 | * |
| 4 | * All rights reserved. This program and the accompanying materials are |
| 5 | * made available under the terms of the Eclipse Public License v2.0 which |
| 6 | * accompanies this distribution and is available at |
| 7 | * |
| 8 | * https://www.eclipse.org/legal/epl-v20.html |
| 9 | */ |
| 10 | |
| 11 | package org.junit.jupiter.api.extension; |
| 12 | |
| 13 | import static org.apiguardian.api.API.Status.EXPERIMENTAL; |
| 14 | |
| 15 | import org.apiguardian.api.API; |
| 16 | import org.junit.jupiter.api.TestInstance.Lifecycle; |
| 17 | |
| 18 | /** |
| 19 | * {@code TestInstancePreConstructCallback} defines the API for {@link Extension |
| 20 | * Extensions} that wish to be invoked <em>prior</em> to creation of test instances. |
| 21 | * |
| 22 | * <p>This extension is a symmetric counterpart to {@link TestInstancePreDestroyCallback}. |
| 23 | * The use cases for this extension may include preparing context-sensitive arguments |
| 24 | * that are injected into the instance's constructor. |
| 25 | * |
| 26 | * <p>Extensions that implement {@code TestInstancePreConstructCallback} must be |
| 27 | * registered at the class level if the test class is configured with |
| 28 | * {@link Lifecycle @TestInstance(Lifecycle.PER_CLASS)} semantics. If the test |
| 29 | * class is configured with |
| 30 | * {@link Lifecycle @TestInstance(Lifecycle.PER_METHOD)} semantics, |
| 31 | * {@code TestInstancePreConstructCallback} extensions may be registered at the |
| 32 | * class level or at the method level. In the latter case, the extension will |
| 33 | * only be applied to the test method for which it is registered. |
| 34 | * |
| 35 | * <h2>Constructor Requirements</h2> |
| 36 | * |
| 37 | * <p>Consult the documentation in {@link Extension} for details on constructor |
| 38 | * requirements. |
| 39 | * |
| 40 | * @since 5.9 |
| 41 | * @see TestInstancePreDestroyCallback |
| 42 | * @see TestInstanceFactory |
| 43 | * @see ParameterResolver |
| 44 | */ |
| 45 | @FunctionalInterface |
| 46 | @API(status = EXPERIMENTAL, since = "5.9") |
| 47 | public interface TestInstancePreConstructCallback extends Extension { |
| 48 | |
| 49 | /** |
| 50 | * Callback invoked prior to test instances being constructed. |
| 51 | * |
| 52 | * @param factoryContext the context for the test instance about to be instantiated; |
| 53 | * never {@code null} |
| 54 | * @param context the current extension context; never {@code null} |
| 55 | */ |
| 56 | void preConstructTestInstance(TestInstanceFactoryContext factoryContext, ExtensionContext context) throws Exception; |
| 57 | |
| 58 | } |