Skip to content

Commit 943cf48

Browse files
committed
Increase coverage
1 parent 3e92f04 commit 943cf48

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

graphql-webclient/src/main/java/graphql/kickstart/spring/webclient/boot/GraphQLResponse.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ private JsonNode readTree(String rawResponse) {
4141
}
4242

4343
private List<GraphQLError> readErrors(JsonNode tree) {
44-
if (tree.has(ERRORS_FIELD) && tree.get(ERRORS_FIELD) != null) {
44+
if (tree.hasNonNull(ERRORS_FIELD)) {
4545
return convertList(tree.get(ERRORS_FIELD), GraphQLError.class);
4646
}
4747
return emptyList();
@@ -56,7 +56,7 @@ private JavaType constructListType(Class<?> type) {
5656
}
5757

5858
public <T> T get(String fieldName, Class<T> type) {
59-
if (data != null && data.has(fieldName) && data.get(fieldName) != null) {
59+
if (data != null && data.hasNonNull(fieldName)) {
6060
return objectMapper.convertValue(data.get(fieldName), type);
6161
}
6262
return null;
@@ -74,7 +74,7 @@ private Optional<JsonNode> getFirstDataEntry() {
7474
}
7575

7676
public <T> List<T> getList(String fieldName, Class<T> type) {
77-
if (data != null && data.has(fieldName) && data.get(fieldName) != null) {
77+
if (data != null && data.hasNonNull(fieldName)) {
7878
return convertList(data.get(fieldName), type);
7979
}
8080
return emptyList();

graphql-webclient/src/test/java/graphql/kickstart/spring/webclient/boot/GraphQLResponseTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ private GraphQLResponse constructResponse(String json) {
3030
return new GraphQLResponse(json, mockedMapper);
3131
}
3232

33+
@Test
34+
void getErrors_noErrors_returnsEmptyList() {
35+
GraphQLResponse response = constructResponse("{ \"data\": null }");
36+
assertTrue(response.getErrors().isEmpty());
37+
}
38+
3339
@Test
3440
void getFieldName_dataIsNull_returnsNull() {
3541
GraphQLResponse response = constructResponse("{ \"data\": null }");

0 commit comments

Comments
 (0)