|
34 | 34 | import org.junit.jupiter.api.DynamicTest;
|
35 | 35 | import org.junit.jupiter.api.Test;
|
36 | 36 | import org.junit.jupiter.api.TestFactory;
|
| 37 | +import org.junit.jupiter.api.extension.ParameterContext; |
37 | 38 | import org.junit.jupiter.params.ParameterizedTest;
|
| 39 | +import org.junit.jupiter.params.converter.ArgumentConversionException; |
| 40 | +import org.junit.jupiter.params.converter.ArgumentConverter; |
| 41 | +import org.junit.jupiter.params.converter.ConvertWith; |
38 | 42 | import org.junit.jupiter.params.provider.Arguments;
|
| 43 | +import org.junit.jupiter.params.provider.CsvSource; |
39 | 44 | import org.junit.jupiter.params.provider.MethodSource;
|
40 | 45 | import org.junit.jupiter.params.provider.ValueSource;
|
41 | 46 | import org.junit.platform.commons.PreconditionViolationException;
|
@@ -277,13 +282,26 @@ private void toStreamWithPrimitiveArray(Object primitiveArray) {
|
277 | 282 | }
|
278 | 283 | }
|
279 | 284 |
|
280 |
| - @Test |
281 |
| - void iteratesListElementsInReverseOrder() { |
282 |
| - var items = List.of("foo", "bar", "baz"); |
| 285 | + @ParameterizedTest |
| 286 | + @CsvSource(delimiter = '|', nullValues = "N/A", textBlock = """ |
| 287 | + foo,bar,baz | baz,bar,foo |
| 288 | + foo,bar | bar,foo |
| 289 | + foo | foo |
| 290 | + N/A | N/A |
| 291 | + """) |
| 292 | + void iteratesListElementsInReverseOrder(@ConvertWith(CommaSeparator.class) List<String> input, |
| 293 | + @ConvertWith(CommaSeparator.class) List<String> expected) { |
283 | 294 | var result = new ArrayList<>();
|
284 | 295 |
|
285 |
| - CollectionUtils.forEachInReverseOrder(items, result::add); |
| 296 | + CollectionUtils.forEachInReverseOrder(input, result::add); |
286 | 297 |
|
287 |
| - assertThat(result).containsExactly("baz", "bar", "foo"); |
| 298 | + assertEquals(expected, result); |
| 299 | + } |
| 300 | + |
| 301 | + private static class CommaSeparator implements ArgumentConverter { |
| 302 | + @Override |
| 303 | + public Object convert(Object source, ParameterContext context) throws ArgumentConversionException { |
| 304 | + return source == null ? List.of() : List.of(((String) source).split(",")); |
| 305 | + } |
288 | 306 | }
|
289 | 307 | }
|
0 commit comments