Debian Codegraph @

junit-jupiter-api/src/main/java/org/junit/jupiter/api/extension/TestInstancePostProcessor.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.STABLE;
14
15 import org.apiguardian.api.API;
16
17 /**
18 * {@code TestInstancePostProcessor} defines the API for {@link Extension
19 * Extensions} that wish to <em>post-process</em> test instances.
20 *
21 * <p>Common use cases include injecting dependencies into the test
22 * instance, invoking custom initialization methods on the test instance,
23 * etc.
24 *
25 * <p>Extensions that implement {@code TestInstancePostProcessor} must be
26 * registered at the class level.
27 *
28 * <h2>Constructor Requirements</h2>
29 *
30 * <p>Consult the documentation in {@link Extension} for details on
31 * constructor requirements.
32 *
33 * @since 5.0
34 * @see #postProcessTestInstance(Object, ExtensionContext)
35 * @see TestInstancePreDestroyCallback
36 * @see TestInstanceFactory
37 * @see ParameterResolver
38 */
39 @FunctionalInterface
40 @API(status = STABLE, since = "5.0")
41 public interface TestInstancePostProcessor extends Extension {
42
43 /**
44 * Callback for post-processing the supplied test instance.
45 *
46 * <p><strong>Note</strong>: the {@code ExtensionContext} supplied to a
47 * {@code TestInstancePostProcessor} will always return an empty
48 * {@link java.util.Optional} value from {@link ExtensionContext#getTestInstance()
49 * getTestInstance()}. A {@code TestInstancePostProcessor} should therefore
50 * only attempt to process the supplied {@code testInstance}.
51 *
52 * @param testInstance the instance to post-process; never {@code null}
53 * @param context the current extension context; never {@code null}
54 */
55 void postProcessTestInstance(Object testInstance, ExtensionContext context) throws Exception;
56
57 }