I have the following test case:
@ParameterizedTest
@JsonFileSource(resources = {"/poc/person.json", "/poc/person2.json"})
void test_jsonfilesource_2(@ConvertWith(DataConverter.class) Person person,
@ConvertWith(DataConverter.class) Person person2){
assertEquals("James", person.getName());
assertEquals("David", person2.getName());
}
This is my DataConverter class:
public class DataConverter extends SimpleArgumentConverter {
private static final ObjectMapper objectMapper = new ObjectMapper();
@Override
protected Object convert(Object source, Class<?> targetType) throws ArgumentConversionException {
if(source == null){
return null;
}
if (targetType == null){
throw new IllegalArgumentException("bla-bla");
}
Object x = null;
try {
x = objectMapper.readValue(source.toString(), targetType);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
return x;
}
}
this is my Person.java:
@Getter
@Setter
public class Person {
private String name;
private int age;
}
File 1:
{
"name": "James",
"age": 10
}
File 2:
{
"name": "David",
"age": 10
}
Files on the right place, I can access them.
I'm using junit 5; net.joshka v5.6.2; org.glassfish 1.1.4.
When I try to execute the test above I get this error:
org.junit.jupiter.api.extension.ParameterResolutionException: No ParameterResolver registered for parameter [poc.Person person2] in method [void DataLoaderPOC.test_jsonfilesource_2(poc.Person, poc.Person)].
I've tried to apply different data converter on the second parameter, but the result is the same.
Any idea?
---UPDATE---
I just figured out that this notation:
@JsonFileSource(resources = {"/poc/person.json", "/poc/person2.json"})
isn't about multiple parameters but run the test with both sources. So it is for looping the test run based on input files. But my question still remains: is it possibile to add multiple parameters from file source?