-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
Description
Currently, EmptyArgumentsProvider
directly checks the type of the first declared parameter and does not know of potential converters declared for that parameter, so it will throw a PreconditionViolationException
if the declared type doesn't match the expectations.
Looking ahead to when #4219 is integrated, a globally-configured converter might even make the situation more complicated.
Steps to reproduce
Given an ArgumentConverter
accepting strings, like:
class StringToBytesConverter extends TypedArgumentConverter<String, byte[]> {
protected StringToBytesConverter() {
super(String.class, byte[].class);
}
@Override
protected byte[] convert(String source) {
return source.getBytes();
}
}
the following test passes:
@ParameterizedTest
@FieldSource
void fieldSourceTest(@ConvertWith(StringToBytesConverter.class) byte[] bytes) {
assertEquals(0, bytes.length);
}
static List<String> fieldSourceTest = List.of("");
but the following test does not:
@ParameterizedTest
@EmptySource
void emptySourceTest(@ConvertWith(StringToBytesConverter.class) byte[] bytes) {
assertEquals(0, bytes.length);
}
failing with:
org.junit.jupiter.api.extension.ParameterResolutionException: Error converting parameter at index 0: MyConverter cannot convert objects of type [[B]. Only source objects of type [java.lang.String] are supported.
Similar reproducers can be composed for all other @EmptySource
supported types, like Collection
, Map
, etc.
Context
- Used versions (Jupiter/Vintage/Platform): 5.13.4
- Build Tool/IDE: Maven/IntelliJ IDEA
Deliverables
-
@EmptySource
provides the empty argument accepted by the available converter
or
-
@EmptySource
Javadoc explicitly mentions its incompatibility with argument conversion
sbrannen