Debian Codegraph @

junit-jupiter-api/src/main/java/org/junit/jupiter/api/extension/TestTemplateInvocationContext.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 java.util.Collections.emptyList;
14 import static org.apiguardian.api.API.Status.STABLE;
15
16 import java.util.List;
17
18 import org.apiguardian.api.API;
19
20 /**
21 * {@code TestTemplateInvocationContext} represents the <em>context</em> of a
22 * single invocation of a {@linkplain org.junit.jupiter.api.TestTemplate test
23 * template}.
24 *
25 * <p>Each context is provided by a {@link TestTemplateInvocationContextProvider}.
26 *
27 * @since 5.0
28 * @see org.junit.jupiter.api.TestTemplate
29 * @see TestTemplateInvocationContextProvider
30 */
31 @API(status = STABLE, since = "5.0")
32 public interface TestTemplateInvocationContext {
33
34 /**
35 * Get the display name for this invocation.
36 *
37 * <p>The supplied {@code invocationIndex} is incremented by the framework
38 * with each test invocation. Thus, in the case of multiple active
39 * {@linkplain TestTemplateInvocationContextProvider providers}, only the
40 * first active provider receives indices starting with {@code 1}.
41 *
42 * <p>The default implementation returns the supplied {@code invocationIndex}
43 * wrapped in brackets &mdash; for example, {@code [1]}, {@code [42]}, etc.
44 *
45 * @param invocationIndex the index of this invocation (1-based).
46 * @return the display name for this invocation; never {@code null} or blank
47 */
48 default String getDisplayName(int invocationIndex) {
49 return "[" + invocationIndex + "]";
50 }
51
52 /**
53 * Get the additional {@linkplain Extension extensions} for this invocation.
54 *
55 * <p>The extensions provided by this method will only be used for this
56 * invocation of the test template. Thus, it does not make sense to return
57 * an extension that acts solely on the container level (e.g.
58 * {@link BeforeAllCallback}).
59 *
60 * <p>The default implementation returns an empty list.
61 *
62 * @return the additional extensions for this invocation; never {@code null}
63 * or containing {@code null} elements, but potentially empty
64 */
65 default List<Extension> getAdditionalExtensions() {
66 return emptyList();
67 }
68
69 }