-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add List-based support to Arguments API #4574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
3f3aa29
d566f95
b73ae11
87ca6b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -13,6 +13,10 @@ | |||||||||||||
| import static org.apiguardian.api.API.Status.EXPERIMENTAL; | ||||||||||||||
| import static org.apiguardian.api.API.Status.STABLE; | ||||||||||||||
|
|
||||||||||||||
| import java.util.ArrayList; | ||||||||||||||
| import java.util.Arrays; | ||||||||||||||
| import java.util.List; | ||||||||||||||
|
|
||||||||||||||
| import org.apiguardian.api.API; | ||||||||||||||
| import org.jspecify.annotations.Nullable; | ||||||||||||||
| import org.junit.platform.commons.util.Preconditions; | ||||||||||||||
|
|
@@ -172,4 +176,72 @@ public String toString() { | |||||||||||||
|
|
||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
| * Factory method for creating an instance of {@code Arguments} based on | ||||||||||||||
| * the supplied {@code arguments} as a {@link List}. | ||||||||||||||
|
||||||||||||||
| * the supplied {@code arguments} as a {@link List}. | |
| * the supplied {@link List} of {@code arguments}. |
(same below for other methods)
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * @param arguments the arguments as a List to be used for an invocation | |
| * of the test method; must not be {@code null} but may contain {@code null} | |
| * @param arguments the arguments to be used for an invocation of the test | |
| * method; must not be {@code null} but may contain {@code null} |
(same below for other methods)
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| static Arguments of(@Nullable List<@Nullable Object> arguments) { | |
| if (arguments == null) { | |
| return of((Object) null); // Properly wrap null | |
| } | |
| static Arguments of(List<@Nullable Object> arguments) { | |
| Preconditions.notNull(arguments, "arguments must not be null"); |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (arguments.isEmpty()) { | |
| // Must still return empty arguments array | |
| return of(new Object[0]); | |
| } | |
| return () -> arguments.toArray(new Object[0]); | |
| return of(arguments.toArray()); |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return new ArgumentSet(name, arguments.toArray(new Object[0])); | |
| return new ArgumentSet(name, arguments.toArray()); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,7 +57,7 @@ public Stream<? extends Arguments> provideArguments(ParameterDeclarations parame | |
| return Stream.of(arguments(Collections.emptySet())); | ||
| } | ||
| if (List.class.equals(parameterType)) { | ||
| return Stream.of(arguments(Collections.emptyList())); | ||
| return Stream.of(Arguments.of((Object) Collections.emptyList())); | ||
|
||
| } | ||
| if (Set.class.equals(parameterType)) { | ||
| return Stream.of(arguments(Collections.emptySet())); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -15,7 +15,11 @@ | |||||
| import static org.junit.jupiter.params.provider.Arguments.arguments; | ||||||
| import static org.junit.jupiter.params.provider.Arguments.of; | ||||||
|
|
||||||
| import java.util.Arrays; | ||||||
| import java.util.List; | ||||||
|
|
||||||
| import org.junit.jupiter.api.Test; | ||||||
| import org.junit.jupiter.params.provider.Arguments.ArgumentSet; | ||||||
|
|
||||||
| /** | ||||||
| * Unit tests for {@link Arguments}. | ||||||
|
|
@@ -56,4 +60,50 @@ void argumentsReturnsSameArrayUsedForCreating() { | |||||
| assertThat(arguments.get()).isSameAs(input); | ||||||
| } | ||||||
|
|
||||||
| @Test | ||||||
| void ofSupportsList() { | ||||||
|
||||||
| void ofSupportsList() { | |
| void fromSupportsList() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add an assertion verifying that modifying the initial List has no effect on arguments
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| void argumentsSupportsListAlias() { | |
| void argumentsFromSupportsList() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also verify that the array in arguments can't be modified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move these next to the other
staticfactory methods above.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion! I'll move the method next to the other static factory methods to keep things consistent.