|
13 | 13 | import static org.apiguardian.api.API.Status.EXPERIMENTAL;
|
14 | 14 | import static org.apiguardian.api.API.Status.STABLE;
|
15 | 15 |
|
| 16 | +import java.util.ArrayList; |
| 17 | +import java.util.List; |
| 18 | + |
16 | 19 | import org.apiguardian.api.API;
|
17 | 20 | import org.jspecify.annotations.Nullable;
|
18 | 21 | import org.junit.platform.commons.util.Preconditions;
|
@@ -172,4 +175,66 @@ public String toString() {
|
172 | 175 |
|
173 | 176 | }
|
174 | 177 |
|
| 178 | + /** |
| 179 | + * Factory method for creating an instance of {@code Arguments} based on |
| 180 | + * the supplied {@code arguments} as a {@link List}. |
| 181 | + * |
| 182 | + * @param arguments the arguments as a List to be used for an invocation |
| 183 | + * of the test method; must not be {@code null} but may contain {@code null} |
| 184 | + * @return an instance of {@code Arguments}; never {@code null} |
| 185 | + * @see #arguments(List) |
| 186 | + */ |
| 187 | + @API(status = EXPERIMENTAL, since = "6.0") |
| 188 | + static Arguments of(List<@Nullable Object> arguments) { |
| 189 | + Preconditions.notNull(arguments, "arguments list must not be null"); |
| 190 | + return () -> arguments.toArray(new Object[0]); |
| 191 | + } |
| 192 | + |
| 193 | + /** |
| 194 | + * Factory method for creating an instance of {@code Arguments} based on |
| 195 | + * the supplied {@code arguments} as a {@link List}. |
| 196 | + * |
| 197 | + * <p>This method is an <em>alias</em> for {@link Arguments#of} and is |
| 198 | + * intended to be used when statically imported — for example, via: |
| 199 | + * {@code import static org.junit.jupiter.params.provider.Arguments.arguments;} |
| 200 | + * |
| 201 | + * @param arguments the arguments as a List to be used for an invocation of the test |
| 202 | + * method; must not be {@code null} but may contain {@code null} |
| 203 | + * @return an instance of {@code Arguments}; never {@code null} |
| 204 | + * @since 6.0 |
| 205 | + * @see #argumentSet(String, Object...) |
| 206 | + */ |
| 207 | + @API(status = EXPERIMENTAL, since = "6.0") |
| 208 | + static Arguments arguments(List<@Nullable Object> arguments) { |
| 209 | + return of(arguments); |
| 210 | + } |
| 211 | + |
| 212 | + /** |
| 213 | + * Factory method for creating an {@link ArgumentSet} based on the supplied |
| 214 | + * {@code name} and {@code arguments} as a List. |
| 215 | + * |
| 216 | + * @param name the name of the argument set; must not be {@code null} or blank |
| 217 | + * @param arguments the arguments list to be used for an invocation of the test |
| 218 | + * method; must not be {@code null} but may contain {@code null} |
| 219 | + * @return an {@code ArgumentSet}; never {@code null} |
| 220 | + * @since 6.0 |
| 221 | + */ |
| 222 | + @API(status = EXPERIMENTAL, since = "6.0") |
| 223 | + static ArgumentSet argumentSet(String name, List<@Nullable Object> arguments) { |
| 224 | + Preconditions.notBlank(name, "name must not be null or blank"); |
| 225 | + Preconditions.notNull(arguments, "arguments list must not be null"); |
| 226 | + return new ArgumentSet(name, arguments.toArray(new Object[0])); |
| 227 | + } |
| 228 | + |
| 229 | + /** |
| 230 | + * Convert the arguments to a mutable List. |
| 231 | + * |
| 232 | + * @return a mutable List of arguments; never {@code null} but may contain {@code null} |
| 233 | + * @since 6.0 |
| 234 | + */ |
| 235 | + @API(status = EXPERIMENTAL, since = "6.0") |
| 236 | + default List<@Nullable Object> toList() { |
| 237 | + return new ArrayList<>(List.of(get())); |
| 238 | + } |
| 239 | + |
175 | 240 | }
|
0 commit comments