New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert ArrayNode to List #654
Comments
Hey @bartsimp! We use Jackson as our JSON parser. Jackson creates an @ParameterizedTest
@JsonSource("""
[
{
"items": [ 1, 3 ]
},
{
"items": [ 2, 4 ]
}
]
""")
void test1(@Property("items") Iterable<Integer> items) {
assertThat(items).hasSize(2);
} Alternatively, as suggested by @Michael1993, you can also modify your JSON: @ParameterizedTest
@JsonSource("""
[
[ 1, 3 ],
[ 2, 4 ]
]
""")
void test2(List<Integer> items) {
assertThat(items).hasSize(2);
} Feel free to reopen this issue if that doesn't help you. |
@Michael1993, @beatngu13 Thanks for suggestions but I'm afraid is not exactly what I'm looking for...
using a json parameterized test which contains also the expected response
do you think is possible? |
@bartsimp I actually made a mistake, my suggestion above throws the following exception once you dig a little deeper:
A workaround (I don't like it though): @ParameterizedTest
@JsonSource("""
[
{
"items": [1, 3],
"expectedResult": 4
},
{
"items": [2, 4],
"expectedResult": 6
}
]
"""
)
void testSum(
@Property("items") Iterable<IntNode> items,
@Property("expectedResult") int expectedResult
) {
List<Integer> itemsList = StreamSupport.stream(items.spliterator(), false)
.map(IntNode::intValue)
.toList();
Integer actualResult = new Calculator().sum(itemsList);
assertEquals(expectedResult, actualResult);
} The "problem" is this method: No case matches, which is why we return I reopen this issue. I'm not that familiar with the Jackson API, and I'm not sure how type erasure will be a problem here, but I believe we can do better. |
I'd like to convert a json array into a java List, but I got this error:
Here my test:
items.json:
what am I missing?
The text was updated successfully, but these errors were encountered: