I would like to write JUnit 5 parametrized test which takes string array (String[]
) as a parameter:
An alternative for Sormuras' solution can be usage of the annotation @ArgumentsSource
which works in very similar manner:
static class StringArrayProvider implements ArgumentsProvider {
@Override
public Stream extends Arguments> provideArguments(ExtensionContext context) throws Exception {
return Stream.of(
(Object) new String[]{"1", "2"},
(Object) new String[]{"1", "2", "3"}).map(Arguments::of);
}
}
Still, casting String[]
to Object
looks strange and I have rather feeling of workaround than of nice design.