-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce DynamicTests generators for Named<Executable> (#3720)
Introduce two methods in `DynamicTest` to generate a `Stream` of `DynamicTest` from a `Stream`/`Iterator` of `Named<Executable>`. The new `NamedExecutable` interface provides default implementations of `getName()` and `getPayload()` so only `execute()` has to be implemented and is particularly well-suited to be implemented by a Java record class. Resolves #3261. --------- Co-authored-by: Marc Philipp <[email protected]>
- Loading branch information
1 parent
8e8268c
commit 6828a79
Showing
5 changed files
with
195 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
junit-jupiter-api/src/main/java/org/junit/jupiter/api/NamedExecutable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* 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.EXPERIMENTAL; | ||
|
||
import java.util.Iterator; | ||
import java.util.stream.Stream; | ||
|
||
import org.apiguardian.api.API; | ||
import org.junit.jupiter.api.function.Executable; | ||
|
||
/** | ||
* {@code NamedExecutable} joins {@code Executable} and {@code Named} in a | ||
* one self-typed functional interface. | ||
* | ||
* <p>The default implementation of {@link #getName()} returns the result of | ||
* calling {@link Object#toString()} on the implementing instance but may be | ||
* overridden by concrete implementations to provide a more meaningful name. | ||
* | ||
* <p>On Java 16 or later, it is recommended to implement this interface using | ||
* a record type. | ||
* | ||
* @since 5.11 | ||
* @see DynamicTest#stream(Stream) | ||
* @see DynamicTest#stream(Iterator) | ||
*/ | ||
@FunctionalInterface | ||
@API(status = EXPERIMENTAL, since = "5.11") | ||
public interface NamedExecutable extends Named<Executable>, Executable { | ||
@Override | ||
default String getName() { | ||
return toString(); | ||
} | ||
|
||
@Override | ||
default Executable getPayload() { | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters