Skip to content

Commit

Permalink
test(junit-pioneer#764): allowed CartesianParameterArgumentsProvider …
Browse files Browse the repository at this point in the history
…to provide NULL values
  • Loading branch information
petrandreev committed Sep 21, 2023
1 parent 416a38d commit 8b5b9d0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
package org.junitpioneer.jupiter.cartesian;

import static java.lang.String.format;
import static java.util.stream.Collectors.toUnmodifiableList;
import static java.util.stream.Collectors.collectingAndThen;
import static java.util.stream.Collectors.toList;
import static org.junit.platform.commons.support.AnnotationSupport.findAnnotation;
import static org.junitpioneer.internal.PioneerUtils.cartesianProduct;

Expand All @@ -20,6 +21,7 @@
import java.lang.reflect.Parameter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;
Expand Down Expand Up @@ -164,7 +166,7 @@ private List<?> provideArguments(ExtensionContext context, Parameter source,
// We like to keep arguments in the order in which they were listed
// in the annotation. Could use a set with defined iteration, but
// this is more explicit.
.collect(toUnmodifiableList());
.collect(collectingAndThen(toList(), Collections::unmodifiableList));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,16 @@ void usesCustomCartesianArgumentsProviderWithArrayArgumentOnParameters() {
assertThat(results).hasNumberOfDynamicallyRegisteredTests(2).hasNumberOfSucceededTests(2);
}

@Test
@DisplayName("when configured with NULL parameters")
void usesCustomCartesianArgumentsProviderWithNullArgumentOnParameters() {
ExecutionResults results = PioneerTestKit
.executeTestMethodWithParameterTypes(CustomCartesianArgumentsProviderTestCases.class,
"nullValuesCartesianArgumentProvider", String.class);

assertThat(results).hasNumberOfDynamicallyRegisteredTests(3).hasNumberOfSucceededTests(3);
}

}

}
Expand Down Expand Up @@ -1190,6 +1200,11 @@ void singleArrayArgument(@CartesianArgumentsSource(StringArrayArgumentsProvider.
assertThat(source).hasSize(2);
}

@CartesianTest
void nullValuesCartesianArgumentProvider(@NullValues String string) {

}

}

private enum TestEnum implements TestInterface {
Expand Down Expand Up @@ -1266,4 +1281,19 @@ public Stream<String> provideArguments(ExtensionContext context, Parameter param

}

@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@CartesianArgumentsSource(NullValuesProvider.class)
@interface NullValues {
}

static class NullValuesProvider implements CartesianParameterArgumentsProvider<String> {

@Override
public Stream<String> provideArguments(ExtensionContext context, Parameter parameter) {
return Stream.of(null, "1", null, "2");
}

}

}

0 comments on commit 8b5b9d0

Please sign in to comment.