/
DynamicNode.java
71 lines (59 loc) · 1.84 KB
/
DynamicNode.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* Copyright 2015-2024 the original author or authors.
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v2.0 which
* accompanies this distribution and is available at
*
* https://www.eclipse.org/legal/epl-v20.html
*/
package org.junit.jupiter.api;
import static org.apiguardian.api.API.Status.MAINTAINED;
import java.net.URI;
import java.util.Optional;
import org.apiguardian.api.API;
import org.junit.platform.commons.util.Preconditions;
import org.junit.platform.commons.util.ToStringBuilder;
/**
* {@code DynamicNode} serves as the abstract base class for a container or a
* test case generated at runtime.
*
* @since 5.0
* @see DynamicTest
* @see DynamicContainer
*/
@API(status = MAINTAINED, since = "5.3")
public abstract class DynamicNode {
private final String displayName;
/** Custom test source {@link URI} associated with this node; potentially {@code null}. */
private final URI testSourceUri;
DynamicNode(String displayName, URI testSourceUri) {
this.displayName = Preconditions.notBlank(displayName, "displayName must not be null or blank");
this.testSourceUri = testSourceUri;
}
/**
* Get the display name of this {@code DynamicNode}.
*
* @return the display name
*/
public String getDisplayName() {
return this.displayName;
}
/**
* Get the custom test source {@link URI} of this {@code DynamicNode}.
*
* @return an {@code Optional} containing the custom test source {@link URI};
* never {@code null} but potentially empty
* @since 5.3
*/
public Optional<URI> getTestSourceUri() {
return Optional.ofNullable(testSourceUri);
}
@Override
public String toString() {
return new ToStringBuilder(this) //
.append("displayName", displayName) //
.append("testSourceUri", testSourceUri) //
.toString();
}
}