@@ -983,13 +983,20 @@ primitive type.
983983[[writing-tests-parameterized-tests-sources-ArgumentsSource]]
984984===== @ArgumentsSource
985985
986- `@ArgumentsSource` can be used to specify a custom, reusable `ArgumentsProvider`.
986+ `@ArgumentsSource` can be used to specify a custom, reusable `ArgumentsProvider`. Note
987+ that an implementation of `ArgumentsProvider` must be declared as either a top-level
988+ class or as a `static` nested class.
987989
988990[source,java,indent=0]
989991----
990992include::{testDir}/example/ParameterizedTestDemo.java[tags=ArgumentsSource_example]
991993----
992994
995+ [source,java,indent=0]
996+ ----
997+ include::{testDir}/example/ParameterizedTestDemo.java[tags=ArgumentsProvider_example]
998+ ----
999+
9931000
9941001[[writing-tests-parameterized-tests-argument-conversion]]
9951002==== Argument Conversion
@@ -1072,7 +1079,8 @@ method_ or a _factory constructor_ as defined below.
10721079 accepts a single `String` argument and returns an instance of the target type. The name
10731080 of the method can be arbitrary and need not follow any particular convention.
10741081- __factory constructor__: a non-private constructor in the target type that accepts a
1075- single `String` argument.
1082+ single `String` argument. Note that the target type must be declared as either a
1083+ top-level class or as a `static` nested class.
10761084
10771085NOTE: If multiple _factory methods_ are discovered, they will be ignored. If a _factory
10781086method_ and a _factory constructor_ are discovered, the factory method will be used
@@ -1087,18 +1095,29 @@ as the title of the book.
10871095include::{testDir}/example/ParameterizedTestDemo.java[tags=implicit_fallback_conversion_example]
10881096----
10891097
1098+ [source,java,indent=0]
1099+ ----
1100+ include::{testDir}/example/ParameterizedTestDemo.java[tags=implicit_fallback_conversion_example_Book]
1101+ ----
1102+
10901103[[writing-tests-parameterized-tests-argument-conversion-explicit]]
10911104===== Explicit Conversion
10921105
10931106Instead of relying on implicit argument conversion you may explicitly specify an
10941107`ArgumentConverter` to use for a certain parameter using the `@ConvertWith` annotation
1095- like in the following example.
1108+ like in the following example. Note that an implementation of `ArgumentConverter` must be
1109+ declared as either a top-level class or as a `static` nested class.
10961110
10971111[source,java,indent=0]
10981112----
10991113include::{testDir}/example/ParameterizedTestDemo.java[tags=explicit_conversion_example]
11001114----
11011115
1116+ [source,java,indent=0]
1117+ ----
1118+ include::{testDir}/example/ParameterizedTestDemo.java[tags=explicit_conversion_example_ToStringArgumentConverter]
1119+ ----
1120+
11021121Explicit argument converters are meant to be implemented by test and extension authors.
11031122Thus, `junit-jupiter-params` only provides a single explicit argument converter that may
11041123also serve as a reference implementation: `JavaTimeArgumentConverter`. It is used via the
@@ -1139,13 +1158,20 @@ _aggregators_.
11391158To use a custom aggregator simply implement the `{ArgumentsAggregator}` interface and
11401159register it via the `@AggregateWith` annotation on a compatible parameter in the
11411160`@ParameterizedTest` method. The result of the aggregation will then be provided as an
1142- argument for the corresponding parameter when the parameterized test is invoked.
1161+ argument for the corresponding parameter when the parameterized test is invoked. Note
1162+ that an implementation of `ArgumentsAggregator` must be declared as either a top-level
1163+ class or as a `static` nested class.
11431164
11441165[source,java,indent=0]
11451166----
11461167include::{testDir}/example/ParameterizedTestDemo.java[tags=ArgumentsAggregator_example]
11471168----
11481169
1170+ [source,java,indent=0]
1171+ ----
1172+ include::{testDir}/example/ParameterizedTestDemo.java[tags=ArgumentsAggregator_example_PersonAggregator]
1173+ ----
1174+
11491175If you find yourself repeatedly declaring `@AggregateWith(MyTypeAggregator.class)` for
11501176multiple parameterized test methods across your codebase, you may wish to create a custom
11511177_composed annotation_ such as `@CsvToMyType` that is meta-annotated with
@@ -1157,6 +1183,11 @@ action with a custom `@CsvToPerson` annotation.
11571183include::{testDir}/example/ParameterizedTestDemo.java[tags=ArgumentsAggregator_with_custom_annotation_example]
11581184----
11591185
1186+ [source,java,indent=0]
1187+ ----
1188+ include::{testDir}/example/ParameterizedTestDemo.java[tags=ArgumentsAggregator_with_custom_annotation_example_CsvToPerson]
1189+ ----
1190+
11601191
11611192[[writing-tests-parameterized-tests-display-names]]
11621193==== Customizing Display Names
0 commit comments