Debian Codegraph @

junit-jupiter-api/src/main/java/org/junit/jupiter/api/DynamicNode.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;
12
13 import static org.apiguardian.api.API.Status.MAINTAINED;
14
15 import java.net.URI;
16 import java.util.Optional;
17
18 import org.apiguardian.api.API;
19 import org.junit.platform.commons.util.Preconditions;
20 import org.junit.platform.commons.util.ToStringBuilder;
21
22 /**
23 * {@code DynamicNode} serves as the abstract base class for a container or a
24 * test case generated at runtime.
25 *
26 * @since 5.0
27 * @see DynamicTest
28 * @see DynamicContainer
29 */
30 @API(status = MAINTAINED, since = "5.3")
31 public abstract class DynamicNode {
32
33 private final String displayName;
34
35 /** Custom test source {@link URI} associated with this node; potentially {@code null}. */
36 private final URI testSourceUri;
37
38 DynamicNode(String displayName, URI testSourceUri) {
39 this.displayName = Preconditions.notBlank(displayName, "displayName must not be null or blank");
40 this.testSourceUri = testSourceUri;
41 }
42
43 /**
44 * Get the display name of this {@code DynamicNode}.
45 *
46 * @return the display name
47 */
48 public String getDisplayName() {
49 return this.displayName;
50 }
51
52 /**
53 * Get the custom test source {@link URI} of this {@code DynamicNode}.
54 *
55 * @return an {@code Optional} containing the custom test source {@link URI};
56 * never {@code null} but potentially empty
57 * @since 5.3
58 */
59 public Optional<URI> getTestSourceUri() {
60 return Optional.ofNullable(testSourceUri);
61 }
62
63 @Override
64 public String toString() {
65 return new ToStringBuilder(this) //
66 .append("displayName", displayName) //
67 .append("testSourceUri", testSourceUri) //
68 .toString();
69 }
70
71 }