Skip to content

Commit

Permalink
Add back support for NULL values to Cartesian Argument Providers (jun…
Browse files Browse the repository at this point in the history
…it-pioneer#764 / junit-pioneer#765)

During migration to JDK11 the support of NULL values
provided by CartesianParameterArgumentsProvider has been silently dropped.

These changes
 - add back support for NULL values and ensure backward compatibility with v. 2.0.1
 - add regression tests for provided NULL values support

Fixes: junit-pioneer#764
  • Loading branch information
petrandreev committed Sep 25, 2023
1 parent 416a38d commit bbb2115
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ The least we can do is to thank them and list some of their accomplishments here

* [Eric Everman](https://github.com/eeverman) added `@RestoreSystemProperties` and `@RestoreEnvironmentVariables` annotations to the [System Properties](https://junit-pioneer.org/docs/system-properties/) and [Environment Variables](https://junit-pioneer.org/docs/environment-variables/) extensions (#574 / #700)
* [Florian Westreicher](https://github.com/meredrica) contributed to the JSON argument source extension (#704 / #724)
* [Pёtr Andreev](https://github.com/petrandreev) added back support for NULL values to `@CartesianTestExtension` (#764 / #765)

#### 2022

Expand Down
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 bbb2115

Please sign in to comment.